Obey request-body-strict in OpenAPI schema generation #3100
+199
−16
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.
Why make this change?
Closes #2947, Closes #1838
OpenAPI schemas did not reflect the
request-body-strictruntime setting. Whenfalse, clients can send extra fields (which are ignored), but the generated schema didn't communicate this—potentially misleading API consumers.What is this change?
Sets
additionalPropertieson request body schemas based onrequest-body-strictconfig:true(default):additionalProperties: false— strict field validationfalse:additionalProperties: true— extra fields allowedAffected schemas:
{EntityName},{EntityName}_NoAutoPK,{EntityName}_NoPK{EntityName}_sp_request(stored procedures)Example OpenAPI output when
request-body-strict: false:{ "components": { "schemas": { "Book": { "type": "object", "properties": { ... }, "additionalProperties": true } } } }How was this tested?
Added
RequestBodyStrictTests.cswith tests for both strict/non-strict modes validatingAdditionalPropertiesAllowedon generated schemas.Sample Request(s)
Returns OpenAPI document with
additionalProperties: trueon request body schemas when config has:{ "runtime": { "rest": { "request-body-strict": false } } }Original prompt
This section details on the original issue you should resolve
<issue_title>[Enh]: Obey "request-body-strict" in OpenAPI</issue_title>
<issue_description>## What?
Today, our OpenAPI includes object types that are not required by the endpoint. See #1838</issue_description>
<agent_instructions>include resolution for #1838 resolve both in a single pr with as little new code as possible</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@JerryNixon ### The ProblemCurrent behavior: The OpenAPI document generated by DAB includes schemas for models like
EntityName_NoAutoPK(entities without auto-generated primary keys) regardless of theruntime.rest.request-body-strictconfiguration setting.Issue #1838 screenshot shows: The OpenAPI document exposes
Book_NoAutoPKschema even though it may not be necessary depending on strictness settings.Understanding
request-body-strictThe
request-body-strictconfiguration controls whether DAB allows extraneous fields in REST request bodies:{ "runtime": { "rest": { "enabled": true, "path": "/api", "request-body-strict": true // Default: true } } }When
true(strict mode - DEFAULT):400 Bad RequesterrorWhen
false(non-strict mode):How It Works at Runtime
Looking at the request validation code:
And the validation enforcement:
The Enhancement Request
What DAB currently does in OpenAPI generation:
request-body-strict:EntityName- Full schema with all fieldsEntityName_NoAutoPK- Schema excluding auto-generated PKs (for POST)EntityName_NoPK- Schema excluding all PKs (for PUT/PATCH)What the enhancement wants:
request-body-strict: true: Include all schema variations (current behavior)request-body-strict: false: Potentially simplify the OpenAPI schema since extra fields are allowed anywayThe current OpenAPI generator doesn't check this setting:
Current Impact
When
request-body-strict: true(Default)OpenAPI shows:
Book- Full schemaBook_NoAutoPK- For POST r...💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.