Merge pull request 'feature/31-lib_generation' (#32) from feature/31-lib_generation into dev
continuous-integration/drone/push Build is passing Details

Reviewed-on: #32
This commit is contained in:
Philipp Dormann 2020-12-15 15:41:41 +00:00
commit 39b932a81c
4 changed files with 74 additions and 4 deletions

View File

@ -92,7 +92,18 @@ steps:
tags:
- $DRONE_TAG
registry: registry.odit.services
- name: trigger lib build
depends_on: [clone]
image: plugins/downstream
settings:
server: https://ci.odit.services/
token:
from_secret: BOT_DRONE_KEY
fork: false
repositories:
- lfk/lib
params:
- SOURCE_TAG: $DRONE_TAG
trigger:
branch:
- main

1
.gitignore vendored
View File

@ -133,3 +133,4 @@ build
*.sqlite
*.sqlite-jurnal
docs
lib

View File

@ -38,11 +38,11 @@
"reflect-metadata": "^0.1.13",
"routing-controllers": "^0.9.0-alpha.6",
"routing-controllers-openapi": "^2.1.0",
"sqlite3": "^5.0.0",
"swagger-ui-express": "^4.1.5",
"typeorm": "^0.2.29",
"typeorm-routing-controllers-extensions": "^0.2.0",
"typeorm-seeding": "^1.6.1",
"sqlite3": "^5.0.0",
"uuid": "^8.3.1"
},
"devDependencies": {
@ -56,6 +56,7 @@
"axios": "^0.21.0",
"jest": "^26.6.3",
"nodemon": "^2.0.6",
"rimraf": "^2.7.1",
"start-server-and-test": "^1.11.6",
"ts-jest": "^26.4.4",
"ts-node": "^9.0.0",
@ -69,7 +70,8 @@
"test": "jest",
"test:watch": "jest --watchAll",
"test:ci": "start-server-and-test dev http://localhost:4010/api/openapi.json test",
"seed": "ts-node ./node_modules/typeorm/cli.js schema:sync && ts-node ./node_modules/typeorm-seeding/dist/cli.js seed"
"seed": "ts-node ./node_modules/typeorm/cli.js schema:sync && ts-node ./node_modules/typeorm-seeding/dist/cli.js seed",
"openapi:export": "ts-node src/openapi_export.ts"
},
"nodemonConfig": {
"ignore": [
@ -77,4 +79,4 @@
"docs/*"
]
}
}
}

56
src/openapi_export.ts Normal file
View File

@ -0,0 +1,56 @@
import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
import consola from "consola";
import fs from "fs";
import "reflect-metadata";
import { createExpressServer, getMetadataArgsStorage } from "routing-controllers";
import { routingControllersToSpec } from 'routing-controllers-openapi';
import authchecker from "./authchecker";
import { config } from './config';
import { ErrorHandler } from './middlewares/ErrorHandler';
const CONTROLLERS_FILE_EXTENSION = process.env.NODE_ENV === 'production' ? 'js' : 'ts';
createExpressServer({
authorizationChecker: authchecker,
middlewares: [ErrorHandler],
development: config.development,
cors: true,
routePrefix: "/api",
controllers: [`${__dirname}/controllers/*.${CONTROLLERS_FILE_EXTENSION}`],
});
const storage = getMetadataArgsStorage();
const schemas = validationMetadatasToSchemas({
refPointerPrefix: "#/components/schemas/",
});
//Spec creation based on the previously created schemas
const spec = routingControllersToSpec(
storage,
{
routePrefix: "/api"
},
{
components: {
schemas,
"securitySchemes": {
"AuthToken": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
}
}
},
info: {
description: "The the backend API for the LfK! runner system.",
title: "LfK! Backend API",
version: "1.0.0",
},
}
);
try {
fs.writeFileSync("./openapi.json", JSON.stringify(spec), { encoding: "utf-8" });
consola.success("Exported openapi spec to openapi.json");
} catch (error) {
consola.error("Couldn't export the openapi spec");
}