This package contains the official JSON Schemas for every version of Swagger/OpenAPI Specification:
Version | Schema | Docs |
---|---|---|
Swagger 1.2 | v1.2 schema | v1.2 docs |
Swagger 2.0 | v2.0 schema | v2.0 docs |
OpenAPI 3.0.x | v3.0.x schema | v3.0.3 docs |
OpenAPI 3.1.x | v3.1.x schema | v3.1.0 docs |
You can install OpenAPI Schemas via npm.
npm install @readme/openapi-schemas
The library contains all OpenAPI Specification versions:
import { openapi } from '@readme/openapi-schemas';
console.log(openapi.v1); // { $schema, id, properties, definitions, ... }
console.log(openapi.v2); // { $schema, id, properties, definitions, ... }
console.log(openapi.v3); // { $schema, id, properties, definitions, ... }
console.log(openapi.v31); // { $schema, id, properties, definitions, ... }
You can use a JSON Schema validator such as Z-Schema or AJV to validate OpenAPI definitions against the specification.
import { openapi } from '@readme/openapi-schemas';
import ZSchema from 'z-schema';
// Create a ZSchema validator
let validator = new ZSchema();
// Validate an OpenAPI definition against the OpenAPI v3.0 specification
validator.validate(openapiDefinition, openapi.v31);