Skip to content

Commit

Permalink
feat: add swagger docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Scalamando committed Nov 12, 2021
1 parent d71057e commit 1552053
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ build

.cache

swagger.json

.env*
!.env.example
54 changes: 54 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"copy-assets": "ts-node tools/copyAssets",
"build-ts": "tsc",
"parcel": "parcel build src/public/js/*.ts -d build/public/js",
"pre:build": "tsoa spec",
"build": "npm run clean && npm run build-ts && npm run copy-assets && npm run parcel",
"dev": "npm run build && npm run start",
"start:dev": "nodemon --watch src -e ts,ejs,css --exec npm run dev",
Expand All @@ -27,6 +28,7 @@
"jimp": "^0.16.1",
"pg": "^8.7.1",
"reflect-metadata": "^0.1.13",
"swagger-ui-express": "^4.1.6",
"tsoa": "^3.14.0",
"typeorm": "^0.2.39"
},
Expand All @@ -35,6 +37,7 @@
"@types/fabric": "^4.5.4",
"@types/node": "^16.11.7",
"@types/shelljs": "^0.8.9",
"@types/swagger-ui-express": "^4.1.3",
"nodemon": "^2.0.15",
"parcel-bundler": "^1.12.5",
"rimraf": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/digit.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class DigitController {
}

@Get("/count")
public async countDigits(): Promise<Number> {
public async countDigits(): Promise<number> {
return countDigits();
}

Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "reflect-metadata";
import { join as joinPaths } from "path";
import { createConnection } from "typeorm";
import express, { Application } from "express";
import swaggerUi from "swagger-ui-express";

import Router from "./routes";
import dbConfig from "./config/database";
Expand All @@ -16,6 +17,16 @@ app.set("view engine", "ejs");
app.use(express.json());
app.use(express.static(joinPaths(__dirname, "public")));

app.use(
"/docs",
swaggerUi.serve,
swaggerUi.setup(undefined, {
swaggerOptions: {
url: "/swagger.json",
},
})
);

app.use(Router);

createConnection(dbConfig)
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/digit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const createDigit = async (payload: IDigitPaylod): Promise<Digit> => {
return digitRepository.save({ ...digit, ...payload });
};

export const countDigits = async (): Promise<Number> => {
export const countDigits = async (): Promise<number> => {
const digitRepository = getRepository(Digit);
return digitRepository.count();
};
2 changes: 2 additions & 0 deletions tools/copyAssets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import shell from "shelljs";

shell.cp("-r", "src/views", "build/");

shell.mkdir("-p", "build/public/css");
shell.mkdir("-p", "build/public/js");
shell.cp("-r", "src/public/css", "build/public/");
shell.cp("-r", "src/public/js/*.js", "build/public/js");
shell.cp("-r", "src/public/swagger.json", "build/public/");
5 changes: 3 additions & 2 deletions tsoa.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"entryFile": "src/index.ts",
"noImplicitAdditionalProperties": "throw-on-extras",
"spec": {
"outputDirectory": "public",
"specVersion": 3
"outputDirectory": "src/public",
"specVersion": 3,
"basePath": "/api"
},
"ignore": ["**/node_modules/**"]
}

0 comments on commit 1552053

Please sign in to comment.