Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static fromRoutes(info: InfoObject,
flattened: Route[]): OpenApiBuilder {
const openAPI = new OpenApiBuilder().addInfo(info);
// create each path from a corresponding route
const paths = flattened.reduce((acc, route) => {
const item: PathItemObject = acc[route.path] || { };
// skeleton operation object
const operation: OperationObject = {
description: route.description || '',
responses: { },
summary: route.summary || '',
parameters: []
};
// handle request body
if (route.request && route.request.body) {
const content: ContentObject = Object.entries(route.request.body)
.map(([contentType, clazz]) => ({ contentType, schema: OpenAPI.makeSchemaObject(clazz) }))
.reduce((acc, { contentType, schema }) => {
acc[contentType] = { schema };