@loopback/openapi-v2
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

DEPRECATION NOTICE

This package has been deprecated in favor of OpenAPI Spec version 3.0.0, we are no longer maintaining it.

@loopback/openapi-v2

This package contains:

  • Decorators that describe LoopBack artifacts as OpenAPI v2 (Swagger) metadata.
  • Utilities that transfer LoopBack metadata to OpenAPI v2 (Swagger) swagger specifications.

Overview

The package has functions described above for LoopBack controller classes. Decorators apply REST api mapping metadata to controller classes and their members. And utilities that inspect controller classes to build OpenAPI v2 (Swagger) specifications from REST api mapping metadata.

Functions for more artifacts will be added when we need.

Installation

$ npm install --save @loopback/openapi-v2

Basic use

Currently this package only has spec generator for controllers. It generates swagger paths and basePath specs for a given decorated controller class.

Here is an example of calling function getControllerSpec to generate the swagger spec:

import {api, getControllerSpec} from '@loopback/openapi-v2';

@api(somePathSpec)
class MyController {
    greet() {
        return 'Hello world!';
    }
}

const myControllerSpec = getControllerSpec(MyController);

then the myControllerSpec will be:

{
    swagger: '2.0',
    basePath: '/',
    info: { title: 'LoopBack Application', version: '1.0.0' },
    paths: { 
        '/greet': { 
            get: {
                responses:  { 
                    '200': { 
                        description: 'The string result.', 
                        schema: { type: 'string' } 
                    } 
                },
                'x-operation-name': 'greet' 
            }
        } 
    } 
}

For details of how to apply controller decorators, please check http://loopback.io/doc/en/lb4/Decorators.html#route-decorators

Related resources

See https://www.openapis.org/ and version 2.0 of OpenAPI Specification.

Contributions

IBM/StrongLoop is an active supporter of open source and welcomes contributions to our projects as well as those of the Node.js community in general. For more information on how to contribute please refer to the Contribution Guide.

Tests

run npm test from the root folder.

Contributors

See all contributors.

License

MIT

Package Sidebar

Install

npm i @loopback/openapi-v2

Weekly Downloads

8

Version

0.3.0

License

MIT

Unpacked Size

550 kB

Total Files

92

Last publish

Collaborators

  • rfeng
  • bajtos
  • rmg
  • hacksparrow
  • dhmlau
  • jerry-apic
  • theprez