How to use the @tsed/swagger.Returns function in @tsed/swagger

To help you get started, we’ve selected a few @tsed/swagger 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 TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / EventCtrl.ts View on Github external
*/
  @Put("/:id")
  save(@BodyParams() event: EventModel): Promise | void {
    event.id = "1";

    return Promise.resolve(event);
  }

  /**
   *
   * @param event
   * @returns {null}
   */
  @Post("/list")
  @Authenticated({role: "admin"})
  @Returns(200, {use: EventModel, collection: Array})
  update(@BodyParams("event", EventModel) event: EventModel[]): EventModel[] {
    return event;
  }

  /**
   *
   * @returns {null}
   */
  @Delete("/:id")
  remove(): Promise | void {
    return Promise.resolve(null);
  }

  /**
   *
   * @returns {null}
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / CalendarCtrl.ts View on Github external
});
  }

  @Get("/query")
  public getQuery(@QueryParams("search") search: string, @Request() request: any): string {
    return search || "EMPTY";
  }

  /**
   *
   * @param auth
   * @param name
   * @returns {{id: number, name: string}}
   */
  @Put("/")
  @Returns(CalendarModel)
  public save(
    @BodyParams("name")
    @Required()
      name: string
  ): CalendarModel {
    const model = new CalendarModel();
    model.id = "2";
    model.name = "test";

    return model;
  }

  @Delete("/")
  @Status(204)
  @Authenticated({role: "admin"})
  @Security("global_auth", "read:global")
github TypedProject / ts-express-decorators / examples / getting-started / src / controllers / calendars / CalendarsCtrl.ts View on Github external
@Get("/:id")
  @Returns(Calendar)
  async get(@Required() @PathParams("id") id: string): Promise {
    const calendar = await this.calendarsService.find(id);

    if (calendar) {
      return calendar;
    }

    throw new NotFound("Calendar not found");
  }

  @Put("/")
  @Status(201)
  @Returns(Calendar)
  save(@BodyParams() calendar: CreateCalendar): Promise {
    return this.calendarsService.create(calendar);
  }

  @Post("/:id")
  @Returns(Calendar)
  async update(@PathParams("id") @Required() id: string,
               @BodyParams() @Required() calendar: CreateCalendar): Promise {
    return this.calendarsService.update({id, ...calendar});
  }

  @Delete("/")
  @Status(204)
  async remove(@BodyParams("id") @Required() id: string): Promise {
    await this.calendarsService.remove(id);
  }
github TypedProject / ts-express-decorators / examples / getting-started / src / controllers / calendars / CalendarsCtrl.ts View on Github external
if (calendar) {
      return calendar;
    }

    throw new NotFound("Calendar not found");
  }

  @Put("/")
  @Status(201)
  @Returns(Calendar)
  save(@BodyParams() calendar: CreateCalendar): Promise {
    return this.calendarsService.create(calendar);
  }

  @Post("/:id")
  @Returns(Calendar)
  async update(@PathParams("id") @Required() id: string,
               @BodyParams() @Required() calendar: CreateCalendar): Promise {
    return this.calendarsService.update({id, ...calendar});
  }

  @Delete("/")
  @Status(204)
  async remove(@BodyParams("id") @Required() id: string): Promise {
    await this.calendarsService.remove(id);
  }

  @Get("/")
  @ReturnsArray(Calendar)
  async getAllCalendars() {
    return this.calendarsService.query();
  }
github TypedProject / ts-express-decorators / examples / getting-started / src / controllers / calendars / CalendarsCtrl.ts View on Github external
*
 * In this case, EventsCtrl is a dependency of CalendarsCtrl.
 * All routes of EventsCtrl will be mounted on the `/calendars` path.
 */
@Controller({
  path: "/calendars",
  children: [
    EventsCtrl
  ]
})
export class CalendarsCtrl {
  constructor(private calendarsService: CalendarsService) {
  }

  @Get("/:id")
  @Returns(Calendar)
  async get(@Required() @PathParams("id") id: string): Promise {
    const calendar = await this.calendarsService.find(id);

    if (calendar) {
      return calendar;
    }

    throw new NotFound("Calendar not found");
  }

  @Put("/")
  @Status(201)
  @Returns(Calendar)
  save(@BodyParams() calendar: CreateCalendar): Promise {
    return this.calendarsService.create(calendar);
  }