-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Make it clear that additionalProperties
can only have a schema value
#668
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
This is confusing spec language. In particular the last sentence is too hard to follow - the definitions can't be the same and not be the same. Also there don't seem to be any local definitions defined - the link in the statement "the Schema Object definition is used instead." points back to this section. What seems to be happening here operationally, is that four properties from JSON Schema are being changed in Open API while keeping the property names. This seems to indicate what's going on, in more direct language
|
@dehora I think the point of the original language was to replace all places in a schema where a nested "JSON Schema object" occurs (this is just inside of those four properties, and in some which are not supported at all) with a "Swagger Schema object". So Swagger model schemas (or now OpenAPI model schemas) work similar to JSON schemas, with some restrictions (e.g. Your proposed wording removes this point, because now any JSON schema objects can be nested, even ones which are not legal OpenAPI model schemas. (Also, the value of (I think that boolean values were forbidden is just a side effect, which might have been intended, but was not explicitly written out.) |
I guess we could instead write the new definitions of those four fields explicitly:
(The definition of In addition, we would need this section about a properties object:
|
@ePaul The definition of how |
@ralfhandl Nicely hidden, thanks for finding. I guess the guiding point here is section 4.4:
Strange way of saying this. I think JSON schema needs some rewording as well, but this is out-of-scope for this discussion. |
Tackling PR: #741 |
Hello, I wonder how to tell that a definition does not support additional properties. It didn't figure out with a schema? |
Note that in the forthcoming-very-soon-now draft-wright-01 (a.k.a. Draft 06), any schema or subschema, not just
This both allows for a more clear expression of intent on behalf of schema authors and allows implementations to optimize these cases- true always passes validation, false always fails, no instance check needed. It also means that the The confusing language and section organization about "container instances" has also been reworked btw. |
3.0 now supports |
how to validate a JSON with known and dynamic property both? |
Currently when object is send as body parameter only properties defined in `properties` in body schema are passed to handler function. Additional keys are filtered out, which is opposite to [spec](https://github.com/OAI/OpenAPI-Specification/blame/3.0.2/versions/3.0.2.md#L2305). For me specification is counter intuitive :( Changes proposed in this pull request: - If `additionalProperties` is not set or is `True`, all properties not defined in `properties` are passed without type casting. - If `additionalProperties` declares value type, unknown properties are cast according to https://github.com/zalando/connexion#type-casting. The best explanation for `additionalProperties` I found in OAI/OpenAPI-Specification#668 (comment)
How is additionalProperties True interpreted? additionalProperties: True additionalProperties: False additionalProperties: {} additionalProperties: string additionalProperties: schema |
@spacether TL;DR:
In general, keywords are ignored for instance types that they don't describe, so I don't recommend trying to understand how OpenAPI 3.1 will use the latest JSON Schema (probably a draft to be published this month, but at least the current draft which will be referenced by OAS 3.1rc0, and this is now explained in a more straightforward manner in §4.3.2 Boolean Schemas and §9.3.2.3 additionalProperties. Note that since boolean schemas are no longer special cases for only certain keywords, they don't get mentioned in the individual keyword section. You can always use |
Hi, Can you please clarify how to represent a map of string and simple value (for example, Looking in https://swagger.io/docs/specification/data-models/dictionaries/ it says:
Is that correct? If not, how should it be? Thanks. |
@MosheElisha yes, that is correct. It looks a little weird to have |
JSON Schema allows for
additionalProperties
both a boolean or an object value.true
is interpreted as "additional properties follow no restrictions",false
means "no additional restrictions", and an object is interpreted as a JSON schema applied to the property values (the empty object is thus equivalent totrue
).The Schema object description says:
This would be naively interpreted as
additionalProperties
can have a boolean or a schema value (with a schema being interpreted as an OpenAPI schema, not a JSON schema).In Swagger-Codegen #1318, @webron commented that this was actually meant as "the value of additionalProperties can only be a (Swagger) Schema object", not a boolean.
Some more discussion was in #477 here.
(I just hit an API which used booleans in several places, and fails with swagger-codegen.)
To make this clearer in the next version of the spec, I suggest to add the following sentence to the cited paragraph above (before the list):
I'm not totally happy with this wording, feel free to propose a better one. Maybe we should instead simply redefine
additionalProperties
generally?The text was updated successfully, but these errors were encountered: