aboutsummaryrefslogtreecommitdiffstats
path: root/docs/json.rst
blob: ca7d9e5d3c7b8ac4e55ade9521d908f880ddced9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
            }
          ]
        }
      ]
    }