From 5a9bf786721ef9820a27e938964489970fc2f17f Mon Sep 17 00:00:00 2001 From: David Omid <davidomid@hotmail.com> Date: Wed, 4 Sep 2024 01:04:04 +0000 Subject: [PATCH 1/4] Fix for https://github.com/OpenAPITools/openapi-generator/issues/19520 --- .../resources/typescript-fetch/modelGeneric.mustache | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 803b27608ea1..dccbce839fcb 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache @@ -54,6 +54,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}}new Set(json['{{baseName}}']),{{/required}} + {{/uniqueItems}} + {{^uniqueItems}} + '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}{{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}(json['{{baseName}}'] as Array<any>),{{/required}} + {{/uniqueItems}} + {{/isArray}} + {{^isArray}} {{#isDateType}} '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}({{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{/required}}new Date(json['{{baseName}}'])), {{/isDateType}} @@ -65,6 +74,7 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}json['{{baseName}}'], {{/isDateTimeType}} {{/isDateType}} + {{/isArray}} {{/isPrimitiveType}} {{^isPrimitiveType}} {{#isArray}} From e9ab486fc9e7e02d3b7fb1a7fc18fdf89a9284a9 Mon Sep 17 00:00:00 2001 From: David Omid <davidomid@hotmail.com> Date: Wed, 4 Sep 2024 01:48:29 +0000 Subject: [PATCH 2/4] Removed redundant Array<any> cast --- .../src/main/resources/typescript-fetch/modelGeneric.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 dccbce839fcb..be3a94cd08d9 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache @@ -59,7 +59,7 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}{{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}new Set(json['{{baseName}}']),{{/required}} {{/uniqueItems}} {{^uniqueItems}} - '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}{{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}(json['{{baseName}}'] as Array<any>),{{/required}} + '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}{{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}json['{{baseName}}'],{{/required}} {{/uniqueItems}} {{/isArray}} {{^isArray}} From 2c8d6a95a6e5ca46007f1f5ddf9c41d33a1ac29b Mon Sep 17 00:00:00 2001 From: David Omid <davidomid@hotmail.com> Date: Wed, 4 Sep 2024 03:00:19 +0000 Subject: [PATCH 3/4] Fixed modelGeneric.mustache --- .../src/main/resources/typescript-fetch/modelGeneric.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 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 be3a94cd08d9..8e68702cd942 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache @@ -56,10 +56,10 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole {{#isPrimitiveType}} {{#isArray}} {{#uniqueItems}} - '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}{{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}new Set(json['{{baseName}}']),{{/required}} + '{{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}}json['{{baseName}}'],{{/required}} + '{{name}}': {{^required}}json['{{baseName}}'] == null ? undefined : {{/required}}{{#required}}{{#isNullable}}json['{{baseName}}'] == null ? null : {{/isNullable}}{{/required}}json['{{baseName}}'], {{/uniqueItems}} {{/isArray}} {{^isArray}} From c06b05de6717db6bb75228ff052804cc476da9b1 Mon Sep 17 00:00:00 2001 From: David Omid <davidomid@hotmail.com> Date: Wed, 4 Sep 2024 03:00:41 +0000 Subject: [PATCH 4/4] Updated samples --- .../petstore/typescript-fetch/builds/default-v3.0/models/Pet.ts | 2 +- .../builds/snakecase-discriminator/models/Pet.ts | 2 +- .../typescript-fetch/builds/validation-attributes/models/Pet.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 f2ad3c1ee466..d87ecc823329 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 @@ -104,7 +104,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<any>).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 f2ad3c1ee466..d87ecc823329 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 @@ -104,7 +104,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<any>).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 a26542a5d5e1..00d42907cb4e 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 @@ -105,7 +105,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<any>).map(TagFromJSON)), 'status': json['status'] == null ? undefined : json['status'], };