fix: support setting body fields manually in request schema#882
fix: support setting body fields manually in request schema#882samchungy wants to merge 1 commit intofastify:mainfrom
Conversation
aef935d to
6f332d1
Compare
c8c68c6 to
0a8d59b
Compare
0a8d59b to
85bcc9b
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for manually setting required and description fields on request body schemas when using the OpenAPI content format (with explicit content types).
Key changes:
- Extended
resolveBodyParamsfunction to handlerequiredanddescriptionfields whenschema.body.contentis provided - Added test coverage for the new functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/spec/openapi/utils.js | Added logic to copy required and description fields from schema to request body when content types are explicitly defined |
| test/spec/openapi/schema.js | Added test case verifying that required and description fields are properly set in the generated OpenAPI specification |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (resolved.required) { | ||
| body.required = true | ||
| } |
There was a problem hiding this comment.
Inconsistent handling of the required field. In the else branch (line 288), required is checked as an array with .length, but here it's treated as a boolean. This inconsistency could lead to bugs if required is provided as an array in the content-based schema format. Consider using if (resolved.required === true) to ensure only boolean values are accepted, or update the logic to handle both cases consistently.
At the moment setting this doesn't do anything when you specify content manually.
Checklist
npm run testandnpm run benchmarkand the Code of conduct