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

211 lines
6.1 KiB
Plaintext

import { outdent } from 'outdent';
import { lintDocument } from '../../../lint';
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
import { BaseResolver } from '../../../resolve';
describe('Oas3 typed enum', () => {
it('should not report on enum object if all items match type', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
/some:
get:
responses:
'200':
description: A paged array of pets
content:
application/json:
schema:
type: integer
enum:
- 1
- 2
- 3
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-enum-type-mismatch': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
it('should not report on enum object if all items match type and enum is nullable', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
/some:
get:
responses:
'200':
description: A paged array of pets
content:
application/json:
schema:
type: string
nullable: true
enum:
- A
- B
- C
- null
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-enum-type-mismatch': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
it('should report on enum object if not all items match type', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
paths:
/some:
get:
responses:
'200':
content:
application/json:
schema:
type: integer
enum:
- 1
- string
- 3
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-enum-type-mismatch': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1some/get/responses/200/content/application~1json/schema/enum/1",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "All values of \`enum\` field must be of the same type as the \`type\` field: expected "integer" but received "string".",
"ruleId": "no-enum-type-mismatch",
"severity": "error",
"suggest": [],
},
]
`);
});
it("should report on enum object, 'string' value in enum does not have allowed types", async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.1.0
paths:
/some:
get:
responses:
'200':
content:
application/json:
schema:
type:
- integer
- array
enum:
- 1
- string
- 3
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-enum-type-mismatch': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/paths/~1some/get/responses/200/content/application~1json/schema/enum/1",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "Enum value \`string\` must be of allowed types: \`integer,array\`.",
"ruleId": "no-enum-type-mismatch",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should not crash on null schema when there is spec rule', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
info:
title: test
version: 1.2.3
paths:
/some:
get:
responses:
'200':
description: test
content:
application/json:
schema: null
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { spec: 'error', 'no-enum-type-mismatch': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"from": undefined,
"location": [
{
"pointer": "#/paths/~1some/get/responses/200/content/application~1json/schema",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "Expected type \`Schema\` (object) but got \`null\`",
"ruleId": "struct",
"severity": "error",
"suggest": [],
},
]
`);
});
});