swagger-editor
swagger-editor copied to clipboard
SwaggerEditor@next: Relative $ref within a schema component with id doesn't not resolve correctly
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:
- Go to https://gist.github.com/mathematikoi/5616f793f3bf3f488a1fb02b4976470e
- copy the definition
- input it on https://editor-next.swagger.io/
- 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.
https://github.com/swagger-api/swagger-editor/issues/4241
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:
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:
Problems that I see in this issue:
Error code looks odd and wraps on multiple lines:
Lining issue with local reference is reported even though the reference is correct: