-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add operation-operationId-valid-in-url (#86)
to check for valid url characters in operationId
- Loading branch information
Marc MacLeod
committed
Feb 4, 2019
1 parent
33a4a06
commit e550cb6
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/rulesets/oas/__tests__/__snapshots__/operation-operationId-valid-in-url.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`operation-operationId-valid-in-url return errors if operationId contains invalid characters 1`] = ` | ||
Array [ | ||
Object { | ||
"message": "must match the pattern '^[A-Za-z0-9-._~:/?#\\\\[\\\\]@!\\\\$&'()*+,;=]*$'", | ||
"name": "operation-operationId-valid-in-url", | ||
"path": Array [ | ||
"paths", | ||
"/todos", | ||
"get", | ||
"operationId", | ||
], | ||
"severity": 40, | ||
"severityLabel": "warn", | ||
"summary": "operationId may only use characters that are valid when used in a URL.", | ||
}, | ||
] | ||
`; |
41 changes: 41 additions & 0 deletions
41
src/rulesets/oas/__tests__/operation-operationId-valid-in-url.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Spectral } from '../../../spectral'; | ||
import { commonOasRules } from '../index'; | ||
|
||
const ruleset = { rules: commonOasRules() }; | ||
|
||
describe('operation-operationId-valid-in-url', () => { | ||
const s = new Spectral(); | ||
s.addRules({ | ||
'operation-operationId-valid-in-url': Object.assign(ruleset.rules['operation-operationId-valid-in-url'], { | ||
enabled: true, | ||
}), | ||
}); | ||
|
||
test('validate a correct object', () => { | ||
const results = s.run({ | ||
swagger: '2.0', | ||
paths: { | ||
'/todos': { | ||
get: { | ||
operationId: "A-Za-z0-9-._~:/?#[]@!$&'()*+,;=", | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect(results.results.length).toEqual(0); | ||
}); | ||
|
||
test('return errors if operationId contains invalid characters', () => { | ||
const results = s.run({ | ||
swagger: '2.0', | ||
paths: { | ||
'/todos': { | ||
get: { | ||
operationId: 'foo-^^', | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect(results.results).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters