@@ -107,7 +107,7 @@ public JsonObject create(BmmModel bmm) {
107107 JsonObjectBuilder definitions = jsonFactory .createObjectBuilder ();
108108
109109
110- allOfArray .add (createRequiredArray ("_type" ));
110+ allOfArray .add (createRequiredArray (typeNameProperty ));
111111
112112 //for every root type, if the type is right, check that type
113113 //anyof does more or less the same, but this is faster plus it gives MUCH less errors!
@@ -220,7 +220,7 @@ private void addClass(JsonObjectBuilder definitions, BmmClass bmmClass) {
220220 if (hasRequiredProperties ) {
221221 definition .add ("required" , required );
222222 }
223- definition . add ( "properties" , properties );
223+
224224
225225 if (!allowAdditionalProperties && atLeastOneProperty ) {
226226 definition .add ("additionalProperties" , false );
@@ -243,6 +243,7 @@ private void addClass(JsonObjectBuilder definitions, BmmClass bmmClass) {
243243 }
244244 }
245245 if (addedAncestors ) {
246+ definition .add ("properties" , properties );
246247 polymorphicArray .add (definition );
247248 definitions .add (typeName , jsonFactory .createObjectBuilder ().add ("allOf" , polymorphicArray ).build ());
248249 } else {
@@ -252,14 +253,16 @@ private void addClass(JsonObjectBuilder definitions, BmmClass bmmClass) {
252253 Map <String , BmmClass > allDescendants = bmmModel .getAllDescendantClassObjects (bmmClass );
253254 for (BmmClass descendant :allDescendants .values ()) {
254255 if (shouldClassBeIncluded (descendant )) {
255- descendantsMappings .add (descendant .getClassKey (), createReference (descendant .getClassKey ()));
256+ descendantsMappings .add (descendant .getClassKey (), createReferenceTarget (descendant .getClassKey ()));
256257 }
257258 }
259+ properties .add ("_type" , createType ("string" ));
258260 definition .add ("discriminator" , jsonFactory .createObjectBuilder ()
259261 .add ("propertyName" , "_type" )
260- .add ("mappings " ,descendantsMappings )
262+ .add ("mapping " ,descendantsMappings )
261263 );
262264 }
265+ definition .add ("properties" , properties );
263266 definitions .add (typeName , definition );
264267 }
265268 }
@@ -397,7 +400,11 @@ private JsonObjectBuilder createReference(String rootType) {
397400// if(rootType.equalsIgnoreCase("Any")) {
398401// return jsonFactory.createObjectBuilder().add("type", "object");
399402// }
400- return jsonFactory .createObjectBuilder ().add ("$ref" , "#/components/schemas/" + convertTypeName (rootType ));
403+ return jsonFactory .createObjectBuilder ().add ("$ref" , createReferenceTarget (rootType ));
404+ }
405+
406+ private String createReferenceTarget (String typeName ) {
407+ return "#/components/schemas/" + convertTypeName (typeName );
401408 }
402409
403410 private boolean isJSPrimitive (String rootType ) {
0 commit comments