Skip to content

fix: honor optional request bodies during validation#903

Open
sueun-dev wants to merge 1 commit into
openapistack:mainfrom
sueun-dev:fix-request-body-required-validation
Open

fix: honor optional request bodies during validation#903
sueun-dev wants to merge 1 commit into
openapistack:mainfrom
sueun-dev:fix-request-body-required-validation

Conversation

@sueun-dev

Copy link
Copy Markdown

This fixes request validation for operations that define a requestBody without setting required: true. The validator was marking requestBody as required whenever the operation had exactly one content type, so an omitted optional body failed with must have required property 'requestBody'.

What changed:

  • Only add requestBody to the generated required list when requestBody.required is true.
  • Added regression coverage for an optional single-media-type body being omitted.
  • Kept validation for an invalid optional body when one is provided.

Checked:

  • npm test -- src/validation.test.ts --runInBand
  • npm run build
  • npm run lint
  • ./node_modules/.bin/prettier --check src/validation.ts src/validation.test.ts
  • npm test -- --runInBand

Fixes #817.
Fixes #292.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant