persona-community-5/.pnpm-store/v3/files/e3/95532e11c1a5e686eccbdc2e3eff0aecca8f3e337fbc05645717875255b72b88c3baf426891615ecb922cf8e68e9ebb2a37c926c5db10f4ed9487f07c45956
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

87 lines
2.4 KiB
Plaintext

import { outdent } from 'outdent';
import { lintDocument } from '../../../lint';
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
import { BaseResolver } from '../../../resolve';
describe('no-invalid-schema-examples', () => {
it('should report on invalid falsy example', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.1.0
components:
schemas:
Car:
type: object
properties:
color:
type: string
example: 0
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-invalid-schema-examples': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
[
{
"from": {
"pointer": "#/components/schemas/Car/properties/color",
"source": "foobar.yaml",
},
"location": [
{
"pointer": "#/components/schemas/Car/properties/color/example",
"reportOnKey": false,
"source": "foobar.yaml",
},
],
"message": "Example value must conform to the schema: type must be string.",
"ruleId": "no-invalid-schema-examples",
"severity": "error",
"suggest": [],
},
]
`);
});
it('should not report on nullable example for OAS3', async () => {
const document = parseYamlToDocument(
outdent`
openapi: 3.0.3
info: {}
paths:
/subscriptions:
get:
responses:
"200":
content:
application/json:
schema:
nullable: true
type: object
example: null
allOf:
- $ref: "#/components/schemas/RiskMetadata"
components:
schemas:
RiskMetadata:
type: object
`,
'foobar.yaml'
);
const results = await lintDocument({
externalRefResolver: new BaseResolver(),
document,
config: await makeConfig({ rules: { 'no-invalid-schema-examples': 'error' } }),
});
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
});
});