persona-community-5/.pnpm-store/v3/files/85/5327d3ba948fddde7800cecef6ee7571210392a8b736d9bac9e32ceeffd2091a54896a87e1cab49d21f53b38ace280e914b324bb3046040cebe2ea8aa675f8
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

206 lines
5.7 KiB
Plaintext

import { outdent } from 'outdent';
import { lintDocument } from '../../../lint';
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
import { BaseResolver } from '../../../resolve';
describe('Oas3 as3-no-server-variables-empty-enum', () => {
it('oas3-no-server-variables-empty-enum: should report on server object with empty enum and unknown enum value', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
info:
title: API
version: 1.0.0
servers:
- url: https://example.com/{var}
variables:
var:
enum: []
default: a
components: {}
`
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-server-variables-empty-enum': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/servers",
"reportOnKey": true,
"source": "",
},
],
"message": "Server variable with \`enum\` must be a non-empty array.",
"ruleId": "no-server-variables-empty-enum",
"severity": "error",
"suggest": [],
},
{
"location": [
{
"pointer": "#/servers",
"reportOnKey": true,
"source": "",
},
],
"message": "Server variable define \`enum\` and \`default\`. \`enum\` must include default value",
"ruleId": "no-server-variables-empty-enum",
"severity": "error",
"suggest": [],
},
]
`);
});
it('oas3-no-server-variables-empty-enum: should report on server object with empty enum', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
info:
title: API
version: 1.0.0
servers:
- url: https://example.com/{var}
variables:
var:
enum: []
components: {}
`
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-server-variables-empty-enum': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"location": [
{
"pointer": "#/servers",
"reportOnKey": true,
"source": "",
},
],
"message": "Server variable with \`enum\` must be a non-empty array.",
"ruleId": "no-server-variables-empty-enum",
"severity": "error",
"suggest": [],
},
]
`);
});
it('oas3-no-server-variables-empty-enum: should be success because variables is empty object', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
info:
title: API
version: 1.0.0
servers:
- url: https://example.com/{var}
variables: {}
components: {}
`
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-server-variables-empty-enum': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
it('oas3-no-server-variables-empty-enum: should be success because variable is empty object', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
info:
title: API
version: 1.0.0
servers:
- url: https://example.com/{var}
variables:
var: {}
components: {}
`
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-server-variables-empty-enum': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
it('oas3-no-server-variables-empty-enum: should be success because enum contains default value', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
info:
title: API
version: 1.0.0
servers:
- url: https://example.com/{var}
variables:
var:
enum:
- a
default: a
components: {}
`
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-server-variables-empty-enum': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
it('oas3-no-server-variables-empty-enum: should be success because enum contains default value', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.0
info:
title: API
version: 1.0.0
servers:
- url: https://example.com/{var}
variables:
var:
type: ['string', 'null']
enum:
- 'some string'
- null
default: 'some string'
components: {}
`
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-server-variables-empty-enum': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
});