Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rulesets): operation-tags should fail on empty array #2050

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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