1.0.0 • Published 4 years ago

type-openapi v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

type-openapi

Features

  • Parses open api v3 specs in JSON or YAML format
  • load open api v3 from file, url, json string, plain javascript object
  • Resolves all $ref pointers, including external files and URLs
  • Construct open api to calsses
  • Get embedded object and properties like vendor extension, security requirements
  • Type safety

Example

  • typescript async/await
import "reflect-metadata";
import {Loader, OpenAPi} from 'type-openapi'
async  function Example() {
    const url = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/api-with-examples.yaml"
    const spec: OpenAPi = await Loader.loadFromURL(url)
    console.log(spec)
} 
  • typescript callback
import "reflect-metadata";
import {CallbackLoader, OpenAPi} from 'type-openapi'
 function Example() {
    const url = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/api-with-examples.yaml"
    CallbackLoader.loadFromURL(url, (err: Error, spec: OpenApi) => {
    	if (err) {
        	console.log(err)
        }
        console.log(spec)
    });
    
} 
  • javascript async/await
require("reflect-metadata");
const {Loader} = require('type-openapi')
async  function Example() {
    const url = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/api-with-examples.yaml"
    const spec = await Loader.loadFromURL(url)
    console.log(spec)
} 
  • javascript callback
require("reflect-metadata");
const {CallbackLoader} = require('type-openapi')
 function Example() {
    const url = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/api-with-examples.yaml"
    CallbackLoader.loadFromURL(url, (err, spec) => {
    	if (err) {
        	console.log(err)
        }
        console.log(spec)
    });
} 

Installation

Install using npm:

  1. Install module:

    npm install type-openapi
  2. reflect-metadata shim is required, install it too:

    npm install reflect-metadata

    and make sure to import it in a global place, like app.ts:

    import "reflect-metadata";

    OR

    require("reflect-metadata");

API Documentation

Full API documentation is available right here

Contributing

I welcome any contributions, features, enhancements, and bug-fixes. File an issue on GitHub and submit a pull request.

License

Type OpenAPi is 100% free and open-source, under the MIT license. Use it however you want.