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

Support validating Open API sub-schemas #452

Closed
VoltaireNoir opened this issue Feb 8, 2024 · 3 comments
Closed

Support validating Open API sub-schemas #452

VoltaireNoir opened this issue Feb 8, 2024 · 3 comments

Comments

@VoltaireNoir
Copy link

VoltaireNoir commented Feb 8, 2024

The spec that I am using is generated by the utoipa crate. The spec version is 3.0.3. The entire spec compiles just fine with JSONSchema::compile. However, there are no errors caused when I use the validate method using invalid data.

I tried compiling the specific schema of the type I'm trying to validate, but that returns invalid reference error (the schema contains internal references such as #/components/schemas/SchemaName). I also tried using the with_document method and naming the document with # but to no avail. I presume this was only meant to be used for external references.

Is this version of the spec not supported? Or am I doing something wrong here? Any help would be greatly appreciated.

  • Update (Feb 10, 2024)
    • I extracted the exact schema of the type and manually placed the correct nested inner types' schemas in place of their references. This works. However, it would be nice if there's a way to use the schema without having to modify it manually.
@Stranger6667
Copy link
Owner

Stranger6667 commented May 10, 2024

What is the task you'd like to do? You compile JSON Schema for Open API 3.0.3 (e.g. from the repo) and then validate the spec generated by utoipa, right?

I got an impression though, that you pass an Open API spec to JSONSchema::compile while Open API spec and JSON Schema are two separate things (even though Open API uses JSON Schema). In this case, the resulting validator will accept any inputs as there will be no JSON Schema keywords in the generated Open API spec.

@Stranger6667 Stranger6667 changed the title Unable to use OpenAPI spec for validation Support validating Open API sub-schemas Oct 24, 2024
@Stranger6667
Copy link
Owner

Stranger6667 commented Oct 24, 2024

Please, disregard my previous comment, I didn't understand the use case.

Using response or parameter schemas that refer to components for validation would be an extremely useful feature.

Right now, it is not possible, as each reference in such a schema does not know about its "root" document. I.e such a schema is not aware that it is part of a larger document (or set of documents as they could be refs in paths, etc). Therefore a local $ref would do lookups only within a parameter or response schema itself.

I am personally interested in this feature as it would be useful in Schemathesis

Maybe there could be even a special mode for Open API specifically so it can handle nullable and other specifics (mostly prior Open API 3.1).

@Stranger6667
Copy link
Owner

Hi! Sorry for the long delay, but it is solvable now. See this comment. There are a few things to improve in the API and I'll keep track of it in #432.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants