Skip to content

Commit

Permalink
test(core): add test demonstrating path mapper issue
Browse files Browse the repository at this point in the history
  • Loading branch information
padamstx committed Jul 6, 2022
1 parent 2db5159 commit 6be6b1f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/__tests__/__fixtures__/gh-658/URIError.yaml
Expand Up @@ -28,6 +28,8 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error"
"404":
$ref: './lib.yaml#/components/responses/NotFoundResponse'
"500":
description: No Bueno.
content:
Expand Down
23 changes: 23 additions & 0 deletions packages/core/src/__tests__/__fixtures__/gh-658/lib.yaml
Expand Up @@ -22,3 +22,26 @@ components:
type: string
test:
$ref: ./URIError.yaml#/components/schemas/Foo
NotFound:
oneOf:
- $ref: '#/components/schemas/DoesntExist'
- $ref: '#/components/schemas/JustCantFindIt'
DoesntExist:
type: object
properties:
id:
type: string
JustCantFindIt:
type: object
properties:
name:
type: string

responses:
NotFoundResponse:
description: Not Found.
content:
application/json:
schema:
$ref: '#/components/schemas/NotFound'

36 changes: 33 additions & 3 deletions packages/core/src/__tests__/spectral.jest.test.ts
Expand Up @@ -190,7 +190,7 @@ describe('Spectral', () => {

const results = await s.run(new Document(fs.readFileSync(documentUri, 'utf8'), Parsers.Yaml, documentUri));

expect(results.length).toEqual(3);
expect(results.length).toEqual(5);

return expect(results).toEqual([
expect.objectContaining({
Expand All @@ -208,6 +208,36 @@ describe('Spectral', () => {
},
}),

expect.objectContaining({
path: ['components', 'schemas', 'DoesntExist', 'properties', 'id'],
source: expect.stringContaining('/src/__tests__/__fixtures__/gh-658/lib.yaml'),
range: {
end: {
character: 22,
line: 32,
},
start: {
character: 11,
line: 31,
},
},
}),

expect.objectContaining({
path: ['components', 'schemas', 'JustCantFindIt', 'properties', 'name'],
source: expect.stringContaining('/src/__tests__/__fixtures__/gh-658/lib.yaml'),
range: {
end: {
character: 22,
line: 37,
},
start: {
character: 13,
line: 36,
},
},
}),

expect.objectContaining({
path: ['paths', '/test', 'get', 'responses', '200', 'content', 'application/json', 'schema'],
source: expect.stringContaining('/src/__tests__/__fixtures__/gh-658/URIError.yaml'),
Expand All @@ -229,11 +259,11 @@ describe('Spectral', () => {
range: {
end: {
character: 18,
line: 43,
line: 45,
},
start: {
character: 8,
line: 42,
line: 44,
},
},
}),
Expand Down

0 comments on commit 6be6b1f

Please sign in to comment.