Consider cases where complexType is null (#680)

This commit is contained in:
Jérémie Bresson 2018-07-29 13:10:58 +02:00 committed by GitHub
parent 3c3ac0a071
commit 14ab3d763e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 3 deletions

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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: {}