Compare commits

...

2 Commits

3 changed files with 34 additions and 8 deletions

View File

@ -25,6 +25,7 @@
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"class-transformer": "^0.3.1", "class-transformer": "^0.3.1",
"class-validator": "^0.12.2", "class-validator": "^0.12.2",
"class-validator-jsonschema": "^2.0.3",
"consola": "^2.15.0", "consola": "^2.15.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.17.1", "express": "^4.17.1",

View File

@ -2,10 +2,23 @@ import { Application } from "express";
import * as swaggerUiExpress from "swagger-ui-express"; import * as swaggerUiExpress from "swagger-ui-express";
import { getMetadataArgsStorage } from "routing-controllers"; import { getMetadataArgsStorage } from "routing-controllers";
import { routingControllersToSpec } from "routing-controllers-openapi"; import { routingControllersToSpec } from "routing-controllers-openapi";
import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
export default async (app: Application) => { export default async (app: Application) => {
const storage = getMetadataArgsStorage(); 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)); app.use("/docs", swaggerUiExpress.serve, swaggerUiExpress.setup(spec));
return app; return app;
}; };

View File

@ -1,14 +1,26 @@
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";
import {
IsInt,
IsNotEmpty,
IsOptional,
IsPositive,
IsString,
} from "class-validator";
@Entity() @Entity()
export class Track { export class Track {
@PrimaryGeneratedColumn() @PrimaryGeneratedColumn()
@IsOptional()
@IsInt()
id: number; id: number;
@Column() @Column()
@IsString()
@IsNotEmpty()
name: string; name: string;
//Length in meters
@Column() @Column()
@IsInt()
@IsPositive()
length: string; length: string;
} }