How to use the routing-controllers-openapi.OpenAPI function in routing-controllers-openapi

To help you get started, we’ve selected a few routing-controllers-openapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github epiphone / routing-controllers-openapi / sample / 01-basic / UsersController.ts View on Github external
class CreateUserBody {
  @IsString()
  name: string

  @IsOptional()
  @MaxLength(20, { each: true })
  hobbies: string[]
}

@OpenAPI({
  security: [{ basicAuth: [] }]
})
@JsonController('/users')
export class UsersController {
  @Get('/')
  @OpenAPI({ summary: 'Return a list of users' })
  getAll() {
    return [
      { id: 1, name: 'First user!', hobbies: [] },
      { id: 2, name: 'Second user!', hobbies: ['fishing', 'cycling'] }
    ]
  }

  @Get('/:id')
  @OpenAPI({ summary: 'Return a single user' })
  getOne(@Param('id') id: number) {
    return { name: 'User #' + id }
  }

  @Post('/')
  @OpenAPI({ summary: 'Create a new user' })
  createUser(@Body({ validate: true }) body: CreateUserBody) {
github epiphone / routing-controllers-openapi / sample / 01-basic / UsersController.ts View on Github external
Param,
  Post,
  Put
} from 'routing-controllers'
import { OpenAPI } from 'routing-controllers-openapi'

class CreateUserBody {
  @IsString()
  name: string

  @IsOptional()
  @MaxLength(20, { each: true })
  hobbies: string[]
}

@OpenAPI({
  security: [{ basicAuth: [] }]
})
@JsonController('/users')
export class UsersController {
  @Get('/')
  @OpenAPI({ summary: 'Return a list of users' })
  getAll() {
    return [
      { id: 1, name: 'First user!', hobbies: [] },
      { id: 2, name: 'Second user!', hobbies: ['fishing', 'cycling'] }
    ]
  }

  @Get('/:id')
  @OpenAPI({ summary: 'Return a single user' })
  getOne(@Param('id') id: number) {
github epiphone / routing-controllers-openapi / sample / 01-basic / UsersController.ts View on Github external
@OpenAPI({
  security: [{ basicAuth: [] }]
})
@JsonController('/users')
export class UsersController {
  @Get('/')
  @OpenAPI({ summary: 'Return a list of users' })
  getAll() {
    return [
      { id: 1, name: 'First user!', hobbies: [] },
      { id: 2, name: 'Second user!', hobbies: ['fishing', 'cycling'] }
    ]
  }

  @Get('/:id')
  @OpenAPI({ summary: 'Return a single user' })
  getOne(@Param('id') id: number) {
    return { name: 'User #' + id }
  }

  @Post('/')
  @OpenAPI({ summary: 'Create a new user' })
  createUser(@Body({ validate: true }) body: CreateUserBody) {
    return { ...body, id: 3 }
  }

  @Put('/')
  createManyUsers(@Body({ type: CreateUserBody }) body: CreateUserBody[]) {
    return {}
  }
}
github epiphone / routing-controllers-openapi / sample / 01-basic / UsersController.ts View on Github external
@OpenAPI({ summary: 'Return a list of users' })
  getAll() {
    return [
      { id: 1, name: 'First user!', hobbies: [] },
      { id: 2, name: 'Second user!', hobbies: ['fishing', 'cycling'] }
    ]
  }

  @Get('/:id')
  @OpenAPI({ summary: 'Return a single user' })
  getOne(@Param('id') id: number) {
    return { name: 'User #' + id }
  }

  @Post('/')
  @OpenAPI({ summary: 'Create a new user' })
  createUser(@Body({ validate: true }) body: CreateUserBody) {
    return { ...body, id: 3 }
  }

  @Put('/')
  createManyUsers(@Body({ type: CreateUserBody }) body: CreateUserBody[]) {
    return {}
  }
}

routing-controllers-openapi

Runtime OpenAPI v3 spec generation for routing-controllers

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis