@redocly/openapi-core
Version:
See https://github.com/Redocly/redocly-cli
44 lines • 1.89 kB
JavaScript
import { isDefined } from '../../utils/is-defined.js';
import { validateExample } from '../utils.js';
export const NoInvalidSchemaExamples = (opts) => {
return {
Schema: {
leave(schema, ctx) {
const examples = schema.examples;
if (Array.isArray(examples)) {
for (const example of examples) {
validateExample({
example,
schema,
options: {
location: ctx.location.child(['examples', examples.indexOf(example)]),
ctx,
allowAdditionalProperties: !!opts.allowAdditionalProperties,
},
reference: 'https://redocly.com/docs/cli/rules/oas/no-invalid-schema-examples',
});
}
}
if (isDefined(schema.example)) {
// Handle nullable example for OAS3
if (schema.nullable === true &&
schema.example === null &&
schema.type !== undefined) {
return;
}
validateExample({
example: schema.example,
schema,
options: {
location: ctx.location.child('example'),
ctx,
allowAdditionalProperties: !!opts.allowAdditionalProperties,
},
reference: 'https://redocly.com/docs/cli/rules/oas/no-invalid-schema-examples',
});
}
},
},
};
};
//# sourceMappingURL=no-invalid-schema-examples.js.map