diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index a2d631ae69..0747ade522 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -4423,7 +4423,11 @@ public class DefaultCodegen implements CodegenConfig { } if (StringUtils.isEmpty(bodyParameterName)) { - codegenParameter.baseName = mostInnerItem.complexType; + if(StringUtils.isEmpty(mostInnerItem.complexType)) { + codegenParameter.baseName = "request_body"; + } else { + codegenParameter.baseName = mostInnerItem.complexType; + } } else { codegenParameter.baseName = bodyParameterName; } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java index 96f49448ce..40b4cb9c52 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/perl/PerlClientCodegenTest.java @@ -17,11 +17,17 @@ package org.openapitools.codegen.perl; -import org.testng.Assert; -import org.testng.annotations.Test; +import io.swagger.parser.OpenAPIParser; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.parser.core.models.ParseOptions; import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.languages.PerlClientCodegen; +import org.openapitools.codegen.utils.ModelUtils; +import org.testng.Assert; +import org.testng.annotations.Test; public class PerlClientCodegenTest { @@ -54,4 +60,14 @@ public class PerlClientCodegenTest { Assert.assertEquals(codegen.isHideGenerationTimestamp(), false); } + @Test + public void testIssue677() { + final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/issue677.yaml", null, new ParseOptions()).getOpenAPI(); + final PerlClientCodegen codegen = new PerlClientCodegen(); + + Operation operation = openAPI.getPaths().get("/issue677").getPost(); + CodegenOperation co = codegen.fromOperation("/issue677", "POST", operation, ModelUtils.getSchemas(openAPI), openAPI); + Assert.assertNotNull(co); + } + } diff --git a/modules/openapi-generator/src/test/resources/3_0/issue677.yaml b/modules/openapi-generator/src/test/resources/3_0/issue677.yaml new file mode 100644 index 0000000000..1aa5a1c6d7 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue677.yaml @@ -0,0 +1,21 @@ +openapi: 3.0.1 +info: + title: My title + description: API under test + version: 1.0.7 +servers: +- url: https://localhost:9999/root +paths: + /issue677: + post: + requestBody: + content: + application/json: + schema: + type: array + items: + type: string + responses: + 201: + description: OK +components: {}