Skip to content
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

Auto collect tuple responses schema references #1071

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

juhaku
Copy link
Owner

@juhaku juhaku commented Oct 1, 2024

Refactor Tuple responses parsing unifying it with request body parsing. This allows reusing same components when serialized to tokens making it less error prone and removing duplication.

This also removes the content_type = [...] array format from ToResponse and IntoResponses derive types as well as from tuple style responses. Same as with request bodies the multiple content types need to defined with content(...) attribute.

Implement auto collect response schema references from tuple style responses within #[utoipa::path(...)] attribute macro. Schema references will be collected recursively in same manner as for request bodies.

Breaking

The content_type = [...] array format is no longer supported. And instead content(...) is to be used instead for defining multiple content types.

Example of supported syntax. The User will be automatically collected to OpenApi when get_user path is registered to the OpenApi.

 #[derive(utoipa::ToSchema)]
 struct User {
     name: String,
 }

 #[utoipa::path(
     get,
     path = "/user",
     responses(
         (status = 200, body = User)
     )
 )]
 fn get_user() {}

Closes #1065 Closes #1025 Closes #465

Refactor Tuple responses parsing unifying it with request body parsing.
This allows reusing same components when serialized to tokens
making it less error prone and removing duplication.

This also removes the `content_type = [...]` array format from
`ToResponse` and `IntoResponses` derive types as well as from tuple
style responses. Same as with request bodies the multiple content
types need to defined with `content(...)` attribute.

Implement auto collect response schema references from tuple style
responses within `#[utoipa::path(...)]` attribute macro. Schema
references will be collected recursively in same manner as for request
bodies.

Example of supported syntax. The `User` will be automatically collected
to OpenApi when `get_user` path is registered to the `OpenApi`.
```rust
 #[derive(utoipa::ToSchema)]
 struct User {
     name: String,
 }

 #[utoipa::path(
     get,
     path = "/user",
     responses(
         (status = 200, body = User)
     )
 )]
 fn get_user() {}
```
@juhaku juhaku force-pushed the feature-auto-collect-tuple-response-schemas branch from ad2b743 to 9a6f6be Compare October 1, 2024 18:54
@juhaku juhaku merged commit 8d5149f into master Oct 1, 2024
22 checks passed
@juhaku juhaku deleted the feature-auto-collect-tuple-response-schemas branch October 1, 2024 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Released
1 participant