-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
readOnly and writeOnly should be at the same level as required in the Schema #1671
Comments
You can wrap the |
As @MikeRalphson suggested, you can use
|
That's actually a pretty good suggestion that I did not think of. A little clunky having a single element I'll just test this out now but, if I don't respond within two weeks, then consider this issue resolved. |
Personally, I prefer the explicitness of putting the |
I guess that "address": {
"oneOf": [
{"$ref": "#/components/schemas/Address"},
{"readOnly": true}
]
}, What is the readOnly behaviour here? Is it only readOnly if it's not an Address? If you intend the behaviour to effect the whole object in all cases then I think I would still put it on the top level. |
(for those who don't know me, I'm the most active editor of the JSON Schema spec) @robertmassaioli we discussed switching Currently, the This is further clarified in the forthcoming draft-08. Additionally, |
@handrews It's good to meet you. And thankyou, I did not realise that having a It's good to know that Btw @MikeRalphson I just wanted to say that I'm a big fan of your work on: https://github.com/Mermade/oas-kit, specifically swagger2openapi. I work for Atlassian on the developer.atlassian.com team and we are either consuming OAS 3.0 files (or converting Swagger 2.0 files to OAS 3.0 files) to then use them as the source of truth for our REST API documentation. For example, this is our largest (by far) Swagger file to document the Jira Cloud Platform REST API: https://developer.atlassian.com/cloud/jira/platform/rest/ I share this just to say thank you for the great work on Json Schema and Swagger respectively. |
@robertmassaioli draft-08 isn't out yet, although I think that part has been committed to master in the repo. I hope to have draft-08 published in October. |
I think it's safe to say: no action required. This issue is resolved. |
This post seems to have been a year since its last comment, and apparently it is still necessary to use the allOf for the refs: This at the json schema level looks perfect, but the tool that builds the definition for me, with the controllers and the models, the tool at https://editor.swagger.io/. for ASP.NET Core projects. I have to tell you that those allOf classes it generates are terribly horrible out of context. How could this be different to allow ReadOnly and WriteOnly to be direct are allOF, or improve the tool so that it does not create those horrible classes. How can I improve that |
@softm-gustavomelendez as tooling is out of scope for this repository, I can only suggest raising an issue on the relevant repo and linking back here. |
In the Schema, when you want to mark a property as
required
you do this:And then, if you want to mark a property as
readOnly
then you would do this:However, what if you want to mark
address
asreadOnly
. This would be invalid and thereadOnly
property onaddress
would be ignored by a valid parser for example:As far as I can tell, you only have two options:
#/components/schemas/Address
intoaddress
and then addreadOnly
.readOnly
property into the root of the#/components/schemas/Address
definition. However, this does not seem to be possible thanks to Clarify spec wrt readOnly and writeOnly in referenced schemas #1622.What this means, is that it's impossible to make refs and
readOnly
work well together.In my mind, the best solution would be to make
readyOnly
andwriteOnly
work likerequired
. Like so:Is this a reasonable proposal? It is affecting our current REST API documentation.
Note: I'm NOT asking to deprecate the current
readOnly
andwriteOnly
fields but rather to add extrareadOnly
andwriteOnly
fields at the level ofrequired
. ThereadOnly
property at therequired
level would have an OR relationship with thereadOnly
property at the current level (and the same would apply forwriteOnly
).The text was updated successfully, but these errors were encountered: