Code Monkey home page Code Monkey logo

docs's People

Contributors

adamgilman avatar aldenquimby avatar alxwrd avatar davidlj95 avatar dderevjanik avatar dependabot[bot] avatar djdmbrwsk avatar dsaouda avatar endor avatar fahrradflucht avatar helios-ag avatar jackey8616 avatar jenseng avatar kth-tw avatar martijngevaert avatar nateeag avatar owolfy avatar ponsfrilus avatar roman991 avatar spifory avatar themis3000 avatar thetimewalker avatar tom-boothman avatar woh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

docs's Issues

Update inversify docs to mention behavior with `setHeaders`

Copied over from lukeautry/tsoa#809

This is a request for clarification in the docs:

The docs give examples for how to integrate tsoa with inversify (link). That part of the documentation also states that We usually don't want to create a new controller instance for every call, so let's create a convenience wrapper around @fluentProvide(), and provides an example of binding a controller to the IOC container in the singleton scope.

This is very reasonable โ€” no point instantiating new controller instances if not necessary, so let's re-use the same instance for each request. However, since the Controller.setHeaders method mutates the controller state, calling setHeaders will modify the headers for every subsequent request to the same controller instance. This is pretty surprising, and took me a while to debug.

Would it be possible to clarify this behavior in the docs?

Descriptions: Add @summary jsdoc

Next to the description field, OpenAPI supports summaries in many cases.
tsoa uses these on the method level:

  /**
   * @summary simple summary
   */
  @Get('SummaryMethod')
  public async summaryMethod(): Promise<TestModel> {
    return new ModelService().getModel();
  }

However, this is not documented yet.

"We usually don't want to create a new controller instance for every call" - unsafe?

The IOC docs state "We usually don't want to create a new controller instance for every call" - Why is this safe?

Given a controller like this:

@Route("users")
@provideSingleton(UsersController)
export class UsersController extends Controller {
  @Get("{userId}")
  public async getUser(
    @Path() userId: number,
    @Query() name?: string
  ): Promise<User> {
	const userService = new UsersService();
    return await userService.get(userId, name);
  }

  @SuccessResponse("201", "Created")
  @Post()
  public async createUser(
    @Body() requestBody: UserCreationParams
  ): Promise<void> {
	const userService = new UsersService();
    this.setStatus(201); // race-condition?
    await userService.create(requestBody);
    return;
  }
}

Isn't there now a race-condition with the setStatus(201) call potentially affecting another request, maybe even for another route? Or am I confused? - If I'm not, I think the quoted sentence should go away, and we should change the example to use a controller per-requests, since it's unsafe in a lot of cases and the controller reuse is likely an unnecessary optimization anyway.

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.