-
Notifications
You must be signed in to change notification settings - Fork 202
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
Using sea-orm model as body type generates incorrect schema name #435
Comments
@juhaku might of missed this |
Yeah, sorry for late reply. @112RG There is one thing that should help you with this: // ... in albums list api
responses(
(status = 200, description = "List containing albums", body = [entity::album::Model])
)
// ... in users list api
responses(
(status = 200, description = "List containing albums", body = [entity::user::Model])
) Then where the ApiDoc is being generated you can use components(
schemas(
entity::album::Model as entity::album::Model,
entity::user::Model as entity::user::Model,
)
), As a matter of fact I might just change this behavior for the next release the otherway around in a way that the |
I changed the behavior for the next release and now it is better and more clear. More details here: #459. Basically now you can register types having same name to OpenAPI as follows. #[derive(ToSchema)]
#[schema(as = entity::album::Model)]
struct Model {
id: String
}
#[derive(ToSchema)]
#[schema(as = entity::artist::Model)]
struct Model {
id: String
}
// .. then in the handler
#[utoipa::path(
get,
path = "/artists",
responses(
(status = 200, description = "List artists", body = [entity::artist::Model])
)
)]
async fn get_artists() -> Vec<entity::artists::Model> {
Vec::new()
}
// .. and where ever the types are registered to the OpenAPI
#[derive(OpenApi)]
#[openapi(
components(
schemas(entity::artist::Model, entity::album::Model)
)
)]
struct ApiDoc; |
Related: #230 |
When using a sea-orm Model as a return type causes the schema generation to break and name the components.schema incorrectly
My utoipa route macro
Here is my Model struct
And finally here is my generation
All sea-orm entities must have a struct called Model. When generating the json file. The Model struct is outputted as
And the schema json is generated as so
Which leads to swagger or in my case
docusaurus-preset-openapi
failing to find the schema definition. There is also another problem when you start adding multiple Model structs it wont work since they are always outputted asModel
The text was updated successfully, but these errors were encountered: