Skip to content

feat(dts-generator): trust source data for event parameter optionality#576

Open
akudev wants to merge 1 commit into
mainfrom
fix/event-parameters2
Open

feat(dts-generator): trust source data for event parameter optionality#576
akudev wants to merge 1 commit into
mainfrom
fix/event-parameters2

Conversation

@akudev
Copy link
Copy Markdown
Member

@akudev akudev commented May 20, 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.

Now the generator respects each parameter's optional field by default:

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

For events whose parameter optionality has not yet been verified in the OpenUI5/SAPUI5 sources, a new "eventsWithAllParamsOptional" directive (string[] in .dtsgenrc) preserves the legacy all-optional behavior. Format: "fully.qualified.ClassName:eventName"

Changes:

  • generate-from-objects.ts: Add eventsWithAllParamsOptional to Directives.

  • generate.ts: Initialize the new directive field.

  • json-fixer.ts: Pass directives to addEventParameterInterfaces(). Add "events" to mapLikeProperties so .dtsgenrc overlays can target individual events by name.

  • json-event-parameter-interfaces.ts: Invert buildProperties() to respect source data by default; only force all-optional when the event is in the eventsWithAllParamsOptional deny-list. Log a warning when a parameter has no "optional" value (unexpected edge case).

  • Regenerated snapshot .d.ts files (parameters with optional: false now appear as required).

Needed for #529

Comment thread packages/dts-generator/src/phases/json-fixer.ts
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

Updates the UI5 .d.ts generator to stop forcing all event-parameter properties to be optional, and instead honor the optional flag from api.json, with an escape hatch for events whose optionality is not yet trusted.

Changes:

  • Adjust event-parameter interface generation to make properties required when optional: false (defaulting to optional when optional is missing/true).
  • Introduce a new .dtsgenrc directive eventsWithAllParamsOptional to preserve legacy “all params optional” behavior for specified events.
  • Add a dedicated test suite and regenerate OpenUI5 snapshot .d.ts outputs to reflect the new optionality rules.

Reviewed changes

Copilot reviewed 6 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test-packages/openui5-snapshot-test/test/event-params-optionality-spec.js Adds targeted mocha tests for event parameter optionality, deny-list behavior, and inheritance.
packages/dts-generator/src/utils/json-event-parameter-interfaces.ts Implements optionality logic + deny-list support when building $Xxx$YyyEventParameters interfaces.
packages/dts-generator/src/phases/json-fixer.ts Passes directives into event-parameter interface generation and enables overlays to target events by name.
packages/dts-generator/src/generate.ts Initializes the new directive field when loading/merging directives.
packages/dts-generator/src/generate-from-objects.ts Extends the public Directives type with eventsWithAllParamsOptional.
packages/dts-generator/api-report/dts-generator.api.md Updates the API report to include the new directive field.
test-packages/openui5-snapshot-test/output-dts/sap.ui.unified.d.ts Regenerated snapshot reflecting required event parameters where optional: false.
test-packages/openui5-snapshot-test/output-dts/sap.ui.layout.d.ts Regenerated snapshot reflecting required event parameters where optional: false.
test-packages/openui5-snapshot-test/output-dts/sap.ui.core.d.ts Regenerated snapshot reflecting required event parameters where optional: false.
test-packages/openui5-snapshot-test/output-dts/sap.tnt.d.ts Regenerated snapshot reflecting required event parameters where optional: false.
test-packages/openui5-snapshot-test/output-dts/sap.m.d.ts Regenerated snapshot reflecting required event parameters where optional: false.
test-packages/openui5-snapshot-test/output-dts/sap.f.d.ts Regenerated snapshot reflecting required event parameters where optional: false.

💡 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/generate-from-objects.ts
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.

Now the generator respects each parameter's optional field by default:
- optional: false → required (no ?)
- optional: true or undefined → optional (?)

For events whose parameter optionality has not yet been verified in the
OpenUI5/SAPUI5 sources, a new "eventsWithAllParamsOptional" directive
(string[] in .dtsgenrc) preserves the legacy all-optional behavior.
Format: "fully.qualified.ClassName:eventName"

Changes:

- generate-from-objects.ts: Add eventsWithAllParamsOptional to Directives.

- generate.ts: Initialize the new directive field.

- json-fixer.ts: Pass directives to addEventParameterInterfaces(). Add
  "events" to mapLikeProperties so .dtsgenrc overlays can target individual
  events by name.

- json-event-parameter-interfaces.ts: Invert buildProperties() to respect
  source data by default; only force all-optional when the event is in the
  eventsWithAllParamsOptional deny-list. Log a warning when a parameter
  has no "optional" value (unexpected edge case).

- Regenerated snapshot .d.ts files (parameters with optional: false now
  appear as required).

Needed for #529
@akudev akudev force-pushed the fix/event-parameters2 branch from 56ace7a to 0569e6c Compare May 20, 2026 08:33
@akudev akudev requested a review from codeworrior May 20, 2026 08:37
Copy link
Copy Markdown
Member

@codeworrior codeworrior left a comment

Choose a reason for hiding this comment

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

The default for optional surprises me, but as it is always set, I don't really mind. Besides that, the change looks reasonable to me.

Comment thread packages/dts-generator/src/utils/json-event-parameter-interfaces.ts

// All parameters should have optional: true or false in practice;
// this test documents the defensive fallback behavior (treated as optional).
it("parameters without optional field default to optional", async () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didn't expect this default, see above.

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.

3 participants