question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenAPI 3.1 Schema causes errors in OpenAPI 3.0.x files

See original GitHub issue

VS Code YAML extension uses Schema Store https://www.schemastore.org/api/json/catalog.json to automatically guess and apply JSON Schemas to documents being edited.

My understanding is that if multiple schemas match a file, these schemas are combined and then used to validate the matching file.

It looks though, that schemastore.org contains schemas written in newer and yet supported by VS Code schema dialect.

In particular, I’ve started seeing that OpenAPI 3.1 schema https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json which uses Draft 2020-12 dialect is being applied to OpenAPI files.

I’m an author of OpenAPI extension (which depends on Redhat YAML one) and I’m seeing users reporting errors which appear like OpenAPI 3.1 schemas are being arbitrarily applied to files they edit: https://github.com/42Crunch/vscode-openapi/issues/130

In particular complains are for the error messages which look like this:

{
	"resource": "xxx/openapi.yaml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "String does not match the pattern of \"^3\\.1\\.\\d+(-.+)?$\".",
	"source": "yaml-schema: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json",
	"startLineNumber": 1,
	"startColumn": 10,
	"endLineNumber": 1,
	"endColumn": 15
}

Would it be possible (if I’m correct in my conclusion) to exclude unsupported schema dialects?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
benjaminfiliatraultcommented, Jun 29, 2021

Same, Postman only support version 3 for now so all our open api files have errors and the autocompletion is not working anymore.

From https://www.schemastore.org/api/json/catalog.json (URL of schema store catalog to use) at around the line 1684 where the openapi.json is defined it have the versions object which could be used to switch between version 3…0.x and version 3.1.x.

    {
      "name": "openapi.json",
      "description": "A JSON schema for Open API documentation files",
      "fileMatch": [
        "openapi.json",
        "openapi.yml",
        "openapi.yaml"
      ],
      "url": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json",
      "versions": {
        "3.0": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json",
        "3.1": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json"
      }
    },

Work around

  1. Go in your vscode JSON settings
  2. add this (Change the yml to the extension you’re using)
"yaml.schemas": {
    "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json": "openapi.yml",
  },

it should accept now the version 3.0 but won’t work for version 3.1

1reaction
shayded-execommented, Sep 14, 2022

When using the 3.0 schema, I get an error that definitions/Schema/properties/multipleOf/exclusiveMinimum must be a number.

It seems as if the extension is using a newer version of the JSON Schema spec to validate the OpenAPI schema than draft-04 like it declares.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating from OpenAPI 3.0 to 3.1.0
OpenAPI Schema is now valid JSON Schema. Everything inside the `schema` keyword in OpenAPI is defined by the Schema Object. This has always...
Read more >
OpenAPI 3: Missing property "$ref" - Stack Overflow
It works pretty well until today - suddenly my document is filled with errors on "properties" within all schema declarations. The error goes:...
Read more >
OpenAPI Compatibility Chart - ReadMe Documentation
If no JSON Schema dialects are specified, we adhere to the OAS and default to v2020-12 for all OpenAPI v3.1.x documents. We support...
Read more >
OpenAPI | IntelliJ IDEA Documentation - JetBrains
These are regular YAML or JSON files with the definition of the OpenAPI specification version. From the main menu, select File | New...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
Types that are not accompanied by a format property follow the type definition in the JSON Schema. Tools that do not recognize a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found