Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function parseSchemaLike(c: SchemaLike, modelsToParse: Array): O3TS.SchemaObject | O3TS.ReferenceObject {
// It's important to note that this method DOES have a side effect: it
// adds any found models to `modelsToParse`.
if (typeof(c) === 'function') {
return inferSchema(c, modelsToParse);
} else if (Array.isArray(c)) {
return { type: 'array', items: parseSchemaLike(c[0], modelsToParse) };
} else if (isReferenceObject(c)) {
return c;
} else { // O3TS.SchemaObjects, but potentially with deeper schemaLikes.
const ret: O3TS.SchemaObject = {
...c,
};
if (c.allOf) {
ret.allOf = c.allOf.map(sub => parseSchemaLike(sub, modelsToParse));
}
if (c.anyOf) {
ret.anyOf = c.anyOf.map(sub => parseSchemaLike(sub, modelsToParse));
}
if (c.oneOf) {
ret.oneOf = c.oneOf.map(sub => parseSchemaLike(sub, modelsToParse));
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 };
function transform(routes: RouteInfo[]) {
const group = groupRoutes(routes)
const paths = transformPaths(group)
return OpenApiBuilder.create({
openapi: "3.0.0",
info: { title: "title", version: "1.0.0" },
paths
}).getSpec()
}
private generateApiOpenApiSpecBuilder(appConfig: AppConfig, middlewareRegistry: MiddlewareRegistry) {
let openApiBuilder = OpenApiBuilder.create()
let paths: IDictionary = {}
let tags: IDictionary = {}
this.logger.debug("Generating OpenAPI spec")
if (appConfig.name) {
this.logger.trace("title: %s", appConfig.name)
openApiBuilder.addTitle(appConfig.name)
}
if (appConfig.version) {
this.logger.trace("version: %s", appConfig.version)
openApiBuilder.addVersion(appConfig.version)
}