'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.
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
- 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
},
}
}
- 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