routing-controllers-openapi
Version:
Runtime OpenAPI v3 spec generation for routing-controllers
93 lines (79 loc) • 1.73 kB
text/typescript
import { Type } from 'class-transformer'
import {
IsOptional,
IsString,
MaxLength,
IsNumber,
IsPositive,
ValidateNested,
} from 'class-validator'
import {
Body,
Get,
JsonController,
Param,
Post,
Put,
QueryParams,
} from 'routing-controllers'
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'
class Child {
name: string
}
class CreateUserBody {
name: string
hobbies: string[]
child: Child
children: Child[]
}
class UserResponse {
name: string
hobbies: string[]
}
class PaginationQuery {
public limit: number
public offset?: number
}
export class UsersController {
getAll( query: PaginationQuery) {
return [
{ id: 1, name: 'First user!', hobbies: [] },
{ id: 2, name: 'Second user!', hobbies: ['fishing', 'cycling'] },
]
}
getOne( id: number) {
return { name: 'User #' + id, hobbies: ['something'] }
}
createUser( body: CreateUserBody) {
return { ...body, id: 3 }
}
createManyUsers( body: CreateUserBody[]) {
return {}
}
}