Now creating (json)schemas from class validator annotated classes

ref #5
This commit is contained in:
2020-11-26 13:44:36 +01:00
parent a6bd723511
commit 796b8942d8
2 changed files with 15 additions and 1 deletions

View File

@@ -2,10 +2,23 @@ import { Application } from "express";
import * as swaggerUiExpress from "swagger-ui-express";
import { getMetadataArgsStorage } from "routing-controllers";
import { routingControllersToSpec } from "routing-controllers-openapi";
import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
export default async (app: Application) => {
const storage = getMetadataArgsStorage();
const spec = routingControllersToSpec(storage);
const schemas = validationMetadatasToSchemas({
refPointerPrefix: '#/components/schemas/',
});
const spec = routingControllersToSpec(storage, {}, {
components: {
schemas,
info: {
description: 'LfK! Backend API`',
title: 'LfK! Backend API',
version: '1.0.0'
}
});
app.use("/docs", swaggerUiExpress.serve, swaggerUiExpress.setup(spec));
return app;
};