-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Support required in nested object #2065
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
Comments
Can you give an example? You can define required properties on all levels: {
"type": "object",
"required": [
"name",
"subobject"
],
"properties": {
"name": {
"type": "string"
},
"subobject": {
"type": "object",
"required": [
"id",
],
"properties": {
"id": {
"type": "number"
},
}
}
} |
My scenario is to do with where I have an object defined externally and then want to ref it in and declare something within it as required.
and then when I use it set specific required fields:
but in a different use I want the same model but a different set of required fields. |
This has come up in the context of JSON Schema- I think the proposals were named The proposals have not been added to JSON Schema in part because they are easily implemented with a preprocessor that can be run in a build step (they simply expand to nested schemas using |
You can already do this: allOf:
- $ref: "#/components/schemas/ProblemSample"
- properties:
object1:
required: [property1]
properties:
innerobject:
required: [property2] (Perhaps you also want to mark FTR, the corresponding JSON Schema issue is json-schema-org/json-schema-vocabularies#18. |
deeprequired helps with better object reusability . One could declare a common object with all fields optional and reuse that in the overall schema in combination with allOf keyword whilst making some fields mandatory . Right now the only option is to declare multiple objects . Example ----- API ------ /updateUser /someOtherUserApi |
@handrews , i think this one could be closed as a handled / linked to the Json Schema repository |
@LasneF I've paused closing JSON Schema issues as I want to get a clear decision on whether we're drawing a hard boundary here or not. For now i'm making sure they're all tagged with |
After several months of discussing 3.x options, there does not seem to be interest in adding more custom JSON Schema keywords. This should be pursued through the JSON Schema project or with custom vocabularies (which OAS 3.1 supports). Closing (although this is not a judgement on the merits, just the jurisdiction!) |
It would be good to be able to specify required fields in an object at a deeper level in the structure.
e.g. required: [objectName.elementName]. This would make it much easier to use allOf with modeled objects which have different required fields in different use cases.
The text was updated successfully, but these errors were encountered: