feature/31-lib_generation #32
13
.drone.yml
13
.drone.yml
@ -92,7 +92,18 @@ steps:
|
|||||||
tags:
|
tags:
|
||||||
- $DRONE_TAG
|
- $DRONE_TAG
|
||||||
registry: registry.odit.services
|
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:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
- main
|
- main
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -133,3 +133,4 @@ build
|
|||||||
*.sqlite
|
*.sqlite
|
||||||
*.sqlite-jurnal
|
*.sqlite-jurnal
|
||||||
docs
|
docs
|
||||||
|
lib
|
@ -38,11 +38,11 @@
|
|||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"routing-controllers": "^0.9.0-alpha.6",
|
"routing-controllers": "^0.9.0-alpha.6",
|
||||||
"routing-controllers-openapi": "^2.1.0",
|
"routing-controllers-openapi": "^2.1.0",
|
||||||
|
"sqlite3": "^5.0.0",
|
||||||
"swagger-ui-express": "^4.1.5",
|
"swagger-ui-express": "^4.1.5",
|
||||||
"typeorm": "^0.2.29",
|
"typeorm": "^0.2.29",
|
||||||
"typeorm-routing-controllers-extensions": "^0.2.0",
|
"typeorm-routing-controllers-extensions": "^0.2.0",
|
||||||
"typeorm-seeding": "^1.6.1",
|
"typeorm-seeding": "^1.6.1",
|
||||||
"sqlite3": "^5.0.0",
|
|
||||||
"uuid": "^8.3.1"
|
"uuid": "^8.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -56,6 +56,7 @@
|
|||||||
"axios": "^0.21.0",
|
"axios": "^0.21.0",
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
"nodemon": "^2.0.6",
|
"nodemon": "^2.0.6",
|
||||||
|
"rimraf": "^2.7.1",
|
||||||
"start-server-and-test": "^1.11.6",
|
"start-server-and-test": "^1.11.6",
|
||||||
"ts-jest": "^26.4.4",
|
"ts-jest": "^26.4.4",
|
||||||
"ts-node": "^9.0.0",
|
"ts-node": "^9.0.0",
|
||||||
@ -69,7 +70,8 @@
|
|||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:watch": "jest --watchAll",
|
"test:watch": "jest --watchAll",
|
||||||
"test:ci": "start-server-and-test dev http://localhost:4010/api/openapi.json test",
|
"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": {
|
"nodemonConfig": {
|
||||||
"ignore": [
|
"ignore": [
|
||||||
|
56
src/openapi_export.ts
Normal file
56
src/openapi_export.ts
Normal 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");
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user