-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds fix for composed schema model vars #8816
Conversation
Can you please share the links to the discussions? |
Sure, here it is: OAI/OpenAPI-Specification#2478 |
public void setDeclawed(Boolean declawed) { | ||
this.declawed = declawed; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spacether the declawed
property has been removed as part of the change, which doesn't seem to be correct according to the definition of Cat
:
Cat:
allOf:
- $ref: '#/components/schemas/Animal'
- $ref: '#/components/schemas/Address'
- type: object
properties:
declawed:
type: boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CodegenModel Cat not containing declawed when vars only contains properties in the current schema is correct. declawed definition only exists in that allOf third schema. It does not have an explicit definition inside Cat because cat has by default:
Cat:
properties: {} # no declawed property here
additionalProperties: true # this allows ingestion of any type of value
Cat containing allOf properties in generated code is an implementation decision.
Per our chat, an allOf schema could be composed also, which means that the variables that it includes in a composed schema like Cat can change from one payload to another or could event be different types like null or object.
This is why I think putting this behind a CLI option may be the best path forward.
Fixing Java looks non-trivial to me but maybe I am missing something.
Do you have a straightforward way to fix Java in this PR?
How do you think I should proceed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CodegenModel Cat not containing declawed when vars only contains properties in the current schema is correct
Can you share the link(s) to discussion supporting this claim so that everyone is on the same page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of this PR is that vars should only contain the properties defined in properties of the current scheme. It should not include composed schema properties. This is consistent with how the openapi folks told me to interpret schemas.
Yup it is in the link I pasted above OAI/OpenAPI-Specification#2478
And here is the slack discussion https://json-schema.slack.com/archives/C5CF75URH/p1613937923034800
CodegenModel is one of our classes which implemente Schema and includes some extra info.
b16dbcd
to
f8607fc
Compare
Fixes typo Adds fix for codegenProperty and a test of it Removes comment Clarifies comment Clarifies what setVars is setting in IJsonSchemaValidationProperties Adds testQueryParameterVarsCorrect testBodyParamAndResponseVarsCorrect Removes unused imports Samples updated Moves fix for vars into python generator only Samples and docs regen
So this change works to remove the vars that were hoisted into composed schemas from those composed schemas. They still exist in the source schemas and can be assigned as additional properties in the composed schemas. I am concerned about merging this because it will remove the variables from the properties and signatures of the composed schemas. While not a breaking change, I suspect that many users will not want that. |
Adds fix for composed schema model vars
Per guidance from json schema and openapi people, when a composed schema has properties or additionalProperties
object payloads are validated to the properties or additionalProerties definition at the composed schema level, independent of properties in composed oneOf/anyOf/allOf definition
So that means that CodegenModel.vars must store only the properties present in the composed schema, if they are present.
This has implications to how we validate composed schemas across generators, and that all generators should eventually support supportsAdditionalPropertiesWithComposedSchema = True.
For now only python and java support it.
This is a fix for: #8813
Blocker
Landing this PR is blocked by: #8802
because we need additionalProperties to be set at the model level before we can use it to allow any value in in all key value pairs.
@sebastien-rosset should the go generator set supportsAdditionalPropertiesWithComposedSchema to True?
PR checklist
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*
.For Windows users, please run the script in Git BASH.
master
,5.1.x
,6.0.x