Skip to content

Conversation

yanxue-22
Copy link
Contributor

@yanxue-22 yanxue-22 commented Sep 23, 2025

Ticket: DX-1437

The error happened in this case:

  1. When it encountered a union of request types, it would:
  2. Look at only the first type in the union (Type A).
  3. Search inside Type A for the URL parameter definitions.
    If Type A didn't have the params defined (due to inconsistency in source code), the generator would immediately stop looking without checking for param specifications in the other types.

With the changes it iterates through all types in the union (Type A, then Type B, etc.) until it finds the first one that contains the params definition. Once it finds the parameter, it uses it for the route and stops searching, since the URL parameters should be the same for the entire route.

I also made a few new test cases that now pass. One of them were if the first schema in a union did not have params, but the rest did, it now looks through the rest of them instead of breaking after the first.

@yanxue-22 yanxue-22 requested a review from a team as a code owner September 23, 2025 19:41
@yanxue-22 yanxue-22 force-pushed the DX-1437-openapi-generator-keep-params-when-requests-are-unioned branch from 22d4ff2 to b2731e4 Compare September 23, 2025 19:48
Path parameters were being dropped when the first schema in a union request didn't contain params.
Now it iterates through all schemas to find the first one with path parameters.
@yanxue-22 yanxue-22 force-pushed the DX-1437-openapi-generator-keep-params-when-requests-are-unioned branch from 8651c8c to 9396a0e Compare September 23, 2025 20:45
@yanxue-22 yanxue-22 changed the title fix: updated parseRequestUnion to extract path parameters from all sc… fix: updated parseRequestUnion for union requests Sep 23, 2025
Copy link
Contributor

@shenbenson shenbenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small comments, but looks good overall

path: '/internal/api/policy/v1/{applicationName}/touchpoints/{touchpoint}/rules/evaluation',
method: 'POST',
request: t.union([
// First schema has NO path parameters - this was causing the bug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep these comments around? It doesn't mean anything without context

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed parts of the code base had comments that pointed out small things, so I didn't know if it was better or worse to leave tidbits. Your comment makes sense though, I'll delete the comment

},
);

const REAL_WORLD_POLICY_EVALUATION_ROUTE = `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this variable name can be better

@yanxue-22 yanxue-22 force-pushed the DX-1437-openapi-generator-keep-params-when-requests-are-unioned branch 2 times, most recently from 226e512 to d64cd6a Compare September 24, 2025 17:09
@yanxue-22 yanxue-22 force-pushed the DX-1437-openapi-generator-keep-params-when-requests-are-unioned branch from d64cd6a to d2836f4 Compare September 24, 2025 17:12
@shenbenson shenbenson merged commit c5000de into master Sep 24, 2025
6 checks passed
@shenbenson shenbenson deleted the DX-1437-openapi-generator-keep-params-when-requests-are-unioned branch September 24, 2025 18:27
Copy link

🎉 This PR is included in version @api-ts/openapi-generator@5.10.2 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants