Skip to content

fix: emit required array for non-nullable action parameters in requestBody#355

Open
axherrm wants to merge 5 commits into
oasis-tcs:mainfrom
axherrm:fix/action-parameter-required-array
Open

fix: emit required array for non-nullable action parameters in requestBody#355
axherrm wants to merge 5 commits into
oasis-tcs:mainfrom
axherrm:fix/action-parameter-required-array

Conversation

@axherrm

@axherrm axherrm commented Jun 25, 2026

Copy link
Copy Markdown

Fixes #354

Problem

pathItemAction built the requestBody schema with a properties object
for every non-binding parameter but never emitted a required array.
As a result, downstream OpenAPI consumers (validators, code generators,
LLM-based agents) treated all action parameters as optional, even when
Nullable="false" was set — causing the service to return 400 Bad Request
when those parameters were omitted.

OData 4.01 Protocol §11.5.5.1 states that non-binding parameters that are
neither nullable nor annotated with Core.OptionalParameter must be
supplied in the request body. The generated OpenAPI document should reflect
this constraint.

Fix

In pathItemAction, collect the names of parameters where $Nullable is
not true and @Core.OptionalParameter is not set, then emit them as
required on the requestBody schema object. This mirrors the logic already
present in pathItemFunction for URL parameters (line 1720).

Changes

  • lib/csdl2openapi.jspathItemAction: compute and conditionally
    emit required array on the requestBody schema.
  • test/csdl2openapi.test.js — new test case
    "action with nullable and not nullable parameters" covering all four
    combinations: non-nullable (required), typed non-nullable (required),
    $Nullable: true (not required), and @Core.OptionalParameter (not
    required).
  • test/annotations.test.js — updated "Default Namespace" snapshot to
    include the now-emitted required array.
  • examples/TripPin.openapi3.json — updated ShareTrip action
    requestBody (userName, tripId are both Nullable="false").
  • examples/odata-rw-v3.openapi3.json — updated Discount and
    IncreaseSalaries action requestBodies (single non-nullable parameter
    each).

Comment thread lib/csdl2openapi.js Outdated
Comment on lines +1637 to +1638
if (!p.$Nullable && !p[voc.Core.OptionalParameter])
requiredParameters.push(p.$Name);

@HeikoTheissen HeikoTheissen Jun 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This makes collection-valued parameters required, although OData-Protocol, section 11.5.6.1 allows their omission.

The interpretation of an omitted non-binding collection-valued parameter is up to the service regardless of its nullability or optionality.

Note also the failed test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thank you for the comment - does the fix I added resolve the issue?

Also, I commited the openapi artifacts after test run so that they should have no diff in CI/CD (diff was the required array which is new and needs to be added to the artifacts to my understanding). Can you permit a new CI/CD run

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.

Action parameter Nullable="false" lost in conversion: requestBody schema has no required array

2 participants