Socket
Socket
Sign inDemoInstall

type-openapi

Package Overview
Dependencies
10
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    type-openapi

Parse,Dereference Open API V3 Specification to Class Constructors


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
1.54 MB
Created
Weekly downloads
 

Readme

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:

  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.

Keywords

FAQs

Last updated on 13 Dec 2019

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc