Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in core/res-req-types.ts when request body has multiple content types with same value #1717

Open
mads-b opened this issue Nov 27, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mads-b
Copy link

mads-b commented Nov 27, 2024

What are the steps to reproduce this issue?

Say an endpoint has two valid request content types:

  /path:
    post:
      operationId: postThePath
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ValueObject"
          application/vnd.vendor.v1+json:
            schema:
              $ref: "#/components/schemas/ValueObject"

The essence of the issue is that orval keys on the schema reference name, so both content types need to have the same schema reference.

We want the app to prefer using the vendor content type for API versioning, so we configure an override in orval.config.ts:

override: {
    contentType: {
        include: [ 'application/vnd.vendor.v1+json' ]
    }
}

What happens?

Generating the hook results in a request without a body, as orval internally resolves this endpoint to only have the application/json request body, which is then filtered out by the include filter.

The problem seems to stem from the getResReqTypes which has a flattening operation as the last step:

  return uniqBy(
    typesArray.flatMap((it) => it),
    uniqueKey,
  );

Where the vendor content type is lost as its uniqueKey is identical to the plain one.

What were you expecting to happen?

I was expecting a hook with a request body

Any logs, error output, etc?

Orval successfully generates the API

Any other comments?

What versions are you using?

System:
OS: Windows 11 10.0.22631
CPU: (16) x64 AMD Ryzen 7 PRO 5850U with Radeon Graphics
Memory: 30.55 GB / 62.83 GB
npmPackages:
@tanstack/react-query: ^5.29.0 => 5.61.4
orval: ^7.3.0 => 7.3.0
react: 18.3.1 => 18.3.1

@melloware melloware added the bug Something isn't working label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants