You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Omit redundant _NoAutoPK and _NoPK OpenAPI schemas when request-body-strict is false (#3325)
## Why make this change?
Closes#3260
## What is this change?
When request-body-strict is set to false, the OpenAPI document was still
generating separate _NoAutoPK and _NoPK component schemas for each
entity. These schemas only differ from the base entity schema by
excluding primary key fields, a distinction that is meaningless when the
request body already allows additional properties. This made the
generated OpenAPI document unnecessarily verbose and confusing for
consumers.
The `isRequestBodyStrict` flag is now threaded through `BuildPaths` and
`CreateOperations` so that POST/PUT/PATCH request body schema references
point to the base entity schema when strict mode is off. The
`CreateComponentSchemas` method now gates `_NoAutoPK` and `_NoPK` schema
generation on strict mode, and its XML documentation has been updated to
accurately describe both strict and non-strict behavior.
## How was this tested?
- [ ] Integration Tests
- [x] Unit Tests
Updated existing unit test
`RequestBodyStrict_False_OmitsRedundantSchemas` (renamed from
`RequestBodyStrict_False_AllowsExtraFields`) to verify that when
request-body-strict is false:
- `_NoAutoPK` and `_NoPK` component schemas are not generated.
- The base entity schema is still present.
- POST/PUT/PATCH operations reference the base entity schema (not
`_NoAutoPK` or `_NoPK`).
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
Co-authored-by: Anusha Kolan <anushakolan10@gmail.com>
Assert.IsNotNull(schema.Reference,"Request body schema should reference a component schema when request-body-strict is false.");
94
+
Assert.AreEqual("book",schema.Reference.Id,"Request body should reference the base 'book' schema when request-body-strict is false.");
95
+
Assert.AreNotEqual("book_NoAutoPK",schema.Reference.Id,"Request body should not reference the 'book_NoAutoPK' schema when request-body-strict is false.");
96
+
Assert.AreNotEqual("book_NoPK",schema.Reference.Id,"Request body should not reference the 'book_NoPK' schema when request-body-strict is false.");
97
+
}
98
+
}
99
+
100
+
Assert.IsTrue(foundRequestBodyForWritableOperation,"Expected at least one POST/PUT/PATCH operation with a JSON request body.");
0 commit comments