From a7b2f1ddd0ebccc7f2ecb646068d61ff4f697311 Mon Sep 17 00:00:00 2001 From: Deep Singhvi Date: Wed, 26 Jun 2024 10:58:28 -0400 Subject: [PATCH] (fix): openapi parser gets boolean values safely (#3937) --- packages/cli/openapi-parser/src/schema/convertSchemas.ts | 5 +++-- packages/cli/openapi-parser/src/utils/getValue.ts | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 packages/cli/openapi-parser/src/utils/getValue.ts diff --git a/packages/cli/openapi-parser/src/schema/convertSchemas.ts b/packages/cli/openapi-parser/src/schema/convertSchemas.ts index 9bc10a5cdaa..79bba16845e 100644 --- a/packages/cli/openapi-parser/src/schema/convertSchemas.ts +++ b/packages/cli/openapi-parser/src/schema/convertSchemas.ts @@ -13,6 +13,7 @@ import { OpenAPIExtension } from "../openapi/v3/extensions/extensions"; import { FernOpenAPIExtension } from "../openapi/v3/extensions/fernExtensions"; import { getFernEnum } from "../openapi/v3/extensions/getFernEnum"; import { getFernTypeExtension } from "../openapi/v3/extensions/getFernTypeExtension"; +import { getValueIfBoolean } from "../utils/getValue"; import { convertAdditionalProperties, wrapMap } from "./convertAdditionalProperties"; import { convertArray } from "./convertArray"; import { convertDiscriminatedOneOf, convertDiscriminatedOneOfWithVariants } from "./convertDiscriminatedOneOf"; @@ -296,8 +297,8 @@ export function convertSchemaObject( _default: schema.default, minimum: schema.minimum, maximum: schema.maximum, - exclusiveMinimum: schema.exclusiveMinimum, - exclusiveMaximum: schema.exclusiveMaximum, + exclusiveMinimum: getValueIfBoolean(schema.exclusiveMinimum), + exclusiveMaximum: getValueIfBoolean(schema.exclusiveMaximum), multipleOf: schema.multipleOf, description, wrapAsNullable, diff --git a/packages/cli/openapi-parser/src/utils/getValue.ts b/packages/cli/openapi-parser/src/utils/getValue.ts new file mode 100644 index 00000000000..d10a92c9870 --- /dev/null +++ b/packages/cli/openapi-parser/src/utils/getValue.ts @@ -0,0 +1,6 @@ +export function getValueIfBoolean(value: unknown): boolean | undefined { + if (value != null && typeof value === "boolean") { + return value; + } + return undefined; +}