forked from loafle/openapi-generator-original
[Typescript] Fix array model of alias to array (#6888)
* Add failing test * Add model unaliasing * Regenerate samples Not really related to this bug fix, but probably necessary for ci checks.
This commit is contained in:
parent
fce74884f8
commit
7cb8766a5c
@ -839,10 +839,10 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
Schema inner;
|
Schema inner;
|
||||||
if (ModelUtils.isArraySchema(p)) {
|
if (ModelUtils.isArraySchema(p)) {
|
||||||
inner = ((ArraySchema) p).getItems();
|
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)) {
|
} else if (ModelUtils.isMapSchema(p)) {
|
||||||
inner = (Schema) p.getAdditionalProperties();
|
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)) {
|
} else if (ModelUtils.isFileSchema(p)) {
|
||||||
return "HttpFile";
|
return "HttpFile";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (ModelUtils.isBinarySchema(p)) {
|
||||||
|
@ -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<Array<string>>");
|
||||||
|
|
||||||
|
ModelUtils.setGenerateAliasAsModel(true);
|
||||||
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "Array<Child>");
|
||||||
|
|
||||||
|
// Same for Map
|
||||||
|
parentSchema = new MapSchema().additionalProperties(new Schema().$ref("#/components/schemas/Child"));
|
||||||
|
|
||||||
|
ModelUtils.setGenerateAliasAsModel(false);
|
||||||
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Array<string>; }");
|
||||||
|
|
||||||
|
ModelUtils.setGenerateAliasAsModel(true);
|
||||||
|
Assert.assertEquals(codegen.getTypeDeclaration(parentSchema), "{ [key: string]: Child; }");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -73,7 +73,7 @@ export class RequestContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public setUrl(url: string) {
|
public setUrl(url: string) {
|
||||||
this.url = new URLParse(url, true);
|
this.url = new URLParse(url, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,7 +93,7 @@ export class RequestContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public setUrl(url: string) {
|
public setUrl(url: string) {
|
||||||
this.url = new URLParse(url, true);
|
this.url = new URLParse(url, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +73,7 @@ export class RequestContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public setUrl(url: string) {
|
public setUrl(url: string) {
|
||||||
this.url = new URLParse(url, true);
|
this.url = new URLParse(url, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +68,7 @@ export class RequestContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public setUrl(url: string) {
|
public setUrl(url: string) {
|
||||||
this.url = new URLParse(url, true);
|
this.url = new URLParse(url, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +73,7 @@ export class RequestContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public setUrl(url: string) {
|
public setUrl(url: string) {
|
||||||
this.url = new URLParse(url, true);
|
this.url = new URLParse(url, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user