= tsoa = Framework with integrated OpenAPI compiler to build Node.js serve-side applications using [[typescript]]. * https://tsoa-community.github.io/docs/introduction.html == Example == {{{#!highlight sh npm init npm install ts-node typescript express @types/express tslint cors @types/cors tsoa @types/tsoa swagger-ui-express @types/swagger-ui-express mkdir -p src/hello touch src/index.ts touch src/hello/helloController.ts touch src/hello/helloResponse.ts mkdir -p build # create tsconfig npx tsc --init touch README.md # ts-node src/index.ts # enable "experimentalDecorators": true, in tsconfig.json # enable "resolveJsonModule": true, in tsconfig.json # in script start in package.json put # npx tsoa swagger && npx tsoa spec-and-routes && ts-node src/index.ts npm start # http://localhost:3000/ curl -vvv localhost:3000 curl -vvv localhost:3000/hello/world curl -vvv localhost:3000/swagger/ }}} == tsoa.json == {{{#!highlight json { "entryFile": "src/index.ts", "noImplicitAdditionalProperties": "throw-on-extras", "controllerPathGlobs": [ "src/**/*Controller.ts" ], "spec": { "outputDirectory": "build", "specVersion": 3 }, "routes": { "routesDir": "build" } } }}} == src/index.ts == {{{#!highlight typescript import express from 'express'; import cors from 'cors'; import bodyParser from 'body-parser'; import { RegisterRoutes } from "../build/routes"; import * as swaggerJson from '../build/swagger.json'; import * as swaggerUI from 'swagger-ui-express'; const port = process.env.PORT || 3000; const app = express(); app.use(cors()); app.use(bodyParser.json()); app.use(["/openapi", "/docs", "/swagger"], swaggerUI.serve, swaggerUI.setup(swaggerJson)); RegisterRoutes(app); app.get('/', (req, res) => { res.send('Hello'); }); app.listen(port, () => { console.log('Listening in port ' + port); }); }}} === src/hello/helloResponse.ts === {{{#!highlight typescript export interface HelloResponse { response: string; } }}} === src/hello/helloController.ts === {{{#!highlight typescript import {Controller,Get,Path,Route,} from "tsoa"; import { HelloResponse } from "./helloResponse"; @Route("hello") export class HelloController extends Controller { @Get("{name}") public async getHello(@Path() name: string ): Promise { return { response: "Hello " + name }; } } }}}