6

RAML automatically validates included examples with the corresponding schema when you render the documentation.

Is there a way to do the same with an OpenAPI 3 spec?

codekie/swagger-examples-validator currently only supports OpenAPI 2.

Anyone knows an easy solution to check all the examples against their schemas?

Codekie
  • 7,574
  • 3
  • 18
  • 26
  • Doesn't SwaggerEditor do that for you? – MCMatan Apr 04 '19 at 16:02
  • 1
    @MCMatan at least the free version does not seem to check the examples. But codekie/swagger-examples-validator now partially supports OpenAPI 3 - `examples` properties are checked but singular `example` properties seem not to be recognized with the current version –  Apr 24 '19 at 11:34
  • codekie/openapi-examples-validator (formerly known as swagger-examples-validator) supports the singular `example`-property by now. – Codekie Nov 09 '20 at 14:33
  • I am not able to validate any example... codekie/openapi-examples-validator always returns: "Validating examples Schemas with examples found: 0 Examples without schema found: 0 Total examples found: 0 No errors found." – javi Apr 07 '21 at 17:32

1 Answers1

3

The official OpenAPI-tools don't validate referenced examples, especially because the official spec doesn't even require the example to match the schema (see: OpenAPI specification), it only states that it "should" match:

Examples of the media type. Each example object SHOULD match the media type and specified schema if present.

You will have to rely on third party tools.

One option would be codekie/openapi-examples-validator, which supports the OpenAPI 3 spec by now

Codekie
  • 7,574
  • 3
  • 18
  • 26