Skip to content

feat(dts-generator): add "explicit" flag for event parameter optionality#575

Open
akudev wants to merge 2 commits into
mainfrom
fix/event-parameters
Open

feat(dts-generator): add "explicit" flag for event parameter optionality#575
akudev wants to merge 2 commits into
mainfrom
fix/event-parameters

Conversation

@akudev
Copy link
Copy Markdown
Member

@akudev akudev commented May 12, 2026

Previously, all properties in generated Xxx$YyyEventParameters interfaces were unconditionally forced to optional ("?"), regardless of their actual "optional" value in the api.json source data.

This adds support for an explicit boolean property on events. When an event has explicit: true, the generator respects each parameter property's actual optional value from the source NestedProperties data:

  • optional: false → required (no ?)
  • optional: true or undefined → optional (?)

Events without the flag (or with explicit: false) retain the existing behavior where all parameters are optional.

Changes:

  • api-json.d.ts: Add explicit?: boolean to both ObjEvent and Ui5Event interfaces so the flag is recognized in the input type system.

  • json-event-parameter-interfaces.ts: Extend buildProperties() to accept an explicit parameter. When true and a property has optional === false, override the forced optional back to false after addJsDocProps sets it. Pass event.explicit === true at the call site.

  • json-fixer.ts: Add events to mapLikeProperties so that .dtsgenrc overlay merges can target individual events by name (matching how methods and properties overlays already work), enabling overlays like: { "name": "sap.m.Select", "events": [{ "name": "change", "explicit": true }] }

Needed for #529

Previously, all properties in generated $Xxx$YyyEventParameters interfaces
were unconditionally forced to optional (?), regardless of their actual
"optional" value in the api.json source data.

This adds support for an "explicit" boolean property on events. When an
event has explicit: true, the generator respects each parameter property's
actual optional value from the source NestedProperties data:
- optional: false → required (no ?)
- optional: true or undefined → optional (?)

Events without the flag (or with explicit: false) retain the existing
behavior where all parameters are optional.

Changes to productive files:

- api-json.d.ts: Add explicit?: boolean to both ObjEvent and Ui5Event
  interfaces so the flag is recognized in the input type system.

- json-event-parameter-interfaces.ts: Extend buildProperties() to accept
  an explicit parameter. When true and a property has optional === false,
  override the forced optional back to false after addJsDocProps sets it.
  Pass event.explicit === true at the call site.

- json-fixer.ts: Add "events" to mapLikeProperties so that .dtsgenrc
  overlay merges can target individual events by name (matching how
  methods and properties overlays already work), enabling overlays like:
  { "name": "sap.m.Select", "events": [{ "name": "change", "explicit": true }] }
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an explicit flag to the UI5 d.ts generator’s event model to optionally preserve required vs. optional event parameter properties from api.json (instead of forcing all event parameters to be optional), and enables overlays to target individual events.

Changes:

  • Extend api.json typing (ObjEvent/Ui5Event) to accept explicit?: boolean.
  • Update event-parameter interface generation to honor optional: false when event.explicit === true.
  • Allow .dtsgenrc overlays to merge events by name (like methods/properties) and add snapshot-style tests for the explicit behavior.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
test-packages/openui5-snapshot-test/test/explicit-event-params-spec.js Adds tests validating optionality behavior with/without the explicit flag for different inheritance setups.
packages/dts-generator/src/utils/json-event-parameter-interfaces.ts Implements explicit handling when building event parameter interface properties.
packages/dts-generator/src/types/api-json.d.ts Adds explicit?: boolean to event type definitions so the flag is accepted by the input schema.
packages/dts-generator/src/phases/json-fixer.ts Treats events as a map-like overlay property so overlays can merge events by name.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/dts-generator/src/utils/json-event-parameter-interfaces.ts
Comment thread packages/dts-generator/src/phases/json-fixer.ts
Add tests for overlay merge behavior and inheritance semantics:

- Overlay test: verifies that a .dtsgenrc overlay like
  { name: "...", events: [{ name: "change", explicit: true }] }
  correctly merges into an existing event by name without affecting
  other events on the same class.

- Inheritance test: documents that inherited parameters stay optional
  when only the subclass event is explicit (they come from the parent
  interface via extends). When the parent event is also explicit, the
  full chain produces required parameters as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants