SOM-Research / jsonSchema-to-uml

A tool to generate UML class diagrams from JSON schema documents
https://som-research.uoc.edu/research-tools/
Eclipse Public License 2.0
39 stars 4 forks source link

IllegalStateException when type is an array #5

Open DavidMhn opened 3 years ago

DavidMhn commented 3 years ago

When an object type is an array, for instance "type": ["string","integer"] The conversion fails with this stack

java.lang.IllegalStateException
    at com.google.gson.JsonArray.getAsString(JsonArray.java:226)
    at edu.uoc.som.jsonschematouml.generators.JSONSchemaToUML.analyzeProperty(JSONSchemaToUML.java:463)
    at edu.uoc.som.jsonschematouml.generators.JSONSchemaToUML.analyzeObject(JSONSchemaToUML.java:336)
    at edu.uoc.som.jsonschematouml.generators.JSONSchemaToUML.analyzeRootSchemaElement(JSONSchemaToUML.java:264)
    at edu.uoc.som.jsonschematouml.generators.JSONSchemaToUML.analyzeDefinitions(JSONSchemaToUML.java:754)
    at edu.uoc.som.jsonschematouml.generators.JSONSchemaToUML.analyzeRootSchemaElement(JSONSchemaToUML.java:269)
    at edu.uoc.som.jsonschematouml.generators.JSONSchemaToUML.analyzeSchema(JSONSchemaToUML.java:253)
    at edu.uoc.som.jsonschematouml.generators.JSONSchemaToUML.analyze(JSONSchemaToUML.java:219)
    at edu.uoc.som.jsonschematouml.generators.JSONSchemaToUML.launch(JSONSchemaToUML.java:171)
    at edu.uoc.som.jsonschematouml.ui.handlers.ConvertToClassDiagram$1.run(ConvertToClassDiagram.java:56)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

This line doesn't handle the array case:

JSONSchemaToUML.java:463
 else if(itemsObject.has("type") && itemsObject.get("type").getAsString().equals("string")) { 

Note this case of type is conform to json schema type definition (at least in json schema draft v7):

"type": {
            "anyOf": [
                {"$ref": "#/definitions/simpleTypes"},
                {
                    "type": "array",
                    "items": {"$ref": "#/definitions/simpleTypes"},
                    "minItems": 1,
                    "uniqueItems": true
                }
            ],