Coder Social home page Coder Social logo

Comments (3)

azaeng04 avatar azaeng04 commented on April 28, 2024 1

@isman-usoh where does ErrorResponse come from in your code?

from tsoa.

isman-usoh avatar isman-usoh commented on April 28, 2024

@egandro

import {Post, Route, Request, SuccessResponse, Response, Controller } from 'tsoa';

@Route('Users')
export class UsersController extends Controller {

    @Response<ErrorResponse>('Unexpected error') // error response
    @SuccessResponse('201', 'Created') // custom success response
    @Post()
    public async createUser(@Body() requestBody: UserCreationRequest): Promise<void> {
        new UserService().create(request);
        this.setStatus(201); // set return status 201
        return Promise.resolve();
    }
}

from tsoa.

azaeng04 avatar azaeng04 commented on April 28, 2024

@isman-usoh that example you showed does not show the ErrorResponse object on the Swagger Doc.

This is the code I have and it does not display it in the Swagger Doc:


import { Route, Controller, Get, Query, SuccessResponse, Tags, Response } from 'tsoa';
import { ExpenseGroup } from "../../models";
import { IExpenseGroupResponse, ErrorResponse } from "../response";

@Route('expenseGroup')
export class ExpenseGroupController extends Controller {
    @Response<ErrorResponse>('The following error occurred')
    @SuccessResponse('200', 'Expense Group found')
    @Tags('Expense Group')
    @Get('')
    public async getExpenseGroupById(@Query() id: number): Promise<IExpenseGroupResponse> {
        const expenseGroup = await ExpenseGroup.findById(id);
        const customResponse = <IExpenseGroupResponse> expenseGroup;
        this.setStatus(200);
        return customResponse;
    }
}

from tsoa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.