tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

Bug: Tsoa removing properties from body incorrectly

Open eduardo-pellenz opened this issue 8 months ago • 5 comments

We are using tsoa to build a BFF, so we are using the default noImplicitAdditionalProperties config so we only define the values that we need and the other ones are just send to the other service automatically.

We found a case where tsoa is removing not defined properties incorrectly:

Image

The bug is probably related to a specific usage of Partial, Omit and union types.

Here is a repository with the bug for you guys to test.

eduardo-pellenz avatar Apr 07 '25 12:04 eduardo-pellenz

Hello there eduardo-pellenz 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

github-actions[bot] avatar Apr 07 '25 12:04 github-actions[bot]

I think I encountered the same issue and spend 3 hours to narrow it down at least to a manageable size:

import { Body, Controller, Put, Route } from "tsoa";

type ValueFormatModel = {
  contentIfNotSet?: string;
};

type SetFieldFormatStepConfigModel = {
  newFormat: Partial<
    | ({
        prefix?: string;
      } & ValueFormatModel)
    | ValueFormatModel
  >;
};

type StepModel = {
  id?: string;
} & SetFieldFormatStepConfigModel;

@Route("users")
export class HelloController extends Controller {
  @Put()
  public async putReplaySteps(
    @Body()
    body: StepModel
  ): Promise<any> {
    return body;
  }
}

Input is:

{
  "newFormat": {
    "contentIfNotSet": "3",
    "prefix": "g"
  }
}

Output is

{
  "newFormat": {
    "contentIfNotSet": "3"
  }
}

DavidMulder0 avatar Apr 29 '25 15:04 DavidMulder0

@eduardo-pellenz Your repository isn't actually accessible publicly btw.

DavidMulder0 avatar Apr 29 '25 15:04 DavidMulder0

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Sep 27 '25 00:09 github-actions[bot]

No indication the issue was solved

DavidMulder0 avatar Sep 27 '25 00:09 DavidMulder0