Code Monkey home page Code Monkey logo

jsonschema-to-uml's Introduction

jsonSchema-to-uml

A tool to generate UML models from JSON schema documents.

Requirements

To generate UML models:

  • Eclipse Modeling tools (it can be found here).

To visualize the generated UML models:

  • A UML 2.5 modeling environment in Eclipse such as Papyrus or UMLDesigner (we tested the tool with Papyrus).

Installation

  1. Open Eclipse IDE
  2. Click on Help / Install New Software...
  3. Click on Add... and fill in the form as indicated. The update site is
https://som-research.github.io/jsonSchema-to-uml/update/
  1. Select JSONSchema to UML then click on Next.
  2. Follow the the rest of the steps (license, etc...) and reboot Eclipse.

Using the plugin

  1. Create a Project or use an existing project in your workspace.
  2. Import the JSON Schema documents in your Eclipse project.
  3. To generate a UML model from your documents you can right-click on a JSON file of your project or a folder containing your documents, and select the JSONSchema to UML/Generate Class diagram option.
  4. A UML model corresponding to the input definition will be generated in the folder src-gen of your project.

Visualizing the Class diagram using Papyrus

  1. Install Papyrus if you didn't do it yet (You can find the instructions here).
  2. Open the perspective Papyrus.
  3. Right-click on the generated UML model and select New -> Papyrus Model.
  4. Follow the steps in the wizard to initialize a Class diagram (keep everything as predefined except in the Initialization information step where you should check Class Diagram as the Representation kind).
  5. Drag-and-drop the UML elements from the Model Explrer into the editor.
  6. Align and arrange the layout as you prefer.
  7. Save.

The mapping in a nutshell

The generation process apply this (non exhaustive) list of mappings:

  • Each JSON Schema element is represented by a UML Class
  • Properties in JSON Schema elements represent the properties of a UML Class.
    • If the property is of primitive type it will become an attribute in the UML Class
    • If the property is of type enum, an Enumeration will be created and an attribute in the UML Class will be added
    • If the property is of type object or refers to other element (using $ref), an association is created in the UML Class. The type of the association corresponds to the UML Class element created from the object (or the referred object)
  • Hierarchies are created from allOf, oneOf, anyOf
  • The elements defined in definitions are considered as a library of JSON Schema elements and therefore they generate new UML Classes
  • The folder structure is used to created UML Packages containing the UML Classes coming from the JSON Schema files.

jsonschema-to-uml's People

Contributors

jlcanovas avatar zsquirrel1009 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonschema-to-uml's Issues

Request that error dialog give details on error.

Hello, The project of JSON files I want to import has right at 1900 JSON files in it. Because of this iit would help significantly if the error dialog could contain information on the error such as file name, error type, line number, with file name being far and away the most helpful item.

Thanks for considering.

Problem Occurred

I've tried installing in several versions of Eclipse and Eclipse with Papyrus all of them fail when I try and do JSONSchema to UML with a dialog saying Problem Occurred. The details of the error are:

An internal error occurred during:
"edu.uoc.som.jsonschematouml.ui.popup.handlers.ConvertToClassDiagram".
java.lang.NullPointerException

I've tried several different JSON Schema files. The example of one is shown below:

{
"id": "/common/core/fieldTypes/codeType_v02_00_rev001.json#",
"$schema": "http://json-schema.org/draft-03/schema#",
"title": "Code",
"description": "The code for the related entity. If this is a coded value, codeValue and shortName should be used. If this is just a string value, only shortName is necessary",
"type": "object",
"additionalProperties": false,
"properties": {
"codeValue": {
"description": "The code for the related entity",
"type": "string"
},
"shortName": {
"description": "Short description of the related code",
"type": "string"
},
"longName": {
"description": "Long description of the related code",
"type": "string"
}
}
}

NullPointerException

Hello,
im having two issues:

  1. I have a JSON file (https://github.com/dashevo/dpns-contract/blob/v0.2-dev/src/schema/dpns-documents.json) that visualizes great with your "JSON Discoverer" but does not work at all with this eclipse plugin. Actually none of my simple examples run. They all have no header and just start with the json structure. There will be no errror and the resulting uml is just:

<?xml version="1.0" encoding="UTF-8"?> <uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_DZCE0EHBEeqcCL9vRpPMpg" name="myJSON"> <packagedElement xmi:type="uml:Package" xmi:id="_DZCE0UHBEeqcCL9vRpPMpg" name="myJSON"> <packagedElement xmi:type="uml:Class" xmi:id="_DZCE0kHBEeqcCL9vRpPMpg" name="Unknown"/> <packagedElement xmi:type="uml:Class" xmi:id="_DZCE00HBEeqcCL9vRpPMpg" name="Dpns-schema"/> </packagedElement> </uml:Model>

  1. So it seems the eclipse plugin needs a header with "schema" and "id". But now I tested the testValid.json from your repo (https://github.com/SOM-Research/jsonSchema-to-uml/blob/master/plugins/edu.uoc.som.jsonschematouml.test/inputs/testValid.json) and this file produces NullPointerException:
    An internal error occurred during: "edu.uoc.som.jsonschematouml.ui.popup.handlers.ConvertToClassDiagram". java.lang.NullPointerException

I saw the solved issue with similar problem, but testValid.json should have valid URI as id.

best regards,

IllegalStateException when type is an array

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
                }
            ],

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.