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

Vscode unable to resolve parts of the schema #247

Closed
TomTardigradeSEL opened this issue Aug 31, 2022 · 15 comments · Fixed by #298
Closed

Vscode unable to resolve parts of the schema #247

TomTardigradeSEL opened this issue Aug 31, 2022 · 15 comments · Fixed by #298
Labels
bug Something isn't working

Comments

@TomTardigradeSEL
Copy link

Describe the bug

According to redhat-developer/yaml-language-server#585 and microsoft/vscode-json-languageservice#123 the use of hashes to reference eternal schemas is not supported.
$ref '/definitions/schemaArray' in 'http://asyncapi.com/schema-store/2.4.0.json' can not be resolved.

How to Reproduce

Create a new asyncapi.json or asyncapi.yaml file in vscode with the yaml extention installed.

image

Expected behavior

The schema should resolve by the language servers used by the extention.

@TomTardigradeSEL TomTardigradeSEL added the bug Something isn't working label Aug 31, 2022
@github-actions
Copy link

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@derberg
Copy link
Member

derberg commented Sep 6, 2022

Thanks for reporting this one, I saw the issue but had no idea that it depends not really on the yaml plugin but actually further on.

I don't think we should count on dependencies to fix the problem.

Feel to me like the best would be to plug into our release process of binding definitions into one schema like https://github.com/asyncapi/spec-json-schemas/blob/master/schemas/2.4.0.json and extend it with dereferencing too 🤔

@jonaslagoni you worked on the bundling. What do you think?

@smoya thoughts? resolving all references in the main schema as part of the release should also decrease amount of request for particular definitions

@magicmatatjahu it will be good for the parser performance when it compiles schema, right? although in exchange the JSON file will be larger. Performance is more important I think

@fmvilas @dalelane thoughts?

@jonaslagoni
Copy link
Member

jonaslagoni commented Sep 15, 2022

Without looking into it, I am pretty sure it's because the reference is not accurately resolved to this schema:

"schemaArray": {

When this reference is encountered:

"$ref": "#/definitions/schemaArray"
it MUST use the schema $id most recently encountered
"$id": "http://json-schema.org/draft-07/schema",
to resolve the relevant references and NOT expect that the root 2.1.0.yaml schema contains a schema at #/definitions/schemaArray i.e. the fully resolved reference should be http://json-schema.org/draft-07/schema#/definitions/schemaArray.

@derberg
Copy link
Member

derberg commented Sep 15, 2022

When this reference is encountered:
spec-json-schemas/schemas/2.4.0.json
Line 601 in 83c03f2
"$ref": "#/definitions/schemaArray"
it MUST use the schema $id most recently encountered
spec-json-schemas/schemas/2.4.0.json
Line 483 in 83c03f2
"$id": "http://json-schema.org/draft-07/schema",
to resolve the relevant references and NOT expect that the root 2.1.0.yaml schema contains a schema at #/definitions/schemaArray i.e. the fully resolved reference should be http://json-schema.org/draft-07/schema#/definitions/schemaArray.

I don't think it will ever be logical to me 😅

@jonaslagoni we know that there is a problem, but it is outside our reach, thus my suggestion is that we basically resolve all references, inline them in the schema that we publish (ignoring circular if we have these)

@jonaslagoni
Copy link
Member

jonaslagoni commented Sep 15, 2022

@jonaslagoni we know that there is a problem, but it is outside our reach, thus my suggestion is that we basically resolve all references, inline them in the schema that we publish (ignoring circular if we have these)

It's definitely a possibility, but ignoring circular is just not an option I think.

An alternative approach is that we create our "own" bundling behavior and change the $refs to be absolute from the perspective of the root object I.e. the bundling behavior would change the reference

"$ref": "#/definitions/schemaArray"

to /definitions/http://json-schema.org/draft-07/schema/definitions/schemaArray.

I think that could work because then we are no longer expecting tools that resolve it to fully support the bundling and dereferencing behavior of JSON Schema. At least it could be a bandage on the wound until the tooling has further matured.

You might need to play around with what works.

@derberg
Copy link
Member

derberg commented Sep 26, 2022

but the same with "$ref": "http://asyncapi.com/definitions/2.4.0/specificationExtension.json" right? and change to #/definitions/http://asyncapi.com/definitions/2.4.0/specificationExtension.json, as we are not sure how resolvers from community work, they can also fetch from http://asyncapi.com/definitions/2.4.0/specificationExtension.json instead of definitions, right?

until the tooling has further matured

😃

@derberg
Copy link
Member

derberg commented Oct 12, 2022

@jonaslagoni ok, now I think I get it, you wrote /definitions/http://json-schema.org/draft-07/schema/definitions/schemaArray as it is there already in the file. Better this way, than make tooling fetch from asyncapi.com

we create our "own" bundling behavior

I think it is ok to follow the current bundler, but then just after bundling just traverse the document again and make small adjustments, no?

@jonaslagoni
Copy link
Member

That should be possible yes.

@jonaslagoni
Copy link
Member

@derberg not sure how long you are with your implementation, but I added an issue for the bundler we used to see if it won't make sense to solve this natively there: hyperjump-io/json-schema-bundle#9

@derberg
Copy link
Member

derberg commented Nov 24, 2022

@jonaslagoni I planned to work on this next week. So yeah, lemme know if you plan to be first 😄

@philCryoport
Copy link

FYI I'm encountering this same issue

@derberg
Copy link
Member

derberg commented Dec 15, 2022

Opened a PR to fix this issue once and for all

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

@github-actions github-actions bot added the stale label Apr 15, 2023
@smoya
Copy link
Member

smoya commented Apr 15, 2023

Still relevant.

@derberg
Copy link
Member

derberg commented May 11, 2023

works like a charm now

Screenshot 2023-05-11 at 18 39 51

and I know @AceTheCreator will follow with more description and examples inside schema to put the autocompletion on a higher level

@ivangsa pinging you as you might want to know in regards to vscode plugin maybe

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.

5 participants