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,6 +1360,7 @@ public class DefaultCodegen implements CodegenConfig {
allProperties = new LinkedHashMap<String, Schema>();
allRequired = new ArrayList<String>();
m.allVars = new ArrayList<CodegenProperty>();
if(composed.getAllOf() != null) {
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
for (Schema innerModel : composed.getAllOf()) {
if (m.discriminator == null) {
@ -1375,6 +1376,7 @@ public class DefaultCodegen implements CodegenConfig {
break; // only one ModelImpl with discriminator allowed in allOf
}
}
}
} else {
allProperties = null;
allRequired = null;

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();