Skip to content

Commit

Permalink
feat: SL-1709 Paths consistency (#90)
Browse files Browse the repository at this point in the history
* fix: a typo and a probable cut-and-paste error

src/rulesets/oas3/index.ts and associated tests:

'specifcication' -> 'specification' in a comment
`servers` must be, and is tested against, being an array not a string

* fix: allow path-keys-no-trailing-slash empty slash (#85)

* fix: add operation-operationId-valid-in-url (#86)

to check for valid url characters in operationId

* fix: SL-1709 paths emitted by ajv are not json pointers

* fix: SL-1709 fixed json dependency version
  • Loading branch information
karol-maciaszek committed Feb 19, 2019
1 parent fe86612 commit c88ca75
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"url": "https://github.com/stoplightio/spectral"
},
"license": "Apache-2.0",
"main": "src/index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"**/*"
],
Expand All @@ -43,6 +44,7 @@
"test.watch": "yarn test --watch"
},
"dependencies": {
"@stoplight/json": "1.x.x",
"@stoplight/types": "3.x.x",
"ajv": "6.x.x",
"jsonpath": "git://github.com/stoplightio/jsonpath.git#fe90d42",
Expand Down
8 changes: 7 additions & 1 deletion src/functions/schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { decodePointerFragment } from '@stoplight/json';
import * as AJV from 'ajv';
import * as jsonSpecv4 from 'ajv/lib/refs/json-schema-draft-04.json';

Expand Down Expand Up @@ -39,7 +40,12 @@ export const schema: IFunction<ISchemaOptions> = (targetVal, opts, paths) => {
}

results.push({
path: path.concat(e.dataPath.split('/').slice(1)),
path: path.concat(
e.dataPath
.split('/')
.slice(1)
.map(frag => decodePointerFragment(frag))
),
message: e.message ? e.message : '',
});
});
Expand Down
31 changes: 31 additions & 0 deletions src/rulesets/oas2/__tests__/oas2-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Spectral } from '../../../spectral';
import { oas2Rules } from '../index';

const ruleset = { rules: oas2Rules() };

describe('oas2-schema', () => {
const s = new Spectral();
s.addRules({
'oas2-schema': Object.assign(ruleset.rules['oas2-schema'], {
enabled: true,
}),
});

test('annotates with correct paths', () => {
const results = s.run({
swagger: '2.0',
paths: {
'/test': {
get: {},
},
},
schemes: ['http'],
info: {
title: 'Test',
version: '1.0.0',
},
});
expect(results.results).toHaveLength(1);
expect(results.results[0].path).toEqual(['paths', '/test', 'get']);
});
});
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,21 @@
into-stream "^4.0.0"
lodash "^4.17.4"

"@stoplight/fast-safe-stringify@2.1.2":
version "2.1.2"
resolved "https://registry.yarnpkg.com/@stoplight/fast-safe-stringify/-/fast-safe-stringify-2.1.2.tgz#2811eff4989c3d4c5c9a3789f057e25358db0899"
integrity sha512-ayw3qQ9KNn2K5q6ggrLclh+rdZsSLwYIUz3uAer1NzaCpalJLR4g32G845ylgq7Xy2AunMHnNfD3FC3s0rUcsA==

"@stoplight/json@^1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@stoplight/json/-/json-1.5.0.tgz#174135278c345129381733c5bee8a9165f126418"
integrity sha512-f9kgxIusy+pO4Y2aPwgiFHXpm64Fmwli3a5tFAfz3iyRra8SiIlRxDJYkpQBFS/qxZP4VUjBAiVEGyudpOi1gQ==
dependencies:
"@stoplight/fast-safe-stringify" "2.1.2"
"@stoplight/types" "3.x.x"
json-source-map "0.4.0"
lodash "4.x.x"

"@stoplight/scripts@3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@stoplight/scripts/-/scripts-3.1.0.tgz#212f183ad2fc941be2c8e79d6abc40bfbb6e1500"
Expand Down Expand Up @@ -7187,6 +7202,11 @@ json-schema@0.2.3:
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
integrity sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=

json-source-map@0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/json-source-map/-/json-source-map-0.4.0.tgz#eea837fe3ce2f2bfd5b13687779406354423c355"
integrity sha1-7qg3/jzi8r/VsTaHd5QGNUQjw1U=

json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
Expand Down

0 comments on commit c88ca75

Please sign in to comment.