JSPM

  • Created
  • Published
  • Downloads 1920843
  • Score
    100M100P100Q192153F
  • License BSD-3-Clause

Convert Swagger 2.0 specifications to OpenApi 3.0

Package Exports

  • swagger2openapi
  • swagger2openapi/common.js
  • swagger2openapi/package.json
  • swagger2openapi/validate
  • swagger2openapi/validate.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 (swagger2openapi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

swagger2openapi

logo

OpenAPI Validation Build Tested on APIs.guru Tested on Mermade OpenAPIs Coverage Status Known Vulnerabilities

Convert Swagger 2.0 definitions into OpenApi 3.0.x

Currently tracking v3.0.0-RC0

Usage:

swagger2openapi [options] [filename|url]
Options:
  -d, --debug    enable debug mode, adds specification-extensions      [boolean]
  -e, --encoding encoding for input/output files      [string] [default: "utf8"]
  -h, --help     Show help                                             [boolean]
  -o, --outfile  the output file to write to                            [string]
  -u, --url      url of original spec, creates x-origin entry           [string]
  -y, --yaml     read and write YAML, default JSON                     [boolean]

or use the APIs:

var converter = require('swagger2openapi');
var options = {};
//options.debug = true; // sets various x-s2o- debugging properties
var openapi = converter.convertSync(swagger, options);
// also available are asynchronous convertObj, convertFile, convertUrl and convertStr functions
var validator = require('swagger2openapi/validate.js');
var options = {};
var result = validator.validate(openapi, options); // returns boolean, throws on error
// options.context now contains a stack (array) of JSON-Pointer strings

Or use the online version which also includes an API

Specification extensions

swagger2openapi has support for a limited number of real-world specification extensions which have a direct bearing on the conversion. All other specification extensions are left untouched.

Specification Extension Vendor Conversion Performed
x-ms-paths Microsoft Treated as an analogue of the openapi.paths object
x-ms-skip-url-encoding Microsoft For query parameters, converted to allowReserved:true
x-ms-odata Microsoft References to #/definitions/ are updated to #/components/schemas
x-ms-parameterized-host Microsoft TODO Not seen in the wild
x-anyOf Open Nitro Project Within schemas, converted to anyOf
x-oneOf Open Nitro Project Within schemas, converted to oneOf
x-not Open Nitro Project Within schemas, converted to not

See also Amazon API Gateway specification extensions

It is expected to be able to configure the process of vendor-extension modification using options or a plugin mechanism in a future release.

Tests

To run a test-suite:

node testRunner [-f {path-to-expected-failures}]... [{path-to-APIs|single-file...}]

The test harness currently expects files with a .json or .yaml extension, or a single named file, and has been tested on Node.js versions 4.x, 6.x and 7.x against

It can also be used as a simple validator if given an existing OpenAPI 3.x definition. The validator (however it is called) uses WHATWG URL parsing if available (node 7.x and above).

Metadata reporting

Also included is a tool reportExtensions to gather a list of vendor (specification) extensions and formats used in a definition or corpus of definitions. For examples of output, see the wiki