Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate openapi 3.0.0 yaml spec?

I have a yaml specification that has been updated from swagger 2.0 to openapi 3.0.0.

The file itself is about 7,000 lines so it is challenging to validate by hand.

I need to figure out which tags I have are no longer compatible with openapi 3.0.0. How can I validate my schema? Are there any command line tools I can use?

I do not want to copy/paste this code somewhere online because I don't want to expose all the routes publicly.

like image 418
William Ross Avatar asked Feb 13 '20 20:02

William Ross


People also ask

How do I validate a Swagger file?

Swagger relies on another standard called JSON Schema for its schema objects, which are what actually describes the JSON (rather than endpoints or metadata). Swagger uses a subset of JSON Schema (missing: oneOf , patternProperties , among others). To that end, you can use a JSON Schema validator.

What is OpenAPI validation?

The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to HTTP APIs. This allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection.


3 Answers

Swagger Editor

https://editor.swagger.io performs validation on the client side, meaning your definition is not sent anywhere. You can also run the editor locally, e.g. offline.

Notes:

  • Because of lazy loading you may need to expand all operations and models in the UI panel to see all of the errors.

  • Warnings are displayed as gutter icons, apart from the error list.

Other validators

https://openapi.tools has a list of OpenAPI validation tools, including command-line tools and Node.js modules.

like image 117
Helen Avatar answered Sep 22 '22 21:09

Helen


Use openapi-lint extension on visual studio code and remember to name your file as *openapi.json, *openapi.yaml, *openapi.yml, *oas3.json, *oas3.yml, *oas3yaml.

like image 32
Klement Tan Avatar answered Sep 23 '22 21:09

Klement Tan


I use swagger-cli. It's a validator and bundler that supports $ref among other things.

like image 20
Devy Avatar answered Sep 24 '22 21:09

Devy