Skip to content

Commit

Permalink
fix(resolving): decode path to produce proper ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Sep 30, 2019
1 parent b968957 commit 6986b82
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"host": "d",
"info": {
"$ref": "./refs/info-ref.json"
},
"paths": {
"/test": {
"$ref": "./refs/paths.json#/paths/~1test"
}
}
}
9 changes: 9 additions & 0 deletions src/cli/services/__tests__/__fixtures__/refs/paths.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"paths": {
"/test": {
"get": {
"response": "bar"
}
}
}
}
48 changes: 48 additions & 0 deletions src/cli/services/__tests__/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,54 @@ describe('Linter service', () => {
},
source: expect.stringContaining('__tests__/__fixtures__/refs/contact.json'),
}),
expect.objectContaining({
code: 'operation-description',
message: 'Operation `description` must be present and non-empty string.',
path: ['paths', '/test', 'get'],
range: {
end: {
character: 7,
line: 5,
},
start: {
character: 13,
line: 3,
},
},
source: expect.stringContaining('__tests__/__fixtures__/refs/paths.json'),
}),
expect.objectContaining({
code: 'operation-operationId',
message: 'Operation should have an `operationId`.',
path: ['paths', '/test', 'get'],
range: {
end: {
character: 7,
line: 5,
},
start: {
character: 13,
line: 3,
},
},
source: expect.stringContaining('__tests__/__fixtures__/refs/paths.json'),
}),
expect.objectContaining({
code: 'operation-tags',
message: 'Operation should have non-empty `tags` array.',
path: ['paths', '/test', 'get'],
range: {
end: {
character: 7,
line: 5,
},
start: {
character: 13,
line: 3,
},
},
source: expect.stringContaining('__tests__/__fixtures__/refs/paths.json'),
}),
]);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/resolved.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pointerToPath } from '@stoplight/json';
import { decodePointerFragment, pointerToPath } from '@stoplight/json';
import { IResolveError } from '@stoplight/json-ref-resolver/types';
import { Dictionary, ILocation, IRange, JsonPath, Segment } from '@stoplight/types';
import { get } from 'lodash';
Expand Down Expand Up @@ -72,7 +72,7 @@ export class Resolved {

if (target && target[REF_METADATA]) {
return {
path: [...get(target, [REF_METADATA, 'root'], []), ...newPath],
path: [...get(target, [REF_METADATA, 'root'], []).map(decodePointerFragment), ...newPath],
doc: get(this.parsedMap.parsed, get(target, [REF_METADATA, 'ref']), this.spec),
};
}
Expand Down

0 comments on commit 6986b82

Please sign in to comment.