Skip to content

jolocom/oas3-tools-object-oriented

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

oas3-tools-object-oriented

'oas3-tools-object-oriented' helps to reach 'API-First' approach by using 'oas3-tools' and the client app implementing OOP paradigm.

It will wire up 'OpenAPI Specification' declaration with controllers classes methods, since 'oas3-tools' supports only functions definitions, which makes impossible to work with classes and its methods. To resolve this problem - this middleware was implemented - it will create and configure 'oas3-tools' application based on provided collection of controllers instances.

Installation

Use the package manager npm or yarn to install 'oas3-tools-object-oriented'.

Npm:

npm install oas3-tools-object-oriented

Yarn:

yarn add oas3-tools-object-oriented

Usage

  1. Implement 'Oas3ToolsObjectOrientedConfig' interface to configure 'oas3-tools' if necessary, and path to the oas3 declaration file:
import { Oas3ToolsObjectOrientedOptions } from '@jolocom/oas3-tools-object-oriented'

const config: Oas3ToolsObjectOrientedConfig = {
  oas3DeclarationFilePath: './api/openapi.yaml',
  oas3AppOptions: {
    routing: {
      ignoreMissingHandlers: true,
      useStubs: true,
    },
    openApiValidator: {
      apiSpec: './api/openapi.yaml',
      // ...other validator configuration options
    },
    logging: {
      errorLimit: 400,
      // ...other logging configuration options
    },
    swaggerUI: {
      swaggerUIPath: '/docs',
      // ...other swaggerUI configuration options
    },
  }
}
  1. Use middleware:
import { oas3ToolsObjectOriented } from '@jolocom/oas3-tools-object-oriented'

const config: Oas3ToolsObjectOrientedOptions = {
  // ...configuration from the step #1
}

// ...app initialization

const controllers: object[] = [/** Controllers instances collection */]

app.use(oas3ToolsObjectOriented(controllers, config))

// ...end of middlewares and app initialization process

License

Apache-2.0