UNPKG

@redocly/openapi-core

Version:

See https://github.com/Redocly/redocly-cli

28 lines (26 loc) 885 B
import { UserContext } from '../../walk'; import { Oas3_1Schema } from '../../typings/openapi'; import { getAdditionalPropertiesOption, validateExample } from '../utils'; export const NoInvalidSchemaExamples: any = (opts: any) => { const allowAdditionalProperties = getAdditionalPropertiesOption(opts) ?? false; return { Schema: { leave(schema: Oas3_1Schema, ctx: UserContext) { if (schema.examples) { for (const example of schema.examples) { validateExample( example, schema, ctx.location.child(['examples', schema.examples.indexOf(example)]), ctx, allowAdditionalProperties ); } } if (schema.example) { validateExample(schema.example, schema, ctx.location.child('example'), ctx, true); } }, }, }; };