question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenAPI 3.1 examples not validating through AJV using OpenAPI 3.1 spec

See original GitHub issue

Hello, there is a lot of JavaScript tooling that uses AJV to validate OpenAPI specs. None of it seems to support 3.1, which is really unfortunate. I was trying to remedy the situation, but failed miserably.

As far as I can tell (see https://github.com/ajv-validator/ajv/issues/1745) even the examples in your OpenAPI3.1 folder do not pass validation. The AJV folks (understandably) won’t help unless I create a minimal reproducible example of a failing schema, which I’m not really qualified to do.

Would you be able to help/shed light on what’s going on?

Copying the relevant details:

Ajv options object

{
    allErrors: true, 
    validateFormats: false, 
    strictSchema: false, 
    strictTypes: false
}

See OAI/OpenAPI-Specification#2489 for a discussion on the options.

JSON Schema

The OpenAPI 3.1 schema defined here: https://github.com/OAI/OpenAPI-Specification/blob/main/schemas/v3.1/schema.json

Sample data

the OpenApi v3.1 webhook example here: https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.json

Your code

See: https://runkit.com/essential-randomness/612d87df07ae0a00092a3492.

This simply call ajv with the given options, passes the OpenApiv3.1 schema and tries to validate the OpenApi Webhook example.

Validation result, data AFTER validation, error messages

Error message:

Invalid: 
data/webhooks/newPet/post/requestBody/content/application~1json/schema must NOT have unevaluated properties, 
data/webhooks/newPet/post/requestBody must match "else" schema,
data/webhooks/newPet must match "else" schema, 
data/components/schemas/Pet must NOT have unevaluated properties, 
data/components/schemas/Pet must NOT have unevaluated properties


Thank you! Hopefully the errors are more understandable if you can read schemas 😃

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MatanYeminicommented, Mar 22, 2022

any updates?

0reactions
jdesrosierscommented, Sep 10, 2022

@no-identd Upgrading AJV won’t fix this problem until AJV fixes the bug responsible for the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@seriousme/openapi-schema-validator - npm
A JSON schema validator for OpenAPI specifications, it currently supports: 2.0 · 3.0.x · 3.1.x. Tested on over 2,000 real-world APIs from AWS, ......
Read more >
OpenAPI validator does not accept OAS version 3.1 - YouTrack
The schema.yaml schema doesn't validate the JSON Schemas in your OpenAPI document because 3.1 allows you to use any JSON Schema dialect you...
Read more >
OpenAPI.Tools
Microcks - Kubernetes native tool for API Mocking and Testing. Turn your OAI contract examples into ready to use mocks. Use examples to...
Read more >
Validating OpenAPI and JSON Schema
Starting with the release of OpenAPI 3.1, the dialect of JSON Schema used in OpenAPI documents is configurable. By default, you get the ......
Read more >
oneOf, anyOf, allOf, not - Swagger
OpenAPI 3.0 provides several keywords which you can use to combine schemas. ... The example above shows how to validate the request body...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found