From c98aae77b05c89a35fa7c179ee3ccec4040ba465 Mon Sep 17 00:00:00 2001 From: Jason Lor <197345+jasonlor@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:41:54 -0700 Subject: [PATCH] #970 Use model.uniqueItems to determine whether Set or Array --- packages/openapi-ts/src/compiler/typedef.ts | 3 ++- packages/openapi-ts/src/utils/type.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/openapi-ts/src/compiler/typedef.ts b/packages/openapi-ts/src/compiler/typedef.ts index 20fd4131c..5a8cc88b0 100644 --- a/packages/openapi-ts/src/compiler/typedef.ts +++ b/packages/openapi-ts/src/compiler/typedef.ts @@ -170,10 +170,11 @@ export const createTypeRecordNode = ( export const createTypeArrayNode = ( types: (any | ts.TypeNode)[], isNullable: boolean = false, + isUnique: boolean = false, ) => { const node = createTypeReferenceNode({ typeArguments: [createTypeUnionNode({ types })], - typeName: 'Array', + typeName: isUnique ? 'Set' : 'Array', }); return maybeNullable({ isNullable, node }); }; diff --git a/packages/openapi-ts/src/utils/type.ts b/packages/openapi-ts/src/utils/type.ts index 74fc159e1..3a4985858 100644 --- a/packages/openapi-ts/src/utils/type.ts +++ b/packages/openapi-ts/src/utils/type.ts @@ -79,10 +79,18 @@ const typeArray = (model: Model) => { return tuple; } - return compiler.typeArrayNode([toType(model.link)], model.isNullable); + return compiler.typeArrayNode( + [toType(model.link)], + model.isNullable, + model.uniqueItems, + ); } - return compiler.typeArrayNode([base(model)], model.isNullable); + return compiler.typeArrayNode( + [base(model)], + model.isNullable, + model.uniqueItems, + ); }; const typeEnum = (model: Model) => {