Skip to content

Commit c363f01

Browse files
authored
fix: no-http-verbs-in-paths should not error on the verb query (#2358)
1 parent bb27e7e commit c363f01

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

.changeset/giant-years-admire.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@redocly/openapi-core": patch
3+
"@redocly/cli": patch
4+
---
5+
6+
Fixed an issue where the `no-http-verbs-in-paths` rule was incorrectly flagging path names containing the verb `query`.

docs/@v2/rules/oas/no-http-verbs-in-paths.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ List of HTTP verbs:
3030
- `delete`
3131
- `options`
3232
- `trace`
33-
- `query` (introduced in OpenAPI 3.2)
3433

3534
## API design principles
3635

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { outdent } from 'outdent';
2+
import { lintDocument } from '../../../lint.js';
3+
import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils.js';
4+
import { createConfig } from '../../../config/index.js';
5+
import { BaseResolver } from '../../../resolve.js';
6+
7+
describe('no-http-verbs-in-paths', () => {
8+
it('should report on HTTP verbs in paths', async () => {
9+
const document = parseYamlToDocument(
10+
outdent`
11+
openapi: 3.1.0
12+
paths:
13+
/path/post:
14+
get:
15+
summary: Contains http verb post in the end
16+
/get/path:
17+
get:
18+
summary: Contains http verb get in the beginning
19+
/path/query:
20+
get:
21+
summary: Should not report on query since it's not an http verb in OAS 3.1
22+
`,
23+
'foobar.yaml'
24+
);
25+
26+
const results = await lintDocument({
27+
externalRefResolver: new BaseResolver(),
28+
document,
29+
config: await createConfig({ rules: { 'no-http-verbs-in-paths': 'error' } }),
30+
});
31+
32+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
33+
[
34+
{
35+
"location": [
36+
{
37+
"pointer": "#/paths/~1path~1post",
38+
"reportOnKey": true,
39+
"source": "foobar.yaml",
40+
},
41+
],
42+
"message": "path \`/path/post\` should not contain http verb post",
43+
"ruleId": "no-http-verbs-in-paths",
44+
"severity": "error",
45+
"suggest": [],
46+
},
47+
{
48+
"location": [
49+
{
50+
"pointer": "#/paths/~1get~1path",
51+
"reportOnKey": true,
52+
"source": "foobar.yaml",
53+
},
54+
],
55+
"message": "path \`/get/path\` should not contain http verb get",
56+
"ruleId": "no-http-verbs-in-paths",
57+
"severity": "error",
58+
"suggest": [],
59+
},
60+
]
61+
`);
62+
});
63+
});

packages/core/src/rules/common/no-http-verbs-in-paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Oas2PathItem } from '../../typings/swagger.js';
55
import type { Oas3PathItem } from '../../typings/openapi.js';
66
import type { UserContext } from '../../walk.js';
77

8-
const httpMethods = ['get', 'head', 'post', 'put', 'patch', 'delete', 'options', 'trace', 'query'];
8+
const httpMethods = ['get', 'head', 'post', 'put', 'patch', 'delete', 'options', 'trace'];
99

1010
export const NoHttpVerbsInPaths: Oas3Rule | Oas2Rule = ({ splitIntoWords }) => {
1111
return {

0 commit comments

Comments
 (0)