From 2bc0e5f7457615f175ba936a0093f8fc5f7ff1d2 Mon Sep 17 00:00:00 2001 From: David Omid Date: Thu, 5 Sep 2024 14:43:34 +0100 Subject: [PATCH] [typescript-fetch] Fixed issue where unique arrays (sets) of primitive values aren't initialized properly (#19521) * Fix for https://github.com/OpenAPITools/openapi-generator/issues/19520 * Removed redundant Array cast * Fixed modelGeneric.mustache * Updated samples --- .../resources/typescript-fetch/modelGeneric.mustache | 10 ++++++++++ .../typescript-fetch/builds/default-v3.0/models/Pet.ts | 2 +- .../builds/snakecase-discriminator/models/Pet.ts | 2 +- .../builds/validation-attributes/models/Pet.ts | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache index c6d384855b5..bf91a7f3db6 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache @@ -55,6 +55,15 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole {{/additionalPropertiesType}} {{#vars}} {{#isPrimitiveType}} + {{#isArray}} + {{#uniqueItems}} + '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}{{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{/required}}new Set(json['{{baseName}}']), + {{/uniqueItems}} + {{^uniqueItems}} + '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}{{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{/required}}json['{{baseName}}'], + {{/uniqueItems}} + {{/isArray}} + {{^isArray}} {{#isDateType}} '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}({{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{/required}}new Date(json['{{baseName}}'])), {{/isDateType}} @@ -66,6 +75,7 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}json['{{baseName}}'], {{/isDateTimeType}} {{/isDateType}} + {{/isArray}} {{/isPrimitiveType}} {{^isPrimitiveType}} {{#isArray}} diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts index bb8a56bf43f..4dc3777b012 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts @@ -106,7 +106,7 @@ export function PetFromJSONTyped(json: any, ignoreDiscriminator: boolean): Pet { 'id': json['id'] == null ? undefined : json['id'], 'category': json['category'] == null ? undefined : CategoryFromJSON(json['category']), 'name': json['name'], - 'photoUrls': json['photoUrls'], + 'photoUrls': new Set(json['photoUrls']), 'tags': json['tags'] == null ? undefined : ((json['tags'] as Array).map(TagFromJSON)), 'status': json['status'] == null ? undefined : json['status'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts index bb8a56bf43f..4dc3777b012 100644 --- a/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Pet.ts @@ -106,7 +106,7 @@ export function PetFromJSONTyped(json: any, ignoreDiscriminator: boolean): Pet { 'id': json['id'] == null ? undefined : json['id'], 'category': json['category'] == null ? undefined : CategoryFromJSON(json['category']), 'name': json['name'], - 'photoUrls': json['photoUrls'], + 'photoUrls': new Set(json['photoUrls']), 'tags': json['tags'] == null ? undefined : ((json['tags'] as Array).map(TagFromJSON)), 'status': json['status'] == null ? undefined : json['status'], }; diff --git a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts index e1269c6caa5..2290adbd00d 100644 --- a/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts +++ b/samples/client/petstore/typescript-fetch/builds/validation-attributes/models/Pet.ts @@ -107,7 +107,7 @@ export function PetFromJSONTyped(json: any, ignoreDiscriminator: boolean): Pet { 'id': json['id'] == null ? undefined : json['id'], 'category': json['category'] == null ? undefined : CategoryFromJSON(json['category']), 'name': json['name'], - 'photoUrls': json['photoUrls'], + 'photoUrls': new Set(json['photoUrls']), 'tags': json['tags'] == null ? undefined : ((json['tags'] as Array).map(TagFromJSON)), 'status': json['status'] == null ? undefined : json['status'], };