Stranger6667 / jsonschema-rs

JSON Schema validation library
https://docs.rs/jsonschema
MIT License
482 stars 90 forks source link

Unable to use OpenAPI spec for validation #452

Open VoltaireNoir opened 5 months ago

VoltaireNoir commented 5 months ago

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.

Stranger6667 commented 1 month ago

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.