How to use the swagger-express-ts.SwaggerDefinitionConstant.Response function in swagger-express-ts

To help you get started, we’ve selected a few swagger-express-ts 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 dimeloper / ts-simple-backend / server / controllers / user.controller.ts View on Github external
constructor() {
    this.router = express.Router();
    this.router.get('/', this.getUsers);
    this.router.post('/', this.createUser);
  }

  public getRouter(): express.Router {
    return this.router;
  }

  @ApiOperationGet({
    description: 'Get user list',
    responses: {
      200: {
        model: 'User',
        type: SwaggerDefinitionConstant.Response.Type.ARRAY,
      },
    },
    /* security: { - use if route is protected
      apiKeyHeader: [],
    }, */
    summary: 'Get users list',
  })
  private async getUsers(
    request: express.Request,
    response: express.Response
  ): Promise {
    const users = await UserModel.find({}).exec();
    response.status(200).json(users);
  }

  @ApiOperationPost({
github olivierlsc / swagger-express-ts / src / cars / cars.controller.ts View on Github external
@ApiPath({
    path: '/cars',
    name: 'Cars',
    security: { apiKeyHeader: [] },
})
@controller('/cars')
@injectable()
export class CarsController implements interfaces.Controller {
    constructor(@inject(CarsService.name) private carsService: CarsService) {}

    @ApiOperationGet({
        description: 'Get cars objects list',
        summary: 'Get cars list',
        responses: {
            200: {
                type: SwaggerDefinitionConstant.Response.Type.ARRAY,
                model: 'Car',
            },
        },
        security: {
            apiKeyHeader: [],
        },
    })
    @httpGet('/')
    public getCars(
        request: express.Request,
        response: express.Response,
        next: express.NextFunction
    ): void {
        response.json(this.carsService.getCars());
    }