diff options
Diffstat (limited to 'docs/json.rst')
-rw-r--r-- | docs/json.rst | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/docs/json.rst b/docs/json.rst new file mode 100644 index 0000000..ca7d9e5 --- /dev/null +++ b/docs/json.rst @@ -0,0 +1,128 @@ +**************** +JSON Meta Export +**************** + +QFace allows you to easily export the domain model as a JSON document. This enables you to parse the domain information to be +used with other tooling. + +Inside your generator you need to register the filter first + +.. code-block:: python + + from qface.filters import jsonify + + + generator = Generator(search_path=search_path) + generator.register_filter('jsonify', jsonify) + +Then inside the template you can transform any symbol into a JSON string using the ``jsonify`` filter. + +.. code-block:: jinja + + {{module|jsonify}} + +Depending on your need you might want to create a JSON document from the whole system or from each interface or you are just +interested on a JSON representation of an enumeration. The portion of the domain model exported to JSON really depends on your custom code generator and on which doamin element you apply the ``jsonify`` filter. + +JSON Format +=========== + +Taking the example QFace document + +.. code-block:: thrift + + module org.example 1.0; + + interface Echo { + readonly string currentMessage; + void echo(Message message); + } + + struct Message { + string text; + } + + enum Status { + Null, + Loading, + Ready, + Error + } + + +The following JSON output is generated + +.. code-block:: json + + { + "name": "org.example", + "version": "1.0", + "interfaces": [ + { + "name": "Echo", + "properties": [ + { + "name": "currentMessage", + "type": { + "name": "string", + "primitive": true + }, + "readonly": true + } + ], + "operations": [ + { + "name": "echo", + "parameters": [ + { + "name": "message", + "type": { + "name": "Message", + "complex": true + } + } + ] + } + ], + "signals": [] + } + ], + "structs": [ + { + "name": "Message", + "fields": [ + { + "name": "text", + "type": { + "name": "string", + "primitive": true + } + } + ] + } + ], + "enums": [ + { + "name": "Status", + "enum": true, + "members": [ + { + "name": "Null", + "value": 0 + }, + { + "name": "Loading", + "value": 1 + }, + { + "name": "Ready", + "value": 2 + }, + { + "name": "Error", + "value": 3 + } + ] + } + ] + } |