🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

type-openapi

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-openapi

Parse,Dereference Open API V3 Specification to Class Constructors

1.0.0
latest
Source
npm
Version published
Maintainers
1
Created
Source

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:

  • Install module:

    npm install type-openapi
    
  • 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.

Keywords

swagger

FAQs

Package last updated on 13 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts