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

OpenAPI format, required plus minimum/maximum fields #449

Open
danmoser opened this issue Jun 24, 2024 · 1 comment
Open

OpenAPI format, required plus minimum/maximum fields #449

danmoser opened this issue Jun 24, 2024 · 1 comment
Labels
question Further information is requested

Comments

@danmoser
Copy link

I'm trying to validate a schema generated my OpenAPI and check-jsonschema is not working with it. In particular, I need to check required plus minimum/maximum fields.

This is the schemafile:

{
  "components": {
    "schemas": {
      "my_data": {
        "type": "object",
        "properties": {
          "longitude": {
            "type": "number",
            "format": "decimal-degrees +/- DDD.D",
            "example": -107.6177275,
            "description": "the longitude of the observatory/instrument",
            "minimum": -180,
            "maximum": 180
          }
        },
        "required": ["longitude"]
      }
    }
  }
}

This is the instance an example of instance file: {"latitude":190.0}.

Currently check-jsonschema is returning ok -- validation done

@sirosen
Copy link
Member

sirosen commented Jun 25, 2024

This sounds to me like an understanding issue, rather than a tool issue. That file doesn't contain a schema at the root, which means that it's effectively equivalent to the schema {}, and passes on any document.

The fastest, easiest path to get the validation you're looking for is to pull the relevant schema from $.components.schemas.my_data into a distinct file and use that for validation.

I'd be happy to talk about tool enhancements to make this sort of workflow easier, but I want to be careful that any discussion starts from a common understanding of which part of the given document is a schema.1 I'll also note, as a warning about a potential issue, that openapi spec extends JSON Schema in several ways, not all of which are easy to support.

Footnotes

  1. relatedly, thanks for including a sample document in this issue! It makes it much easier to discuss.

@sirosen sirosen added the question Further information is requested label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants