persona-community-5/.pnpm-store/v3/files/5e/abdaf14ed2957d76024227342d8b644ab7564997ab6cbdf8b41b9bf750cd9b31e231e42f3ab35aac2d2330f86b7f6d5f572abeb3405830888daed3024445c5
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

203 lines
5.5 KiB
Plaintext

import { outdent } from 'outdent';
import { lintDocument } from '../../../lint';
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
import { BaseResolver } from '../../../resolve';
describe('Oas3 path-params-defined', () => {
it('should not report on defined params', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
/pets/{a}/{b}:
parameters:
- name: a
in: path
get:
parameters:
- name: b
in: path
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'path-params-defined': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
it('should report on undefined param params', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
/pets/{a}/{b}:
parameters:
- name: a
in: path
- name: b
in: header
get:
parameters:
- name: b
in: query
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'path-params-defined': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1pets~1{a}~1{b}/get/parameters",
"reportOnKey": true,
"source": "foobar.yaml",
},
],
"message": "The operation does not define the path parameter \`{b}\` expected by path \`/pets/{a}/{b}\`.",
"ruleId": "path-params-defined",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should report on undeclared param', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
/pets/{a}:
parameters:
- name: a
in: path
- name: d
in: path
get:
parameters:
- name: c
in: path
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'path-params-defined': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1pets~1{a}/parameters/1/name",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "Path parameter \`d\` is not used in the path \`/pets/{a}\`.",
"ruleId": "path-params-defined",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/paths/~1pets~1{a}/get/parameters/0/name",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "Path parameter \`c\` is not used in the path \`/pets/{a}\`.",
"ruleId": "path-params-defined",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should fail cause POST has no parameters', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
/pets/{a}:
get:
parameters:
- name: a
in: path
post:
description: without parameters
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'path-params-defined': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1pets~1{a}/post/parameters",
"reportOnKey": true,
"source": "foobar.yaml",
},
],
"message": "The operation does not define the path parameter \`{a}\` expected by path \`/pets/{a}\`.",
"ruleId": "path-params-defined",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should apply parameters for POST operation from path parameters', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
/pets/{a}:
parameters:
- name: a
in: path
get:
parameters:
- name: a
in: path
post:
description: without parameters
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'path-params-defined': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
});