Skip to content

Commit

Permalink
fix(rulesets): operation-tags should fail on empty array (#2050)
Browse files Browse the repository at this point in the history
Co-authored-by: Garrett Brustkern <[email protected]>
  • Loading branch information
eazy-g and Garrett Brustkern authored Feb 7, 2022
1 parent 29c65da commit a4c421f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ yarn test.harness
3. In your terminal, navigate to the directory you cloned Spectral into.
4. Install the dependencies: `yarn`
5. Build Spectral: `yarn build`
6. Run Spectral from your local installation: `./packages/cli/dist/index.js lint [openapi_spec_file]`
6. Run Spectral from your local installation: `node ./packages/cli/dist/index.js lint [openapi_spec_file] --ruleset /path/to/ruleset.yaml`
7. Create a new branch for your work: `git checkout -b [name_of_your_new_branch]`
8. Make changes, add tests, and then run the tests: `yarn test` and `yarn workspace @stoplight/spectral-cli build.binary && yarn test.harness`
9. Update the documentation if appropriate. For example, if you added a new rule to an OpenAPI ruleset,
Expand Down
22 changes: 22 additions & 0 deletions packages/rulesets/src/oas/__tests__/operation-tags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,26 @@ testRule('operation-tags', [
},
],
},

{
name: 'tags is empty',
document: {
swagger: '2.0',
paths: {
'/todos': {
get: {
tags: [],
},
},
},
},
errors: [
{
code: 'operation-tags',
message: 'Operation must have non-empty "tags" array.',
path: ['paths', '/todos', 'get', 'tags'],
severity: DiagnosticSeverity.Warning,
},
],
},
]);
9 changes: 8 additions & 1 deletion packages/rulesets/src/oas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,14 @@ const ruleset = {
given: '#OperationObject',
then: {
field: 'tags',
function: truthy,
function: schema,
functionOptions: {
dialect: 'draft7',
schema: {
type: 'array',
minItems: 1,
},
},
},
},
'path-declarations-must-exist': {
Expand Down

0 comments on commit a4c421f

Please sign in to comment.