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

Missing mapping in oneOf with discriminator #1805

Open
hnykda opened this issue Mar 11, 2025 · 4 comments
Open

Missing mapping in oneOf with discriminator #1805

hnykda opened this issue Mar 11, 2025 · 4 comments
Labels
bug 🔥 Something isn't working

Comments

@hnykda
Copy link

hnykda commented Mar 11, 2025

Description

Hi.

I have this:

    "/tasks/chat": {
      "post": {
        "summary": "Create Chat Task",
        "description": "Create a new chat task.",
        "operationId": "create_chat_task_tasks_chat_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/StandaloneChatRequestParams"
                  },
                  {
                    "$ref": "#/components/schemas/MapReduceChatRequestParams"
                  }
                ],
                "title": "Request",
                "discriminator": {
                  "propertyName": "processing_mode",
                  "mapping": {
                    "standalone": "#/components/schemas/StandaloneChatRequestParams",
                    "map": "#/components/schemas/MapReduceChatRequestParams",
                    "reduce": "#/components/schemas/MapReduceChatRequestParams"
                  }
                }
              }
            }
          },
          "required": true
        },

but with the following config:

import { defineConfig, defaultPlugins } from "@hey-api/openapi-ts";

export default defineConfig({
  input: "http://localhost:8000/openapi.json",
  output: "src/lib/engine_api/generated",
  plugins: [
    ...defaultPlugins,
    {
      name: "@hey-api/client-next",
      runtimeConfigPath: "./src/lib/engine_api/main.ts",
    },
    {
      enums: "javascript",
      name: "@hey-api/typescript",
    },
  ],
});

I get:

export type CreateChatTaskTasksChatPostData = {
  body:
    | ({
        processing_mode?: "standalone";
      } & StandaloneChatRequestParams)
    | ({
        processing_mode?: "map";
      } & MapReduceChatRequestParams);
  path?: never;
  query?: never;
  url: "/tasks/chat";
};

i.e. reduce mapping is missing. Seems that it's order dependent. When I switch the order of map with reduce in the original JSON, it gets generated with reduced instead (and map is missing).

Reproducible example or configuration

No response

OpenAPI specification (optional)

No response

System information (optional)

No response

@hnykda hnykda added the bug 🔥 Something isn't working label Mar 11, 2025
@hnykda hnykda changed the title Missing mapping in one off with discriminator Missing mapping in oneOf with discriminator Mar 11, 2025
@mrlubos
Copy link
Member

mrlubos commented Mar 25, 2025

Thanks @hnykda! Would you be interested in creating a pull request with the fix?

@hnykda
Copy link
Author

hnykda commented Mar 25, 2025

Very unlikely, sorry!

@mrlubos
Copy link
Member

mrlubos commented Mar 25, 2025

All good! Worth checking 😀

@hnykda
Copy link
Author

hnykda commented Mar 26, 2025

I agree!

And thank you for your work, very appreciated 👍

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