Skip to content

Commit a4c421f

Browse files
eazy-gGarrett Brustkern
andauthored
fix(rulesets): operation-tags should fail on empty array (stoplightio#2050)
Co-authored-by: Garrett Brustkern <[email protected]>
1 parent 29c65da commit a4c421f

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ yarn test.harness
170170
3. In your terminal, navigate to the directory you cloned Spectral into.
171171
4. Install the dependencies: `yarn`
172172
5. Build Spectral: `yarn build`
173-
6. Run Spectral from your local installation: `./packages/cli/dist/index.js lint [openapi_spec_file]`
173+
6. Run Spectral from your local installation: `node ./packages/cli/dist/index.js lint [openapi_spec_file] --ruleset /path/to/ruleset.yaml`
174174
7. Create a new branch for your work: `git checkout -b [name_of_your_new_branch]`
175175
8. Make changes, add tests, and then run the tests: `yarn test` and `yarn workspace @stoplight/spectral-cli build.binary && yarn test.harness`
176176
9. Update the documentation if appropriate. For example, if you added a new rule to an OpenAPI ruleset,

packages/rulesets/src/oas/__tests__/operation-tags.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,26 @@ testRule('operation-tags', [
3737
},
3838
],
3939
},
40+
41+
{
42+
name: 'tags is empty',
43+
document: {
44+
swagger: '2.0',
45+
paths: {
46+
'/todos': {
47+
get: {
48+
tags: [],
49+
},
50+
},
51+
},
52+
},
53+
errors: [
54+
{
55+
code: 'operation-tags',
56+
message: 'Operation must have non-empty "tags" array.',
57+
path: ['paths', '/todos', 'get', 'tags'],
58+
severity: DiagnosticSeverity.Warning,
59+
},
60+
],
61+
},
4062
]);

packages/rulesets/src/oas/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,14 @@ const ruleset = {
290290
given: '#OperationObject',
291291
then: {
292292
field: 'tags',
293-
function: truthy,
293+
function: schema,
294+
functionOptions: {
295+
dialect: 'draft7',
296+
schema: {
297+
type: 'array',
298+
minItems: 1,
299+
},
300+
},
294301
},
295302
},
296303
'path-declarations-must-exist': {

0 commit comments

Comments
 (0)