Skip to content

Conversation

@fredr
Copy link
Member

@fredr fredr commented Dec 11, 2025

Reported in https://discord.com/channels/814482502336905216/1445923767015571599/1448428947607130183

type FooRequest = {
  foo: string;
};

type ApiRequest = {
  blob: FooRequest | string;
};

export const myApi = api<ApiRequest, void>(
  { expose: true, method: "POST" },
  (req) => {},
);

Now yields:

{
  "schema": {
    "properties": {
      "blob": {
        "anyOf": [
          {
            "$ref": "#/components/schemas/hello.FooRequest"
          },
          {
            "type": "string"
          }
        ]
      }
    },
    "required": [
      "blob"
    ],
    "type": "object"
  }
}

Possibly also solves #1757 #1521 #1867

@fredr fredr self-assigned this Dec 11, 2025
@encore-cla
Copy link

encore-cla bot commented Dec 11, 2025

All committers have signed the CLA.

@eleijonmarck
Copy link
Contributor

looks valid to me

Copy link
Member

@eandre eandre left a comment

Choose a reason for hiding this comment

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

Does this change how the schema looks like? Does everything get nested as refs now?

@fredr
Copy link
Member Author

fredr commented Dec 11, 2025

Does this change how the schema looks like? Does everything get nested as refs now?

No, I tried to show that in the example, e.g string is represented as {"type": "string"} as before the change, but named will be represented as ref. Or where there any other types you where thinking about?

@fredr fredr merged commit 308a837 into main Dec 11, 2025
5 checks passed
@fredr fredr deleted the fredr/clientgen-openapi-union branch December 11, 2025 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants