Fix NullPointer with empty Composed Schema (#107)

This commit is contained in:
Jérémie Bresson 2018-04-17 10:50:10 +02:00 committed by GitHub
parent cae0d83742
commit 93301eaacf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 13 deletions

View File

@ -1360,19 +1360,21 @@ public class DefaultCodegen implements CodegenConfig {
allProperties = new LinkedHashMap<String, Schema>();
allRequired = new ArrayList<String>();
m.allVars = new ArrayList<CodegenProperty>();
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
for (Schema innerModel : composed.getAllOf()) {
if (m.discriminator == null) {
m.discriminator = schema.getDiscriminator();
}
if (innerModel.getXml() != null) {
m.xmlPrefix = innerModel.getXml().getPrefix();
m.xmlNamespace = innerModel.getXml().getNamespace();
m.xmlName = innerModel.getXml().getName();
}
if (modelImplCnt++ > 1) {
LOGGER.warn("More than one inline schema specified in allOf:. Only the first one is recognized. All others are ignored.");
break; // only one ModelImpl with discriminator allowed in allOf
if(composed.getAllOf() != null) {
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
for (Schema innerModel : composed.getAllOf()) {
if (m.discriminator == null) {
m.discriminator = schema.getDiscriminator();
}
if (innerModel.getXml() != null) {
m.xmlPrefix = innerModel.getXml().getPrefix();
m.xmlNamespace = innerModel.getXml().getNamespace();
m.xmlName = innerModel.getXml().getName();
}
if (modelImplCnt++ > 1) {
LOGGER.warn("More than one inline schema specified in allOf:. Only the first one is recognized. All others are ignored.");
break; // only one ModelImpl with discriminator allowed in allOf
}
}
}
} else {

View File

@ -14,6 +14,7 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.ComposedSchema;
import io.swagger.v3.oas.models.media.Content;
import io.swagger.v3.oas.models.media.IntegerSchema;
import io.swagger.v3.oas.models.media.MediaType;
@ -162,6 +163,14 @@ public class JavaClientCodegenTest {
CodegenParameter codegenParameter3 = codegen.fromRequestBody(body3 , Collections.<String, Schema>singletonMap("Point", point), new HashSet<String>());
}
@Test
public void nullValuesInComposedSchema() throws Exception {
final JavaClientCodegen codegen = new JavaClientCodegen();
CodegenModel result = codegen.fromModel("CompSche",
new ComposedSchema());
Assert.assertEquals(result.name, "CompSche");
}
@Test
public void testParametersAreCorrectlyOrderedWhenUsingRetrofit(){
JavaClientCodegen javaClientCodegen = new JavaClientCodegen();