-
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
OpenAPI schema generation silently allows missing schemas #465
Comments
This is something that indeed needs some thought. That is, there is currently no way to know what schemas have been added to the OpenAPI and what are not. I am planning to investigate possibility to automatically add these to the schema but there are no guarantees whether it is possible in any feasible way. Difficulty here comes from that Only thing I can think of is if Yet if is possible have schemas automatically added to the But if possible it would be good to have such an safety mechanism to check whether schema is correct or not. |
I think what you'd have to do is thread a registry of some sort, through the |
I guess this could be less awful by just having a trait |
Yeah, I was considering something like a centralized store for
@djrenren Could you elaborate a bit on this. If this trait would be implemented in compile time same time with |
yeah basically right here: utoipa/utoipa-gen/src/openapi.rs Line 442 in 2986e5a I'm not sure what would happen if there were conflicts between manually described components and auto-discovered ones. probably would just want to error out at instantiation. |
Yeah, here it is a runtime panic and error cannot be targeted to specific span. Unless the spans are collected as well. Though the question remains that how to deal with manually defined components. |
The problem would also be solved by collecting all the types that need to be referenced in |
Yes that is possible, but there is a but. That only will work to the extend of single crate. I have been planning to do something like this for other purposes and it could be leveraged here as well but I haven't got a hold of it yet. While I haven't tested it with cross crate references I don't belive it will work because they are seprate processes does not know anything about each others existense. In such cases there still is a need to manually point a schema location what to register as a schema. This kind of situation is very common when API is bigger than a simple demo API. But if cross crate references are possible, that would make it a lot simplier. Perhaps I need to test it out sometime. |
I don't think the API should use any kind of global registration mechanism, to be clear. It should be enough to use the recursive nature of types with derived traits. If we could somehow collect types from the endpoint handler functions (which we already list out for schema declarations), that should allow for many schemas to exist in parallel. |
Note https://github.com/rxdiscovery/utoipa_auto_discovery by @rxdiscovery is planning to solve this, but hasnt done so yet. |
I found a similar problem with |
Is there anyway to make this complain now ? Its very hard to trust code reviews would catch this before its consumed by another project like in my case. I even tried to use a different library just for validation on the outputted JSON schema but failed. Maybe someone has a better idea? |
Related #1025 |
@jfrader In master there is version that actually enforces the types to exist before they can be added to the |
There are PRs on that repo which do this, and they are available at https://github.com/ProbablyClem/utoipauto which is published at https://crates.io/crates/utoipauto |
I could consider this as done, as all mandatory things for this is implemented excluding support for |
I am using the OpenAPI schema generation, and the generated OAS doc for the following includes schema
SchemaA
correctly, however it refers toSchemaB
which isn't present in the generated OAS, making it invalid. There should be some failure to indicate thatSchemaA
cant be included in the OAS withoutSchemaB
.Adding
SchemaB
in the above solves the problem.This also occurred in the 2.x release, so it isnt a regression.
The text was updated successfully, but these errors were encountered: