Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
Issue swagger-api#15: fix NullPointerException with ComposedSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini committed Feb 21, 2018
1 parent 82632bb commit 3ab39a7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1207,18 +1207,26 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
allRequired = new ArrayList<String>();
codegenModel.allVars = new ArrayList<CodegenProperty>();
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
for (Schema innerModel: composed.getAllOf()) {
if (codegenModel.discriminator == null) {
codegenModel.discriminator = schema.getDiscriminator();
}
if (innerModel.getXml() != null) {
codegenModel.xmlPrefix = innerModel.getXml().getPrefix();
codegenModel.xmlNamespace = innerModel.getXml().getNamespace();
codegenModel.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) {
for (Schema innerModel : composed.getAllOf()) {
if (codegenModel.discriminator == null) {
codegenModel.discriminator = schema
.getDiscriminator();
}
if (innerModel.getXml() != null) {
codegenModel.xmlPrefix = innerModel.getXml()
.getPrefix();
codegenModel.xmlNamespace = innerModel.getXml()
.getNamespace();
codegenModel.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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.swagger.codegen.CodegenModelType;
import io.swagger.codegen.CodegenParameter;
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;
Expand Down Expand Up @@ -161,4 +162,12 @@ public void arraysInRequestBody() throws Exception {
Assert.assertEquals(codegenParameter3.dataType, "List<Point>");
Assert.assertEquals(codegenParameter3.baseType, "Point");
}

@Test
public void nullValuesInComposedSchema() throws Exception {
final JavaClientCodegen codegen = new JavaClientCodegen();
CodegenModel result = codegen.fromModel("CompSche",
new ComposedSchema());
Assert.assertEquals(result.name, "CompSche");
}
}

0 comments on commit 3ab39a7

Please sign in to comment.