@redocly/openapi-core
Version:
See https://github.com/Redocly/redocly-cli
34 lines • 1.4 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, {
location: ctx.location.child(['examples', examples.indexOf(example)]),
ctx,
allowAdditionalProperties: !!opts.allowAdditionalProperties,
});
}
}
if (isDefined(schema.example)) {
// Handle nullable example for OAS3
if (schema.nullable === true &&
schema.example === null &&
schema.type !== undefined) {
return;
}
validateExample(schema.example, schema, {
location: ctx.location.child('example'),
ctx,
allowAdditionalProperties: !!opts.allowAdditionalProperties,
});
}
},
},
};
};
//# sourceMappingURL=no-invalid-schema-examples.js.map