Skip to content

Commit

Permalink
fix navigazione composed model
Browse files Browse the repository at this point in the history
  • Loading branch information
gcornacchia committed Dec 3, 2024
1 parent 1a98099 commit 2862cc2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ private void navigateModel(String originalRef, List<String> usedDefinition, Map<
Schema s = (Schema) res.get(ITEMS);
if (s.get$ref()!=null) {
navigateModel(s.get$ref(), usedDefinition, res, null);
} else if (s instanceof ComposedSchema) {
ComposedSchema cm = (ComposedSchema)s;
lookComposedModel(cm.getAllOf(),usedDefinition,res);
lookComposedModel(cm.getAnyOf(),usedDefinition,res);
lookComposedModel(cm.getOneOf(),usedDefinition,res);
if (cm.getNot()!=null) {
navigateModel(cm.getNot().get$ref(), usedDefinition, res, null);
}
}
}
} else if (ob instanceof ComposedSchema) {
Expand Down Expand Up @@ -239,6 +247,15 @@ private void navigateSchema(String propertyName, Schema p, List<String> usedDefi
if (mp.getAdditionalProperties() instanceof Schema ) {
navigateSchema(mp.getName(), (Schema)mp.getAdditionalProperties(), usedDefinition, res);
}
} else if (p instanceof ComposedSchema){
ComposedSchema cm = (ComposedSchema)p;
lookComposedModel(cm.getAllOf(),usedDefinition,res);
lookComposedModel(cm.getAnyOf(),usedDefinition,res);
lookComposedModel(cm.getOneOf(),usedDefinition,res);
if (cm.getNot()!=null) {
navigateModel(cm.getNot().get$ref(), usedDefinition, res, null);
}

} else {
log.debug(p.getClass() + " - nothing to do!");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
{
"components" : {
"schemas" : { }
"schemas" : {
"One" : {
"type" : "object",
"properties" : {
"property1" : {
"type" : "string"
}
},
"additionalProperties" : false
},
"Two" : {
"type" : "object",
"properties" : {
"property2" : {
"type" : "string"
}
},
"additionalProperties" : false
}
}
},
"$schema" : "http://json-schema.org/draft-04/schema#",
"additionalProperties" : false,
"title" : "updatePetresponse200",
"type" : "array",
"items" : { }
"type" : "object",
"properties" : {
"id" : {
"type" : "array",
"items" : {
"oneOf" : [ {
"$ref" : "#/components/schemas/One"
}, {
"$ref" : "#/components/schemas/Two"
} ]
}
}
}
}
16 changes: 10 additions & 6 deletions src/test/resources/petstoreoas3ArrayAllofInline.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,16 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"oneOf": [
{"$ref": "#/components/schemas/One"},
{"$ref": "#/components/schemas/Two"}
]
"properties": {
"id": {
"type": "array",
"items": {
"oneOf": [
{"$ref": "#/components/schemas/One"},
{"$ref": "#/components/schemas/Two"}
]
}
}
}
}
}
Expand Down

0 comments on commit 2862cc2

Please sign in to comment.