JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 169860
  • Score
    100M100P100Q184289F
  • License Apache-2.0

An AsyncAPI schema parser for OpenAPI 3.0.x and Swagger 2.x schemas.

Package Exports

  • @asyncapi/openapi-schema-parser
  • @asyncapi/openapi-schema-parser/cjs/index.js
  • @asyncapi/openapi-schema-parser/esm/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@asyncapi/openapi-schema-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

OpenAPI Schema Parser

An AsyncAPI schema parser for OpenAPI 3.0.x and Swagger 2.x schemas.

Note Version >= 3.0.0 of package is only supported by @asyncapi/parser version >= 2.0.0.

Installation

npm install @asyncapi/openapi-schema-parser
// OR
yarn add @asyncapi/openapi-schema-parser

Usage

import { Parser } from '@asyncapi/parser';
import { OpenAPISchemaParser } from '@asyncapi/openapi-schema-parser';

const parser = new Parser();
parser.registerSchemaParser(OpenAPISchemaParser()); 

const asyncapiWithOpenAPI = `
asyncapi: 2.0.0
info:
  title: Example with OpenAPI
  version: 0.1.0
channels:
  example:
    publish:
      message:
        schemaFormat: 'application/vnd.oai.openapi;version=3.0.0'
        payload: # The following is an OpenAPI schema
          type: object
          properties:
            title:
              type: string
              nullable: true
            author:
              type: string
              example: Jack Johnson
`;

const { document } = await parser.parse(asyncapiWithOpenAPI);
const { Parser } = require('@asyncapi/parser');
const { OpenAPISchemaParser } = require('@asyncapi/openapi-schema-parser');

const parser = new Parser();
parser.registerSchemaParser(OpenAPISchemaParser()); 

const asyncapiWithOpenAPI = `
asyncapi: 2.0.0
info:
  title: Example with OpenAPI
  version: 0.1.0
channels:
  example:
    publish:
      message:
        schemaFormat: 'application/vnd.oai.openapi;version=3.0.0'
        payload: # The following is an OpenAPI schema
          type: object
          properties:
            title:
              type: string
              nullable: true
            author:
              type: string
              example: Jack Johnson
`;

const { document } = await parser.parse(asyncapiWithOpenAPI);

It also supports referencing remote OpenAPI schemas:

import { Parser } from '@asyncapi/parser';
import { OpenAPISchemaParser } from '@asyncapi/openapi-schema-parser';

const parser = new Parser();
parser.registerSchemaParser(OpenAPISchemaParser()); 

const asyncapiWithOpenAPI = `
asyncapi: 2.0.0
info:
  title: Example with OpenAPI
  version: 0.1.0
channels:
  example:
    publish:
      message:
        schemaFormat: 'application/vnd.oai.openapi;version=3.0.0'
        payload:
          $ref: 'yourserver.com/schemas#/Book'
`;

const { document } = await parser.parse(asyncapiWithOpenAPI);