swagger-api / swagger-api/swagger-client
Resolver error
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 2.7k
- Forks
- 765
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 6
Description
Q&A (please complete the following information)
- OS: Windows 10
- Environment: Node.js v13.4.0
- Method of installation: npm
- Swagger-Client version: 3.10.8
- Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
Swagger/OpenAPI definition:
The test consists of 3 cross-referenced YAML files: test.yaml (main), which references data types from 2 other YAML files (a.yaml and b.yaml). To perform the test, these 3 files should be placed in the same directory, or URL location.
test.yaml
openapi: 3.0.0
info:
version: 1.0.0
title: Title
paths:
/foo:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Body'
responses:
'201':
description: Created
content:
application/json:
schema:
$ref: '#/components/schemas/Body'
components:
schemas:
Body:
type: object
properties:
p1:
$ref: 'a.yaml#/components/schemas/A'
p2:
$ref: 'b.yaml#/components/schemas/B1'
a.yaml
openapi: 3.0.0
info:
version: 1.0.0
title: A
description: A
paths: {}
components:
schemas:
A:
type: object
properties:
p1:
$ref: 'b.yaml#/components/schemas/B3'
b.yaml
openapi: 3.0.0
info:
version: 1.0.0
title: B
description: B
paths: {}
components:
schemas:
B1:
type: string
B2:
type: integer
B3:
type: object
properties:
p1:
$ref: '#/components/schemas/B2'
Swagger-Client usage:
import SwaggerClient from 'swagger-client'
new SwaggerClient('https://<server>/test.yaml').then(swaggerClient => {
console.log(swaggerClient.errors[0].message);
});
Describe the bug you're encountering
The output of the JS script above is:
Could not resolve reference: Could not resolve pointer: /components/schemas/B2 does not exist in document
To reproduce...
Steps to reproduce the behavior:
- Put the 3 files in a same URL location
- Execute the JS script above with node.js
Expected behavior
There should not be any error, since all the types can be resolved
Screenshots
Not needed
Additional context or thoughts
The same issue can be tested in the online Swagger Editor, by following the link:
https://editor.swagger.io/?url=https://jdegre.github.io/test/test.yaml
And, right after the test.yaml is loaded, in the right side of the window, expand the POST method, and you will see the same error:
Resolver error at paths./foo.post.responses.201.content.application/json.schema.properties.p1.properties.p1.properties.p1.$ref
Could not resolve reference: Could not resolve pointer: /components/schemas/B2 does not exist in document
Jump to line 18
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the resolver error with test.yaml and its cross-references to a.yaml and b.yaml at the documented URL, starting from the SwaggerClient constructor and the reported nested $ref. Trace why B2 is not found through the chained references; done means all three files load without a resolver error and the referenced schema resolves.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100