-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): update
operation-tag-defined
rule
check for `tags` existence in `Operation` node`
- Loading branch information
1 parent
4681d7c
commit c9d7e79
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
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,6 @@ | ||
--- | ||
"@redocly/openapi-core": patch | ||
"@redocly/cli": patch | ||
--- | ||
|
||
Updated `operation-tag-defined` configurable rule. |
68 changes: 68 additions & 0 deletions
68
packages/core/src/rules/common/__tests__/operation-tag-defined.test.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,68 @@ | ||
import { outdent } from 'outdent'; | ||
import { lintDocument } from '../../../lint'; | ||
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils'; | ||
import { BaseResolver } from '../../../resolve'; | ||
|
||
describe('Oas3 operation-tag-defined', () => { | ||
it('should not report on operation object if at least one tag is defined', async () => { | ||
const document = parseYamlToDocument( | ||
outdent` | ||
openapi: 3.0.4 | ||
tags: | ||
- name: a | ||
paths: | ||
/some: | ||
get: | ||
tags: | ||
- a | ||
`, | ||
'foobar.yaml' | ||
); | ||
|
||
const results = await lintDocument({ | ||
externalRefResolver: new BaseResolver(), | ||
document, | ||
config: await makeConfig({ rules: { 'operation-tag-defined': 'error' } }), | ||
}); | ||
|
||
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`); | ||
}); | ||
|
||
it('should report on operation object if no tags are defined', async () => { | ||
const document = parseYamlToDocument( | ||
outdent` | ||
openapi: 3.0.4 | ||
tags: | ||
- name: a | ||
paths: | ||
/some: | ||
get: | ||
`, | ||
'foobar.yaml' | ||
); | ||
|
||
const results = await lintDocument({ | ||
externalRefResolver: new BaseResolver(), | ||
document, | ||
config: await makeConfig({ rules: { 'operation-tag-defined': 'error' } }), | ||
}); | ||
|
||
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"location": [ | ||
{ | ||
"pointer": "#/paths/~1some/get/tags", | ||
"reportOnKey": true, | ||
"source": "foobar.yaml", | ||
}, | ||
], | ||
"message": "Operation tags should be defined", | ||
"ruleId": "operation-tag-defined", | ||
"severity": "error", | ||
"suggest": [], | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
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