From cd0a56eb178506c78771d97102eb20309d82fb9c Mon Sep 17 00:00:00 2001 From: Shodai Suzuki Date: Sun, 4 Feb 2024 11:31:55 +0900 Subject: [PATCH] fix(angular): avoid `Angular` type error when `nullable` (#1200) --- packages/core/src/getters/scalar.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/core/src/getters/scalar.ts b/packages/core/src/getters/scalar.ts index 8fbdbdd74..dfbf8a29b 100644 --- a/packages/core/src/getters/scalar.ts +++ b/packages/core/src/getters/scalar.ts @@ -1,5 +1,5 @@ import { SchemaObject } from 'openapi3-ts/oas30'; -import { ContextSpecs, ScalarValue } from '../types'; +import { ContextSpecs, ScalarValue, OutputClient } from '../types'; import { escape, isString } from '../utils'; import { getArray } from './array'; import { getObject } from './object'; @@ -20,7 +20,10 @@ export const getScalar = ({ name?: string; context: ContextSpecs; }): ScalarValue => { - const nullable = item.nullable ? ' | null' : ''; + // NOTE: Angular client does not support nullable types + const isAngularClient = context.output.client === OutputClient.ANGULAR; + const nullable = item.nullable && !isAngularClient ? ' | null' : ''; + const enumItems = item.enum?.filter((enumItem) => enumItem !== null); if (!item.type && item.items) {