feat(dts-generator): add "explicit" flag for event parameter optionality#575
Open
akudev wants to merge 2 commits into
Open
feat(dts-generator): add "explicit" flag for event parameter optionality#575akudev wants to merge 2 commits into
akudev wants to merge 2 commits into
Conversation
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 }] }
There was a problem hiding this comment.
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 acceptexplicit?: boolean. - Update event-parameter interface generation to honor
optional: falsewhenevent.explicit === true. - Allow
.dtsgenrcoverlays to mergeeventsby name (likemethods/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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, all properties in generated
Xxx$YyyEventParametersinterfaces were unconditionally forced to optional ("?"), regardless of their actual "optional" value in the api.json source data.This adds support for an
explicitboolean property on events. When an event has explicit: true, the generator respects each parameter property's actual optional value from the source NestedProperties data:Events without the flag (or with
explicit: false) retain the existing behavior where all parameters are optional.Changes:
api-json.d.ts: Addexplicit?: booleanto bothObjEventandUi5Eventinterfaces so the flag is recognized in the input type system.json-event-parameter-interfaces.ts: ExtendbuildProperties()to accept anexplicitparameter. When true and a property hasoptional === false, override the forced optional back to false afteraddJsDocPropssets it. Passevent.explicit === trueat the call site.json-fixer.ts: AddeventstomapLikePropertiesso 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