diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java index 512ddce35cb..90de094757d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java @@ -839,10 +839,10 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo Schema inner; if (ModelUtils.isArraySchema(p)) { inner = ((ArraySchema) p).getItems(); - return this.getSchemaType(p) + "<" + this.getTypeDeclaration(inner) + ">"; + return this.getSchemaType(p) + "<" + this.getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner)) + ">"; } else if (ModelUtils.isMapSchema(p)) { inner = (Schema) p.getAdditionalProperties(); - return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }"; + return "{ [key: string]: " + this.getTypeDeclaration(ModelUtils.unaliasSchema(this.openAPI, inner)) + "; }"; } else if (ModelUtils.isFileSchema(p)) { return "HttpFile"; } else if (ModelUtils.isBinarySchema(p)) { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/TypeScriptClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/TypeScriptClientCodegenTest.java new file mode 100644 index 00000000000..20084678d3f --- /dev/null +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/TypeScriptClientCodegenTest.java @@ -0,0 +1,44 @@ +package org.openapitools.codegen.typescript.fetch; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.media.*; +import org.openapitools.codegen.TestUtils; +import org.openapitools.codegen.languages.TypeScriptClientCodegen; +import org.openapitools.codegen.utils.ModelUtils; +import org.testng.Assert; +import org.testng.annotations.Test; + + +public class TypeScriptClientCodegenTest { + @Test + public void getTypeDeclarationTest() { + Schema childSchema = new ArraySchema().items(new StringSchema()); + + OpenAPI api = TestUtils.createOpenAPI(); + api.getComponents().addSchemas("Child", childSchema); + + TypeScriptClientCodegen codegen = new TypeScriptClientCodegen(); + codegen.setOpenAPI(api); + + // Cf. issue #4968: Array of Alias of Array + Schema parentSchema = new ArraySchema().items( + new Schema().$ref("#/components/schemas/Child") + ); + + ModelUtils.setGenerateAliasAsModel(false); + Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array>"); + + ModelUtils.setGenerateAliasAsModel(true); + Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array"); + + // Same for Map + parentSchema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/Child")); + + ModelUtils.setGenerateAliasAsModel(false); + Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Array; }"); + + ModelUtils.setGenerateAliasAsModel(true); + Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Child; }"); + } + +} diff --git a/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts index 4241ca3d329..ec8437b19ca 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts @@ -73,7 +73,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URLParse(url, true); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts index 7bb54a77ff9..8afe112b13b 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts @@ -93,7 +93,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URLParse(url, true); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts index 4241ca3d329..ec8437b19ca 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts @@ -73,7 +73,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URLParse(url, true); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts index a3207336003..4ae3fd11b9f 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts @@ -68,7 +68,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URLParse(url, true); } /** diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts index 4241ca3d329..ec8437b19ca 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts @@ -73,7 +73,7 @@ export class RequestContext { * */ public setUrl(url: string) { - this.url = new URLParse(url, true); + this.url = new URLParse(url, true); } /**