persona-community-5/.pnpm-store/v3/files/78/b16ca80bfdfed3599c1797984b913e4243f801f933765e70b149b57dc6c37843dda1550b0adc06adfb6070a3d04cd13b0c9f6d19e6b00df8d03700cca31254
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

168 lines
4.6 KiB
Plaintext

import { outdent } from 'outdent';
import { lintDocument } from '../../../lint';
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
import { BaseResolver } from '../../../resolve';
describe('Oas3 operation-parameters-unique', () => {
it('should report on duplicated path params', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/test':
parameters:
- name: a
in: query
- name: a
in: query
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'operation-parameters-unique': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1test/parameters/1",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "Paths must have unique \`name\` + \`in\` parameters.
Repeats of \`in:query\` + \`name:a\`.",
"ruleId": "operation-parameters-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should not report when operation overwrites path param', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/test':
parameters:
- name: a
in: query
put:
parameters:
- name: a
in: query
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'operation-parameters-unique': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
it('should report when operation with duplicated params', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/test':
parameters:
- name: a
in: query
put:
parameters:
- name: a
in: query
- name: a
in: path
- name: a
in: query
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'operation-parameters-unique': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1test/put/parameters/2",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "Operations must have unique \`name\` + \`in\` parameters. Repeats of \`in:query\` + \`name:a\`.",
"ruleId": "operation-parameters-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should report when operation with duplicated params via $ref', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
'/test':
parameters:
- $ref: '#/components/parameters/a'
put:
parameters:
- $ref: '#/components/parameters/a'
- name: a
in: path
- $ref: '#/components/parameters/a'
components:
parameters:
a:
in: query
name: a
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'operation-parameters-unique': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1test/put/parameters/2",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "Operations must have unique \`name\` + \`in\` parameters. Repeats of \`in:query\` + \`name:a\`.",
"ruleId": "operation-parameters-unique",
"severity": "error",
"suggest": [],
},
]
`);
});
});