import { Example } from '../../../src/decorators/example'; import { Request, Query } from '../../../src/decorators/parameter'; import { Get } from '../../../src/decorators/methods'; import { Controller } from '../../../src/interfaces/controller'; import { ModelService } from '../services/modelService'; import { Route } from '../../../src/decorators/route'; import { GenericModel, TestModel, TestSubModel, TestClassModel } from '../testModel'; import { Tags } from '../../../src/decorators/tags'; @Route('GetTest') export class GetTestController extends Controller { /** * This is a description of the getModel method * this is some more text on another line */ @Get() @Example({ boolArray: [true, false], boolValue: true, id: 1, modelValue: { email: 'test@test.com', id: 100, }, modelsArray: new Array(), numberArray: [1, 2, 3], numberValue: 1, optionalString: 'optional string', strLiteralArr: ['Foo', 'Bar'], strLiteralVal: 'Foo', stringArray: ['string one', 'string two'], stringValue: 'a string' }) public async getModel(): Promise { return new ModelService().getModel(); } @Get('Current') public async getCurrentModel(): Promise { return new ModelService().getModel(); } @Get('ClassModel') public async getClassModel(): Promise { return new ModelService().getClassModel(); } @Get('Multi') public async getMultipleModels(): Promise { return [ new ModelService().getModel(), new ModelService().getModel(), new ModelService().getModel() ]; } /** * @param numberPathParam This is a description for numberPathParam * @param numberParam This is a description for numberParam */ @Get('{numberPathParam}/{booleanPathParam}/{stringPathParam}') public async getModelByParams( numberPathParam: number, stringPathParam: string, booleanPathParam: boolean, @Query() booleanParam: boolean, @Query() stringParam: string, @Query() numberParam: number, @Query() optionalStringParam?: string): Promise { const model = new ModelService().getModel(); model.optionalString = optionalStringParam; model.numberValue = numberPathParam; model.boolValue = booleanPathParam; model.stringValue = stringPathParam; return model; } @Get('ResponseWithUnionTypeProperty') public async getResponseWithUnionTypeProperty(): Promise { return { value: 'success' }; } @Get('UnionTypeResponse') public async getUnionTypeResponse(): Promise { return ''; } @Get('Request') public async getRequest(@Request() request: Object): Promise { const model = new ModelService().getModel(); // set the stringValue from the request context to test successful injection model.stringValue = (request).stringValue; return model; } @Get('DateParam') public async getByDataParam(@Query() date: Date): Promise { const model = new ModelService().getModel(); model.dateValue = date; return model; } @Get('ThrowsError') public async getThrowsError(): Promise { throw { message: 'error thrown', status: 400 }; } @Get('GeneratesTags') @Tags('test', 'test-two') public async getGeneratesTags(): Promise { return new ModelService().getModel(); } @Get('HandleBufferType') public async getBuffer(@Query() buffer: Buffer): Promise { return new Buffer('testbuffer'); } @Get('GenericModel') public async getGenericModel(): Promise> { return { result: new ModelService().getModel() }; } @Get('GenericModelArray') public async getGenericModelArray(): Promise> { return { result: [ new ModelService().getModel() ] }; } @Get('GenericPrimitive') public async getGenericPrimitive(): Promise> { return { result: new ModelService().getModel().stringValue }; } @Get('GenericPrimitiveArray') public async getGenericPrimitiveArray(): Promise> { return { result: new ModelService().getModel().stringArray }; } } export interface ErrorResponse { code: string; msg: string; } export interface CustomError extends Error { message: string; status: number; } export interface Result { value: 'success' | 'failure'; }