fix(go-server): skip readOnly fields in AssertXxxRequired
AssertXxxRequired is only invoked on decoded request bodies, but it enforced every entry of a schema's required list, including readOnly properties. Per OpenAPI 3.x, readOnly properties are produced by the server and MUST NOT be sent by the client, so a schema legitimately listing a readOnly property as required (e.g. Redfish/JSON:API identity fields like id, @odata.type) caused the generated controller to reject every valid request that omitted the readOnly field.
Skip readOnly entries in the requiredVars loop in model.mustache so non-readOnly required fields are still validated while readOnly ones are not enforced on request bodies. Add a regression test using a spec with a readOnly+required id and a non-readOnly required name.
fix #24168
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/configs/java*.
IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed. - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
@lwj5
Summary by cubic
Skip readOnly fields during go-server model validation so request bodies can omit server-produced fields. Non-readOnly required fields are still enforced, and readOnly fields are excluded from required checks, recursion, and constraints per OpenAPI 3.
- Bug Fixes
- Update
model.mustacheto skipreadOnlyfields when building the required map, recursing inAssertXxxRequired, and checkingAssertXxxConstraints. - Add
readonly-required.yamland tests inGoServerCodegenTestto confirmidis skipped,nameis enforced, and nestedMetais not recursed into.
- Update