Skip to content

Commit

Permalink
DROOLS-6638 DMN OAS generation NPE (apache#3870) (apache#3877)
Browse files Browse the repository at this point in the history
* DROOLS-6638 reproducer

* fix (wrong loop nesting)
  • Loading branch information
tarilabs committed Oct 5, 2021
1 parent 48e09ee commit 2e5751f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,19 @@ private void buildOutputSet() {
outputDoc.put(outputDecision.getName(), ((DecisionNodeImpl) outputDecision).getDecision().getDescription());
}
} else {
CompositeTypeImpl is = new CompositeTypeImpl(ds.getModelNamespace(), TEMP, ds.getId() + "DSOutputSet");
CompositeTypeImpl os = new CompositeTypeImpl(ds.getModelNamespace(), TEMP, ds.getId() + "DSOutputSet");
for (DMNElementReference er : ds.getDecisionService().getOutputDecision()) {
String id = DMNCompilerImpl.getId(er);
DecisionNode outputDecision = model.getDecisionById(id);
if (outputDecision != null) {
is.addField(outputDecision.getName(), outputDecision.getResultType());
os.addField(outputDecision.getName(), outputDecision.getResultType());
outputDoc.put(outputDecision.getName(), ((DecisionNodeImpl) outputDecision).getDecision().getDescription());
} else {
this.outputSet = new SimpleTypeImpl(ds.getModelNamespace(), TEMP, ds.getId() + "DSOutputSet", false, null, ds.getResultType(), null);
return; // since cannot lookup correctly, just assign the model-defined DS variable type.
}
this.outputSet = is;
}
this.outputSet = os;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.kie.dmn.api.core.DMNModel;
import org.kie.dmn.api.core.DMNRuntime;
import org.kie.dmn.core.stronglytyped.DMNRuntimeTypesTest;
import org.kie.dmn.core.v1_3.DMN13specificTest;
import org.kie.dmn.openapi.model.DMNOASResult;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -66,4 +67,20 @@ public void testTF() throws Exception {
assertThat(validateUsing(validator, "{ \"Driver\": { \"Points\": 10 }, \"Violation\" : {\"Type\": \"string\"} }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"Driver\": { \"Points\": 10 }, \"Violation\" : {\"Type\": \"speed\",\"Actual Speed\":140, \"Speed Limit\":100} }")).isEmpty();
}

@Test
public void testCH11() throws Exception {
final DMNRuntime runtime = createRuntimeWithAdditionalResources("Chapter 11 Example.dmn",
DMN13specificTest.class,
"Financial.dmn");
DMNOASResult result = DMNOASGeneratorFactory.generator(runtime.getModels()).build();

DMNModel modelUnderTest = runtime.getModel("http://www.trisotech.com/definitions/_9d01a0c4-f529-4ad8-ad8e-ec5fb5d96ad4", "Chapter 11 Example");
ObjectNode syntheticJSONSchema = synthesizeSchema(result, modelUnderTest);
JsonSchema validator = getJSONSchema(syntheticJSONSchema);

assertThat(validateUsing(validator, "{ \"asd\":123 }")).isNotEmpty();
assertThat(validateUsing(validator, "{ \"Applicant data\": {}, \"Requested product\": {}, \"Bureau data\": {}, \"Supporting documents\": null, \"Loan default data\": \"data...\" }")).isEmpty();

}
}

0 comments on commit 2e5751f

Please sign in to comment.