From f6139daf6c23d912a70dec0aefd1bb2ffb2b47ea Mon Sep 17 00:00:00 2001 From: eden wang <64514273+eyw520@users.noreply.github.com> Date: Mon, 6 Jan 2025 13:10:39 -0500 Subject: [PATCH] fix(cli): add unions to settings. (#5532) --- fern/apis/generators-yml/definition/generators.yml | 3 +++ generators-yml.schema.json | 10 ++++++++++ .../generators-yml/convertGeneratorsConfiguration.ts | 3 ++- .../generators/types/OpenApiSettingsSchema.ts | 2 ++ .../generators/types/OpenApiSettingsSchema.ts | 2 ++ pnpm-lock.yaml | 2 -- 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/fern/apis/generators-yml/definition/generators.yml b/fern/apis/generators-yml/definition/generators.yml index c2c74c07917..a641cd390df 100644 --- a/fern/apis/generators-yml/definition/generators.yml +++ b/fern/apis/generators-yml/definition/generators.yml @@ -222,6 +222,9 @@ types: title-as-schema-name: optional optional-additional-properties: optional coerce-enums-to-literals: optional + prefer-undiscriminated-unions-with-literals: + type: optional + docs: Whether to prefer undiscriminated unions with literals. Defaults to false. object-query-parameters: type: optional docs: Enables parsing deep object query parameters diff --git a/generators-yml.schema.json b/generators-yml.schema.json index b873268a9a6..d38a1b2f6bb 100644 --- a/generators-yml.schema.json +++ b/generators-yml.schema.json @@ -1366,6 +1366,16 @@ } ] }, + "prefer-undiscriminated-unions-with-literals": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "null" + } + ] + }, "object-query-parameters": { "oneOf": [ { diff --git a/packages/cli/configuration-loader/src/generators-yml/convertGeneratorsConfiguration.ts b/packages/cli/configuration-loader/src/generators-yml/convertGeneratorsConfiguration.ts index 968bd1432a8..598c0793684 100644 --- a/packages/cli/configuration-loader/src/generators-yml/convertGeneratorsConfiguration.ts +++ b/packages/cli/configuration-loader/src/generators-yml/convertGeneratorsConfiguration.ts @@ -338,7 +338,8 @@ async function parseApiConfigurationV2Schema({ audiences: [], settings: { shouldUseTitleAsName: spec.settings?.["title-as-schema-name"], - shouldUseUndiscriminatedUnionsWithLiterals: undefined, + shouldUseUndiscriminatedUnionsWithLiterals: + spec.settings?.["prefer-undiscriminated-unions-with-literals"] ?? false, asyncApiMessageNaming: undefined, onlyIncludeReferencedSchemas: spec.settings?.["only-include-referenced-schemas"], shouldUseOptionalAdditionalProperties: spec.settings?.["optional-additional-properties"] ?? true, diff --git a/packages/cli/configuration/src/generators-yml/schemas/api/resources/generators/types/OpenApiSettingsSchema.ts b/packages/cli/configuration/src/generators-yml/schemas/api/resources/generators/types/OpenApiSettingsSchema.ts index 4c6fd3a134c..d10bfd06607 100644 --- a/packages/cli/configuration/src/generators-yml/schemas/api/resources/generators/types/OpenApiSettingsSchema.ts +++ b/packages/cli/configuration/src/generators-yml/schemas/api/resources/generators/types/OpenApiSettingsSchema.ts @@ -8,6 +8,8 @@ export interface OpenApiSettingsSchema { "title-as-schema-name"?: boolean; "optional-additional-properties"?: boolean; "coerce-enums-to-literals"?: boolean; + /** Whether to prefer undiscriminated unions with literals. Defaults to false. */ + "prefer-undiscriminated-unions-with-literals"?: boolean; /** Enables parsing deep object query parameters */ "object-query-parameters"?: boolean; /** Enables exploring readonly schemas in OpenAPI specifications */ diff --git a/packages/cli/configuration/src/generators-yml/schemas/serialization/resources/generators/types/OpenApiSettingsSchema.ts b/packages/cli/configuration/src/generators-yml/schemas/serialization/resources/generators/types/OpenApiSettingsSchema.ts index e9f53ac2fea..d5df0e5ce1b 100644 --- a/packages/cli/configuration/src/generators-yml/schemas/serialization/resources/generators/types/OpenApiSettingsSchema.ts +++ b/packages/cli/configuration/src/generators-yml/schemas/serialization/resources/generators/types/OpenApiSettingsSchema.ts @@ -15,6 +15,7 @@ export const OpenApiSettingsSchema: core.serialization.ObjectSchema< "title-as-schema-name": core.serialization.boolean().optional(), "optional-additional-properties": core.serialization.boolean().optional(), "coerce-enums-to-literals": core.serialization.boolean().optional(), + "prefer-undiscriminated-unions-with-literals": core.serialization.boolean().optional(), "object-query-parameters": core.serialization.boolean().optional(), "respect-readonly-schemas": core.serialization.boolean().optional(), "only-include-referenced-schemas": core.serialization.boolean().optional(), @@ -28,6 +29,7 @@ export declare namespace OpenApiSettingsSchema { "title-as-schema-name"?: boolean | null; "optional-additional-properties"?: boolean | null; "coerce-enums-to-literals"?: boolean | null; + "prefer-undiscriminated-unions-with-literals"?: boolean | null; "object-query-parameters"?: boolean | null; "respect-readonly-schemas"?: boolean | null; "only-include-referenced-schemas"?: boolean | null; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fdf1c7db60c..7d461100018 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4230,8 +4230,6 @@ importers: specifier: ^2.1.8 version: 2.1.8(@types/node@18.15.3)(jsdom@20.0.3)(sass@1.72.0)(terser@5.31.5) - packages/cli/cli/dist/local: {} - packages/cli/configuration: dependencies: '@fern-api/core-utils':