Stranger6667/jsonschema-rs

Unable to use OpenAPI spec for validation

VoltaireNoir opened this issue · 1 comments

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.

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.