reTHINK-project / dev-service-framework

DEPRECATED! Service framework libs have been moved to dev-runtime-core repo
Apache License 2.0
1 stars 2 forks source link

update json-schema generation with new package structure. #22

Closed pchainho closed 8 years ago

pchainho commented 8 years ago

Update json-schema generation tool according to new package structure as discussed in #16

json-schema generation tool should be moved to this repo: src/tools

shumy commented 8 years ago

I'm trying to figure out what should be the new output. For example, picking the message.cduml and one of the genereted files Message.json:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "Message",
    "type": "object",
    "required": ["id", "from", "type", "contextId", "body", "messageType", "uRL", "messageBodyArray"],
    "additionalProperties": false,
    "properties": {
        "id": {
            "type": "string"
        },
        "from": {
            "$ref": "../URL/URL.json"
        },
        "to": {
            "$ref": "../URL/URLList.json"
        },
        "type": {
            "$ref": "../Message/MessageType.json"
        },
        "contextId": {
            "type": "null"
        },
        "body": {
            "$ref": "../Message/MessageBody.json"
        },
        "signature": {
            "type": "null"
        }
        ,
        "messageType": {
            "$ref": "../Message/MessageType.json"
        },
        "uRL": {
            "$ref": "../URL/URL.json"
        },
        "messageBodyArray": {
            "$ref": "../Message/MessageBody.json"
        }
    }
}

How should I generate the references? I was trying to use the concept of "definitions" http://spacetelescope.github.io/understanding-json-schema/structuring.html But this requires to define a top level class in the package. This can work in message.cduml if considering the top level class of the same name of the package, but it's not always possible.

shumy commented 8 years ago

Another problem that as came up is related to mismatch between UML definitions and JSON Schema. This is not a technical problem and there's nothing wrong with the actual generated schemas, it's just, they are not as useful as it seems. The way JSON Schema is validated, is starting on a root object and verifies every field and reference attached to it. However class diagrams don't strictly follow a tree structure. Even if we define a root object, if there are detached definitions (with inverted references), these are not validated. JSON schema is directly related to document databases. But class diagramas define better, relational databases. I don't see a way to solve this, unless carefully designing the class diagrams. By following a tree structure and by separating in different packages. Any ideas are wellcome.

shumy commented 8 years ago

Found other minor issues:

  1. How to define some special types. Currently URL's are defined as classes, these are converted to JSON object definitions. However URL's are formatted strings instead.
  2. When defining a reference in PlantUML like ClassX --> ClassY there is no place to define the reference variable name. The placeolder after the definition could be used like ClassX --> ClassY:name but this is currently defined as free text (not suitable to a variable name, because it can have spaces).
  3. There are some circular references in the model and can be a problem when validating data, creating infinite loops.
  4. There are no arrays or references to native types.

Some proposed solutions:

  1. Use the PlantUML feature "specific spot" to define custom type elements. Just add <<(T,orchid)>> to the class definition to be a Type definition.
  2. Use the relation description for variable name, and drop the general purpose.
  3. Do not generate inverted references. For example ClassX --> ClassY will be the same as ClassX -- ClassY assuming the left to right direction. But I would rather prefer that UML be corrected instead.
  4. Should be defined as "field: type[]"
pchainho commented 8 years ago
  1. Use the PlantUML feature "specific spot" to define custom type elements. Just add <<(T,orchid)>> to the class definition to be a Type definition.

ok

  1. Use the relation description for variable name, and drop the general purpose.

We agreed to ignore associations like ClassX --> ClassY and to just take into account attributs defined in each class.

  1. Do not generate inverted references. For example ClassX --> ClassY will be the same as ClassX -- ClassY assuming the left to right direction.

This one should not be an issue anymore since we agreed to ignore plantuml associations

  1. Should be defined as "field: type[]"

ok

shumy commented 8 years ago

Parser was not prepared to accept relations beetween packages. It's was updated, but no JSON is generated for this.

shumy commented 8 years ago

Parser was updated, and schemas generated.

  1. Code and tool available at "tools/plantuml-json-parser/"
  2. Model sources available at "schemas/"
  3. JSON Schemas available at "schemas/json-schema/"
pchainho commented 8 years ago

Not done according to previously agreed structure

pchainho commented 8 years ago

partially done according to agreed structure. It is ready to be used for the validation of data synch objects.