-
Notifications
You must be signed in to change notification settings - Fork 197
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
ToSchema derives array with items with allOf combination of the types of all the tuple elements #901
Comments
Tuples don't seem to be supported exactly in OpenAPI but it would probably be possible to at least use anyOf and minItems and maxItems to get as close as OpenAPI allows the validation to go. Alternatively if someone uses a tuple and it is not supported by utoipa at all it should probably lead to a compile error. |
It should be possible to set |
According to how serde serializes tuples https://serde.rs/json.html see the struct |
But this schema requires every element of the tuple to satisfy the types of all of them which obviously won't work. |
@taladar Ah, true, instead it should serialize as |
|
True, the limitation should already be present on some tuples though. It should actually set that the array should contain 2 items. But it does not set prefix items though. But it might be that it does not take account all cases. Nonetheless while those utoipa/utoipa-gen/src/component/schema.rs Lines 607 to 610 in 576f6c1
|
Technically speaking the entire schema does not prevent any client from sending any random data to the endpoint. |
Yeah, it just shows "what a good guy should send" |
@emersion That is true, I'll change the tuple implementation out of the |
This PR adds support for `prefixItems` as defined in JSON schema specification https://json-schema.org/understanding-json-schema/reference/array#tupleValidation. The `prefixItems` are used to correctly represent tuple values Rust tuples. This will remove the old `allOf` behavior known from OpenAPI 3.0 which fails to correctly represent a tuple. Prefix items are conforming OpenAPI 3.1 and is coming from JSON Schema. Add new type `ArrayItems` what represent [`Array::items`] supported values. ### Breaking This commit removes `allOf` tuple behavior, replacing with with all new `prefixItems` while setting `items` to false. Closes #901
This PR adds support for `prefixItems` as defined in JSON schema specification https://json-schema.org/understanding-json-schema/reference/array#tupleValidation. The `prefixItems` are used to correctly represent tuple values Rust tuples. This will remove the old `allOf` behavior known from OpenAPI 3.0 which fails to correctly represent a tuple. Prefix items are conforming OpenAPI 3.1 and is coming from JSON Schema. Add new type `ArrayItems` what represent [`Array::items`] supported values. ### Breaking This commit removes `allOf` tuple behavior, replacing with with all new `prefixItems` while setting `items` to false. Closes #901
This PR adds support for `prefixItems` as defined in JSON schema specification https://json-schema.org/understanding-json-schema/reference/array#tupleValidation. The `prefixItems` are used to correctly represent tuple values Rust tuples. This will remove the old `allOf` behavior known from OpenAPI 3.0 which fails to correctly represent a tuple. Prefix items are conforming OpenAPI 3.1 and is coming from JSON Schema. Add new type `ArrayItems` what represent [`Array::items`] supported values. ### Breaking This commit removes `allOf` tuple behavior, replacing with with all new `prefixItems` while setting `items` to false. Closes #901
This PR adds support for `prefixItems` as defined in JSON schema specification https://json-schema.org/understanding-json-schema/reference/array#tupleValidation. The `prefixItems` are used to correctly represent tuple values Rust tuples. This will remove the old `allOf` behavior known from OpenAPI 3.0 which fails to correctly represent a tuple. Prefix items are conforming OpenAPI 3.1 and is coming from JSON Schema. Add new type `ArrayItems` what represent [`Array::items`] supported values. ### Breaking This commit removes `allOf` tuple behavior, replacing with with all new `prefixItems` while setting `items` to false. Closes #901
This PR adds support for `prefixItems` as defined in JSON schema specification https://json-schema.org/understanding-json-schema/reference/array#tupleValidation. The `prefixItems` are used to correctly represent tuple values Rust tuples. This will remove the old `allOf` behavior known from OpenAPI 3.0 which fails to correctly represent a tuple. Prefix items are conforming OpenAPI 3.1 and is coming from JSON Schema. Add new type `ArrayItems` what represent [`Array::items`] supported values. ### Breaking This commit removes `allOf` tuple behavior, replacing with with all new `prefixItems` while setting `items` to false. Closes #901
Thank you so much! |
Given e.g.
we get
which seems to be the schema for a type that fulfills all the requirements at the same time instead of one where each element fulfills one of the requirements.
This happens for both enum and struct fields and it does not seem to matter if the field is named which leads me to conclude that the location of the tuple within the type we derive ToSchema on probably doesn't matter.
The text was updated successfully, but these errors were encountered: