tsoa-custom-decorators
Version:
Build swagger-compliant REST APIs using TypeScript and Node
170 lines (148 loc) • 4.71 kB
text/typescript
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';
export class GetTestController extends Controller {
/**
* This is a description of the getModel method
* this is some more text on another line
*/
<TestModel>({
boolArray: [true, false],
boolValue: true,
id: 1,
modelValue: {
email: 'test@test.com',
id: 100,
},
modelsArray: new Array<TestSubModel>(),
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<TestModel> {
return new ModelService().getModel();
}
public async getCurrentModel(): Promise<TestModel> {
return new ModelService().getModel();
}
public async getClassModel(): Promise<TestClassModel> {
return new ModelService().getClassModel();
}
public async getMultipleModels(): Promise<TestModel[]> {
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
*/
public async getModelByParams(
numberPathParam: number,
stringPathParam: string,
booleanPathParam: boolean,
booleanParam: boolean,
stringParam: string,
numberParam: number,
optionalStringParam?: string): Promise<TestModel> {
const model = new ModelService().getModel();
model.optionalString = optionalStringParam;
model.numberValue = numberPathParam;
model.boolValue = booleanPathParam;
model.stringValue = stringPathParam;
return model;
}
public async getResponseWithUnionTypeProperty(): Promise<Result> {
return {
value: 'success'
};
}
public async getUnionTypeResponse(): Promise<string | boolean> {
return '';
}
public async getRequest( request: Object): Promise<TestModel> {
const model = new ModelService().getModel();
// set the stringValue from the request context to test successful injection
model.stringValue = (<any>request).stringValue;
return model;
}
public async getByDataParam( date: Date): Promise<TestModel> {
const model = new ModelService().getModel();
model.dateValue = date;
return model;
}
public async getThrowsError(): Promise<TestModel> {
throw {
message: 'error thrown',
status: 400
};
}
public async getGeneratesTags(): Promise<TestModel> {
return new ModelService().getModel();
}
public async getBuffer( buffer: Buffer): Promise<Buffer> {
return new Buffer('testbuffer');
}
public async getGenericModel(): Promise<GenericModel<TestModel>> {
return {
result: new ModelService().getModel()
};
}
public async getGenericModelArray(): Promise<GenericModel<TestModel[]>> {
return {
result: [
new ModelService().getModel()
]
};
}
public async getGenericPrimitive(): Promise<GenericModel<string>> {
return {
result: new ModelService().getModel().stringValue
};
}
public async getGenericPrimitiveArray(): Promise<GenericModel<string[]>> {
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';
}