From 2e8bee59c4d05c08cd6132a53166d147dfb52073 Mon Sep 17 00:00:00 2001 From: Liooo Date: Sat, 3 May 2025 23:53:47 +0900 Subject: [PATCH 1/3] fix: make oneOf discriminator props required --- packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts | 1 + packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts b/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts index 15b5b4bf9..f43caaf3e 100644 --- a/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts +++ b/packages/openapi-ts/src/openApi/3.0.x/parser/schema.ts @@ -710,6 +710,7 @@ const parseOneOf = ({ } : valueSchemas[0]!, }, + required: [schema.discriminator.propertyName], type: 'object', }; irCompositionSchema = { diff --git a/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts b/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts index 315fceb63..a5d2405c5 100644 --- a/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts +++ b/packages/openapi-ts/src/openApi/3.1.x/parser/schema.ts @@ -423,6 +423,7 @@ const parseAllOf = ({ } : valueSchemas[0]!, }, + required: [ref.discriminator.propertyName], type: 'object', }; if (ref.required?.includes(ref.discriminator.propertyName)) { From cbe18a6a658a10afd35682513f8e8589aa356b2a Mon Sep 17 00:00:00 2001 From: Liooo Date: Sat, 3 May 2025 23:54:26 +0900 Subject: [PATCH 2/3] update snapshot --- .../3.0.x/discriminator-mapped-many/types.gen.ts | 4 ++-- .../__snapshots__/3.0.x/discriminator-one-of/types.gen.ts | 8 ++++---- .../3.0.x/plugins/@hey-api/sdk/default/types.gen.ts | 4 ++-- .../3.0.x/plugins/@hey-api/sdk/throwOnError/types.gen.ts | 4 ++-- .../angular-query-experimental/asClass/types.gen.ts | 4 ++-- .../angular-query-experimental/axios/types.gen.ts | 4 ++-- .../angular-query-experimental/fetch/types.gen.ts | 4 ++-- .../plugins/@tanstack/react-query/asClass/types.gen.ts | 4 ++-- .../plugins/@tanstack/react-query/axios/types.gen.ts | 4 ++-- .../plugins/@tanstack/react-query/fetch/types.gen.ts | 4 ++-- .../plugins/@tanstack/solid-query/asClass/types.gen.ts | 4 ++-- .../plugins/@tanstack/solid-query/axios/types.gen.ts | 4 ++-- .../plugins/@tanstack/solid-query/fetch/types.gen.ts | 4 ++-- .../plugins/@tanstack/svelte-query/asClass/types.gen.ts | 4 ++-- .../plugins/@tanstack/svelte-query/axios/types.gen.ts | 4 ++-- .../plugins/@tanstack/svelte-query/fetch/types.gen.ts | 4 ++-- .../plugins/@tanstack/vue-query/asClass/types.gen.ts | 4 ++-- .../3.0.x/plugins/@tanstack/vue-query/axios/types.gen.ts | 4 ++-- .../3.0.x/plugins/@tanstack/vue-query/fetch/types.gen.ts | 4 ++-- .../3.0.x/plugins/fastify/default/types.gen.ts | 4 ++-- .../__snapshots__/3.0.x/plugins/zod/default/zod.gen.ts | 4 ++-- 21 files changed, 44 insertions(+), 44 deletions(-) diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/discriminator-mapped-many/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/discriminator-mapped-many/types.gen.ts index 1f6c5f2f2..e48cc7825 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/discriminator-mapped-many/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/discriminator-mapped-many/types.gen.ts @@ -1,9 +1,9 @@ // This file is auto-generated by @hey-api/openapi-ts export type Foo = ({ - foo?: 'one' | 'two'; + foo: 'one' | 'two'; } & Bar) | ({ - foo?: 'three'; + foo: 'three'; } & Baz); export type Bar = { diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/discriminator-one-of/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/discriminator-one-of/types.gen.ts index cdd9c641f..c739a4d95 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/discriminator-one-of/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/discriminator-one-of/types.gen.ts @@ -1,9 +1,9 @@ // This file is auto-generated by @hey-api/openapi-ts export type Foo = ({ - type?: 'Bar'; + type: 'Bar'; } & Bar) | ({ - type?: 'Baz'; + type: 'Baz'; } & Baz); export type Baz = Qux; @@ -18,9 +18,9 @@ export type Qux = { export type Quux = 'Bar' | 'Baz'; export type Quuz = ({ - type?: 'bar'; + type: 'bar'; } & Bar) | ({ - type?: 'baz'; + type: 'baz'; } & Baz); export type ClientOptions = { diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/default/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/sdk/throwOnError/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/asClass/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts index a152624a2..170641a8a 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/axios/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/angular-query-experimental/fetch/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/asClass/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/types.gen.ts index a152624a2..170641a8a 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/axios/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/react-query/fetch/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/asClass/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/types.gen.ts index a152624a2..170641a8a 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/axios/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/solid-query/fetch/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/asClass/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/types.gen.ts index a152624a2..170641a8a 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/axios/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/svelte-query/fetch/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/asClass/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/types.gen.ts index a152624a2..170641a8a 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/axios/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@tanstack/vue-query/fetch/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/fastify/default/types.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/fastify/default/types.gen.ts index 4f2e24b56..c2e9e8e23 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/fastify/default/types.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/fastify/default/types.gen.ts @@ -442,9 +442,9 @@ export type ModelSquare = { * This is a model with one property with a 'one of' relationship where the options are not $ref */ export type CompositionWithOneOfDiscriminator = ({ - kind?: 'circle'; + kind: 'circle'; } & ModelCircle) | ({ - kind?: 'square'; + kind: 'square'; } & ModelSquare); /** diff --git a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/zod/default/zod.gen.ts b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/zod/default/zod.gen.ts index c4e3b9123..ebd85ab94 100644 --- a/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/zod/default/zod.gen.ts +++ b/packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/zod/default/zod.gen.ts @@ -274,10 +274,10 @@ export const zModelSquare = z.object({ export const zCompositionWithOneOfDiscriminator = z.union([ z.object({ - kind: z.literal('circle').optional() + kind: z.literal('circle') }).and(zModelCircle), z.object({ - kind: z.literal('square').optional() + kind: z.literal('square') }).and(zModelSquare) ]); From aa10522f2bd018a417d875e5ab12ed0a848d2e49 Mon Sep 17 00:00:00 2001 From: Lubos Date: Sun, 4 May 2025 06:58:29 +0100 Subject: [PATCH 3/3] Create eighty-rivers-enjoy.md --- .changeset/eighty-rivers-enjoy.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eighty-rivers-enjoy.md diff --git a/.changeset/eighty-rivers-enjoy.md b/.changeset/eighty-rivers-enjoy.md new file mode 100644 index 000000000..c7b208876 --- /dev/null +++ b/.changeset/eighty-rivers-enjoy.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +fix: make descriminator field required when used with `oneOf` keyword