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

[JSON Schema Store] IDEs cannot determine the version of the JSON Schema to use #236

Closed
smoya opened this issue Jun 27, 2022 · 2 comments · Fixed by #237
Closed

[JSON Schema Store] IDEs cannot determine the version of the JSON Schema to use #236

smoya opened this issue Jun 27, 2022 · 2 comments · Fixed by #237
Labels
bug Something isn't working

Comments

@smoya
Copy link
Member

smoya commented Jun 27, 2022

Describe the bug

IDEs, like VSCode, cannot determine the version of the JSON Schema file to use based on the AsyncAPI version in use.

2022-06-27 at 09 48 32

How to Reproduce

Expected behavior

IDEs should pick up the proper JSON Schema file based on the version selected on the AsyncAPI file.

The solution can be found in SchemaStore/schemastore#2229 (comment)

@smoya smoya added the bug Something isn't working label Jun 27, 2022
@smoya
Copy link
Member Author

smoya commented Jul 6, 2022

I found a small rock on the path.

In order to support several versions, we need to provide a file like this one.
The point is that the $id of our JSON Schema documents look like http://asyncapi.com/definitions/1.0.0/asyncapi.json -- note the /definitions path part.
However, if we want to measure the downloads from Schema-Store linked documents, we should set $ref to point to /schema-store paths since Schema Store plugins will download making a GET from the $id (as it is an URL).

{
  "$id": "http://asyncapi.com/schema-store/all.json",
  "$schema": "http://json-schema.org/draft-07/schema",
  "title": "JSON Schema documents for all AsyncAPI spec versions",
  "description": "All AsyncAPI JSON Schema documents listed in one file. Needed for serving all documents through schemastore.org",
  "type": "object",
  "oneOf": [
    {
      "allOf": [
        {
          "properties": {
            "asyncapi": {
              "const": "1.0.0"
            }
          }
        },
        {
          "$ref": "http://asyncapi.com/schema-store/1.0.0.json"
        }
      ]
    },

The real problem behind that is that the $id of the document served at http://asyncapi.com/schema-store/1.0.0.json is http://asyncapi.com/definitions/1.0.0.json, so it's kind of inconsistent on those cases where the schema has been loaded already from http://asyncapi.com/schema-store/1.0.0.json (on a local schema registry), forcing the tool to download it again.

It is not a big issue as Schema-Store plugin is being used for development, but still a bit inconsistent.

Posible solutions

1. Just deal with it. To have one all.schema-store.json file with all $ref pointing to the http://asyncapi.com/schema-store/<doc>.json

2. To provide two files, one all.schema-store.json and a all.json, with all $ref pointing to the http://asyncapi.com/schema-store/<doc>.json and http://asyncapi.com/definitions/<doc>.json respectively.

Even though I'm not sure if any user will use the all.json tbh. The only use case I can think of is for our parsers.

Any preference or alternative @derberg @fmvilas ?

I'm going to move on with just the first option as we can always move with the second.

@smoya
Copy link
Member Author

smoya commented Jul 13, 2022

This is not fixed yet. SchemaStore/schemastore#2342 will be the last PR required. @derberg could you reopen it?

Nevermind, this is now considered as fixed since the PR on Schema Store has been merged.

We can confirm it works because since the PR got merged, schemas for other AsyncAPI versions started to be downloaded:
4fa2fe8f-5f7e-4f44-9282-2433058e7e74
2022-07-13 at 15 36 31

cc @derberg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant