swagger-editor icon indicating copy to clipboard operation
swagger-editor copied to clipboard

SwaggerEditor@next: Relative $ref within a schema component with id doesn't not resolve correctly

Open mathematikoi opened this issue 1 year ago • 2 comments

Q&A (please complete the following information)

  • OS: [e.g. macOS]
  • Browser: [e.g. chrome, safari]
  • Version: [e.g. 22]
  • Method of installation: [e.g. npm, dist assets]
  • Swagger-Editor version: [e.g. 3.10.0]
  • Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0]

Content & configuration

Example Swagger/OpenAPI definition: illustrative definition here https://gist.github.com/mathematikoi/5616f793f3bf3f488a1fb02b4976470e

Swagger-Editor configuration options:

SwaggerEditor({
  // your config options here
})
?yourQueryStringConfig

Describe the bug you're encountering

To reproduce copy the definition from the gist and input it in the swagger next editor, you'll see that a relative reference can't be resolved and highlighted as a an error, which shouldn't happen according the to the open api 3.1 spec.

Steps to reproduce the behavior:

  1. Go to https://gist.github.com/mathematikoi/5616f793f3bf3f488a1fb02b4976470e
  2. copy the definition
  3. input it on https://editor-next.swagger.io/
  4. See error on line 42 (the irony)

Expected behavior

the reference resolving correctly within the example schema as it has an id and should be treated as a resource schema.

Screenshots

Additional context or thoughts

OpenAPI 3.1 indeed integrates JSON Schema draft 2020-12 as its schema language and it changes how $ref and $id work. It introduces the concept of a "schema resource", which is a schema object that is identified by an $id. A schema resource establishes a new resolution scope for relative JSON pointers, such as those in $ref properties.

The "example" schema object in your document does have an $id, and therefore establishes its own resolution scope. The $ref in "property" should resolve within this scope, where "only" is defined.

mathematikoi avatar Jul 10 '23 19:07 mathematikoi

https://github.com/swagger-api/swagger-editor/issues/4241

mathematikoi avatar Jul 10 '23 19:07 mathematikoi

Hi @mathematikoi,

This looks legit.

the reference resolving correctly within the example schema as it has an id and should be treated as a resource schema.

Expected behavior actually happens. The resolution works correctly, the only issue is in linting, which basically reports false positive. The proof for resolution correctness lies in actual rendering of the Schema Object:

image

One additional issue that I see is on line 45. The definitions keyword doesn't exists in JSON Schema 2020-12 draft. Instead you should use $defs keyword. The resulting rendering will look like this now:

image


Problems that I see in this issue:

Error code looks odd and wraps on multiple lines:

image

Lining issue with local reference is reported even though the reference is correct:

image

char0n avatar Aug 05 '23 19:08 char0n