Line data Source code
1 : /* File: json_schema_writer.c; Copyright and License: see below */
2 :
3 : #include "json/json_schema_writer.h"
4 : #include "json/json_constants.h"
5 : #include "utf8stringbuf/utf8string.h"
6 : #include "u8/u8_trace.h"
7 : #include <assert.h>
8 :
9 : static const char SCHEMA_GRAPH_HEADER[]
10 : =
11 : "{\n"
12 : " \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n"
13 : " \"$id\": \"https://localhost/1d0f422c-9c68-4fe4-a295-87bc8e8d080d/crystal-facet-uml.schema.json\",\n"
14 : " \"title\": \"crystal-facet-uml model\",\n"
15 : " \"description\": \"This schema defines the structure of json objects to store a uml/sysml model.\",\n"
16 : " \"type\": \"object\",\n"
17 : " \"required\": [\"" JSON_CONSTANTS_KEY_HEAD "\"],\n"
18 : " \"properties\":\n"
19 : " {\n"
20 : " \"" JSON_CONSTANTS_KEY_HEAD "\":\n"
21 : " {\n"
22 : " \"description\": \"" JSON_CONSTANTS_KEY_HEAD " defines properties of the json file.\",\n"
23 : " \"type\": \"object\"\n"
24 : " },\n"
25 : ;
26 :
27 : static const char SCHEMA_GRAPH_VIEWS[]
28 : =
29 : " \"" JSON_CONSTANTS_KEY_VIEWS "\":\n"
30 : " {\n"
31 : " \"description\": \"" JSON_CONSTANTS_KEY_VIEWS " is an array whose elements describe the views on the model.\",\n"
32 : " \"type\": \"array\",\n"
33 : " \"items\":\n"
34 : " {\n"
35 : " \"description\": \"An element of " JSON_CONSTANTS_KEY_VIEWS " is an object that specifies a "
36 : JSON_CONSTANTS_KEY_DIAGRAM ".\",\n"
37 : " \"type\": \"object\",\n"
38 : " \"required\": [\"" JSON_CONSTANTS_KEY_DIAGRAM "\"],\n"
39 : " \"properties\":\n"
40 : " {\n"
41 : ;
42 :
43 : static const char SCHEMA_DIAGRAM_HEADER[]
44 : =
45 : " \"" JSON_CONSTANTS_KEY_DIAGRAM "\":\n"
46 : " {\n"
47 : " \"description\": \"" JSON_CONSTANTS_KEY_DIAGRAM " is a view that is specified by listing the nodes to be shown in "
48 : #ifdef JSON_CONSTANTS_NEW_KEYS
49 : JSON_CONSTANTS_KEY_DIAGRAM_ELEMENT_LIST ".\",\n"
50 : #else
51 : JSON_CONSTANTS_KEY_DIAGRAM_ELEMENTS ".\",\n"
52 : #endif
53 : " \"type\": \"object\",\n"
54 : " \"properties\":\n"
55 : " {\n"
56 : ;
57 :
58 : static const char SCHEMA_DIAGRAM_ELEMENTS_HEADER[]
59 : =
60 : #ifdef JSON_CONSTANTS_NEW_KEYS
61 : " \"" JSON_CONSTANTS_KEY_DIAGRAM_ELEMENT_LIST "\":\n"
62 : #else
63 : " \"" JSON_CONSTANTS_KEY_DIAGRAM_ELEMENTS "\":\n"
64 : #endif
65 : " {\n"
66 : #ifdef JSON_CONSTANTS_NEW_KEYS
67 : " \"description\": \"" JSON_CONSTANTS_KEY_DIAGRAM_ELEMENT_LIST " is the list of elements shown in the diagram.\",\n"
68 : #else
69 : " \"description\": \"" JSON_CONSTANTS_KEY_DIAGRAM_ELEMENTS " is the list of elements shown in the diagram.\",\n"
70 : #endif
71 : " \"type\": \"array\",\n"
72 : " \"items\":\n"
73 : " {\n"
74 : #ifdef JSON_CONSTANTS_NEW_KEYS
75 : " \"description\": \"An element of " JSON_CONSTANTS_KEY_DIAGRAM_ELEMENT_LIST " specifies what and how to show.\",\n"
76 : #else
77 : " \"description\": \"An element of " JSON_CONSTANTS_KEY_DIAGRAM_ELEMENTS " specifies what and how to show.\",\n"
78 : #endif
79 : " \"type\": \"object\",\n"
80 : " \"properties\":\n"
81 : " {\n"
82 : ;
83 :
84 : static const char SCHEMA_DIAGRAM_ELEMENTS_FOOTER[]
85 : =
86 : " },\n"
87 : " \"additionalProperties\": false\n"
88 : " }\n"
89 : " }\n"
90 : ;
91 :
92 : static const char SCHEMA_DIAGRAM_FOOTER[]
93 : =
94 : " },\n"
95 : " \"additionalProperties\": false\n"
96 : " }\n"
97 : ;
98 :
99 : static const char SCHEMA_GRAPH_NODES[]
100 : =
101 : " }\n"
102 : " }\n"
103 : " },\n"
104 : " \"" JSON_CONSTANTS_KEY_NODES "\":\n"
105 : " {\n"
106 : " \"description\": \"" JSON_CONSTANTS_KEY_NODES " is an array whose elements describe the nodes of the model-graph.\",\n"
107 : " \"type\": \"array\",\n"
108 : " \"items\":\n"
109 : " {\n"
110 : " \"description\": \"An element of " JSON_CONSTANTS_KEY_NODES " is an object that specifies a "
111 : JSON_CONSTANTS_KEY_CLASSIFIER ".\",\n"
112 : " \"type\": \"object\",\n"
113 : " \"required\": [\"" JSON_CONSTANTS_KEY_CLASSIFIER "\"],\n"
114 : " \"properties\":\n"
115 : " {\n"
116 : ;
117 :
118 : static const char SCHEMA_CLASSIFIER_HEADER[]
119 : =
120 : " \"" JSON_CONSTANTS_KEY_CLASSIFIER "\":\n"
121 : " {\n"
122 : " \"description\": \"" JSON_CONSTANTS_KEY_CLASSIFIER " is a node that contains a list of subnodes called " JSON_CONSTANTS_KEY_CLASSIFIER_FEATURES ".\",\n"
123 : " \"type\": \"object\",\n"
124 : " \"properties\":\n"
125 : " {\n"
126 : ;
127 :
128 : static const char SCHEMA_FEATURES_HEADER[]
129 : =
130 : " \"" JSON_CONSTANTS_KEY_CLASSIFIER_FEATURES "\":\n"
131 : " {\n"
132 : " \"description\": \"" JSON_CONSTANTS_KEY_CLASSIFIER_FEATURES " is the list of features of the classifier.\",\n"
133 : " \"type\": \"array\",\n"
134 : " \"items\":\n"
135 : " {\n"
136 : " \"description\": \"An element of " JSON_CONSTANTS_KEY_CLASSIFIER_FEATURES " specifies a feature or port or lifeline.\",\n"
137 : " \"type\": \"object\",\n"
138 : " \"properties\":\n"
139 : " {\n"
140 : ;
141 :
142 : static const char SCHEMA_FEATURES_FOOTER[]
143 : =
144 : " },\n"
145 : " \"additionalProperties\": false\n"
146 : " }\n"
147 : " }\n"
148 : ;
149 :
150 : static const char SCHEMA_CLASSIFIER_FOOTER[]
151 : =
152 : " },\n"
153 : " \"additionalProperties\": false\n"
154 : " }\n"
155 : ;
156 :
157 : static const char SCHEMA_GRAPH_EDGES[]
158 : =
159 : " }\n"
160 : " }\n"
161 : " },\n"
162 : " \"" JSON_CONSTANTS_KEY_EDGES "\":\n"
163 : " {\n"
164 : " \"description\": \"" JSON_CONSTANTS_KEY_EDGES " is an array whose elements describe the edges of the model-graph.\",\n"
165 : " \"type\": \"array\",\n"
166 : " \"items\":\n"
167 : " {\n"
168 : " \"description\": \"An element of " JSON_CONSTANTS_KEY_EDGES " is an object that specifies a "
169 : JSON_CONSTANTS_KEY_RELATIONSHIP ".\",\n"
170 : " \"type\": \"object\",\n"
171 : " \"required\": [\"" JSON_CONSTANTS_KEY_RELATIONSHIP "\"],\n"
172 : " \"properties\":\n"
173 : " {\n"
174 : ;
175 :
176 : static const char SCHEMA_RELATIONSHIP_HEADER[]
177 : =
178 : " \"" JSON_CONSTANTS_KEY_RELATIONSHIP "\":\n"
179 : " {\n"
180 : " \"description\": \"" JSON_CONSTANTS_KEY_RELATIONSHIP " is an edge with 1 source and 1 destination end.\",\n"
181 : " \"type\": \"object\",\n"
182 : " \"properties\":\n"
183 : " {\n"
184 : ;
185 :
186 : static const char SCHEMA_RELATIONSHIP_FOOTER[]
187 : =
188 : " },\n"
189 : " \"additionalProperties\": false\n"
190 : " }\n"
191 : ;
192 :
193 : static const char SCHEMA_GRAPH_FOOTER[]
194 : =
195 : " }\n"
196 : " }\n"
197 : " }\n"
198 : " }\n"
199 : "}\n"
200 : ;
201 :
202 : static const char INDENT_7[] = " ";
203 : static const char INDENT_10[] = " ";
204 :
205 0 : void json_schema_writer_init ( json_schema_writer_t *this_,
206 : universal_output_stream_t *output )
207 : {
208 0 : U8_TRACE_BEGIN();
209 0 : assert( NULL != output );
210 :
211 0 : json_type_name_map_init( &((*this_).enum_map) );
212 0 : utf8stream_writer_init( &((*this_).writer), output );
213 0 : (*this_).indent = 7;
214 :
215 0 : U8_TRACE_END();
216 0 : }
217 :
218 0 : void json_schema_writer_destroy( json_schema_writer_t *this_ )
219 : {
220 0 : U8_TRACE_BEGIN();
221 :
222 0 : utf8stream_writer_destroy( &((*this_).writer) );
223 0 : json_type_name_map_destroy( &((*this_).enum_map) );
224 :
225 0 : U8_TRACE_END();
226 0 : }
227 :
228 0 : u8_error_t json_schema_writer_write_schema( json_schema_writer_t *this_ )
229 : {
230 0 : U8_TRACE_BEGIN();
231 0 : u8_error_t export_err = U8_ERROR_NONE;
232 :
233 : static const char *const ANY_ID = "id is a proposal, may be changed automatically";
234 : static const char *const ANY_UUID = "uuid is an identifier, all letters must be lowercase";
235 : static const char *const ANY_STEREO = "stereotype is available since version 1.47.0";
236 : static const char *const ANY_DESCR = "a part of the description (to be concatenated)";
237 : static const char *const ANY_ORDER
238 : = "a value between –2147483648 and 2147483647 by which to order elements in 1 or 2 dimensions";
239 :
240 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_GRAPH_HEADER );
241 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_GRAPH_VIEWS );
242 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_DIAGRAM_HEADER );
243 :
244 0 : (*this_).indent = 7;
245 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_DIAGRAM_ID, ANY_ID );
246 : static const char *const D_PARENT_NAME
247 : = "name of " JSON_CONSTANTS_KEY_DIAGRAM_PARENT " diagram, exported for reviews by humans, ignored at import";
248 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_DIAGRAM_PARENT_NAME, D_PARENT_NAME );
249 : static const char *const D_PARENT_ID = "uuid of the parent diagram, omitted by the root diagram";
250 0 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_DIAGRAM_PARENT, D_PARENT_ID, true );
251 : /* generate an enum listing all options */
252 : static const char *const D_DIAGTYPE_NAME
253 : #ifdef JSON_CONSTANTS_NEW_KEYS
254 : = JSON_CONSTANTS_KEY_TYPE_ID " as string, exported for reviews by humans, ignored at import";
255 : #else
256 : = JSON_CONSTANTS_KEY_DIAGRAM_DIAGRAM_TYPE " as string, exported for reviews by humans, ignored at import";
257 : #endif
258 0 : const char *const * D_TYPE_VALUES = json_type_name_map_get_diagram_types_list( &((*this_).enum_map) );
259 0 : export_err |= json_schema_writer_private_declare_enum( this_,
260 : JSON_CONSTANTS_KEY_TYPE_NAME,
261 : D_DIAGTYPE_NAME,
262 : D_TYPE_VALUES
263 : );
264 : static const char *const D_DIAGTYPE_ID = "id of diagram type, see source file data/include/entity/data_diagram_type.h";
265 : #ifdef JSON_CONSTANTS_NEW_KEYS
266 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_TYPE_ID, D_DIAGTYPE_ID );
267 : #else
268 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_DIAGRAM_DIAGRAM_TYPE, D_DIAGTYPE_ID );
269 : #endif
270 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_DIAGRAM_STEREOTYPE, ANY_STEREO );
271 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_DIAGRAM_NAME, "" );
272 0 : export_err |= json_schema_writer_private_declare_array_of_string( this_, JSON_CONSTANTS_KEY_DIAGRAM_DESCRIPTION, "", ANY_DESCR );
273 : #ifdef JSON_CONSTANTS_NEW_KEYS
274 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_ORDER, ANY_ORDER );
275 : #else
276 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_DIAGRAM_LIST_ORDER, ANY_ORDER );
277 : #endif
278 : /* generate an enum listing all options */
279 : static const char *const D_FLAG_NAME
280 : = JSON_CONSTANTS_KEY_DIAGRAM_DISPLAY_FLAGS " as string, exported for reviews by humans, ignored at import";
281 0 : const char *const * D_FLAG_VALUES = json_type_name_map_get_diagram_tags_list( &((*this_).enum_map) );
282 0 : export_err |= json_schema_writer_private_declare_enum( this_,
283 : JSON_CONSTANTS_KEY_DIAGRAM_DISPLAY_FLAG_NAMES,
284 : D_FLAG_NAME,
285 : D_FLAG_VALUES
286 : );
287 : static const char *const D_FLAGS = "set of flags, see source file data/include/entity/data_diagram_flag.h";
288 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_DIAGRAM_DISPLAY_FLAGS, D_FLAGS );
289 0 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_UUID, ANY_UUID, true /*elements follow*/ );
290 :
291 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_DIAGRAM_ELEMENTS_HEADER );
292 :
293 0 : (*this_).indent = 10;
294 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_DIAGRAMELEMENT_ID, ANY_ID );
295 : static const char *const E_NODE_C_NAME
296 : = "name of " JSON_CONSTANTS_KEY_DIAGRAMELEMENT_NODE "/classifier, exported for reviews by humans, ignored at import";
297 : #ifdef JSON_CONSTANTS_NEW_KEYS
298 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_DIAGRAMELEMENT_NODE_NAME, E_NODE_C_NAME );
299 : #else
300 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_DIAGRAMELEMENT_CLASSIFIER_NAME, E_NODE_C_NAME );
301 : static const char *const E_NODE_F_NAME
302 : = "name of " JSON_CONSTANTS_KEY_DIAGRAMELEMENT_NODE "/feature (if lifeline), optional, exported for reviews by humans, ignored at import";
303 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_DIAGRAMELEMENT_FOCUSED_FEATURE_NAME, E_NODE_F_NAME );
304 : #endif
305 : static const char *const E_NODE = "the uuid of either the classifier or the feature (type lifeline only)";
306 0 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_DIAGRAMELEMENT_NODE, E_NODE, true );
307 : /* generate an enum listing all options */
308 : static const char *const E_FLAG_NAME
309 : = JSON_CONSTANTS_KEY_DIAGRAMELEMENT_DISPLAY_FLAGS " as string, exported for reviews by humans, ignored at import";
310 0 : const char *const * E_FLAG_VALUES = json_type_name_map_get_diagramelement_tags_list( &((*this_).enum_map) );
311 0 : export_err |= json_schema_writer_private_declare_enum( this_,
312 : JSON_CONSTANTS_KEY_DIAGRAMELEMENT_DISPLAY_FLAG_NAMES,
313 : E_FLAG_NAME,
314 : E_FLAG_VALUES
315 : );
316 : static const char *const E_FLAGS = "set of flags, see source file data/include/entity/data_diagramelement_flag.h";
317 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_DIAGRAMELEMENT_DISPLAY_FLAGS, E_FLAGS );
318 0 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_UUID, ANY_UUID, false );
319 :
320 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_DIAGRAM_ELEMENTS_FOOTER );
321 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_DIAGRAM_FOOTER );
322 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_GRAPH_NODES );
323 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_CLASSIFIER_HEADER );
324 :
325 0 : (*this_).indent = 7;
326 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_CLASSIFIER_ID, ANY_ID );
327 : /* generate an enum listing all options */
328 : static const char *const C_TYPE_NAME
329 : #ifdef JSON_CONSTANTS_NEW_KEYS
330 : = "name of " JSON_CONSTANTS_KEY_TYPE_ID ", exported for reviews by humans, ignored at import";
331 : #else
332 : = "name of " JSON_CONSTANTS_KEY_CLASSIFIER_MAIN_TYPE ", exported for reviews by humans, ignored at import";
333 : #endif
334 0 : const char *const * C_TYPE_VALUES = json_type_name_map_get_classifier_types_list( &((*this_).enum_map) );
335 0 : export_err |= json_schema_writer_private_declare_enum( this_,
336 : JSON_CONSTANTS_KEY_TYPE_NAME,
337 : C_TYPE_NAME,
338 : C_TYPE_VALUES
339 : );
340 : static const char *const C_TYPE_ID = "id of classifier type, see source file data/include/entity/data_classifier_type.h";
341 : #ifdef JSON_CONSTANTS_NEW_KEYS
342 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_TYPE_ID, C_TYPE_ID );
343 : #else
344 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_CLASSIFIER_MAIN_TYPE, C_TYPE_ID );
345 : #endif
346 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_CLASSIFIER_STEREOTYPE, "" );
347 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_CLASSIFIER_NAME, "" );
348 0 : export_err |= json_schema_writer_private_declare_array_of_string( this_, JSON_CONSTANTS_KEY_CLASSIFIER_DESCRIPTION, "", ANY_DESCR );
349 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_CLASSIFIER_X_ORDER, ANY_ORDER );
350 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_CLASSIFIER_Y_ORDER, ANY_ORDER );
351 : #ifdef JSON_CONSTANTS_NEW_KEYS
352 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_ORDER, ANY_ORDER );
353 : #else
354 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_CLASSIFIER_LIST_ORDER, ANY_ORDER );
355 : #endif
356 0 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_UUID, ANY_UUID, true /*features follow*/ );
357 :
358 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_FEATURES_HEADER );
359 :
360 0 : (*this_).indent = 10;
361 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_FEATURE_ID, ANY_ID );
362 : /* generate an enum listing all options */
363 : static const char *const F_TYPE_NAME
364 : #ifdef JSON_CONSTANTS_NEW_KEYS
365 : = "name of " JSON_CONSTANTS_KEY_TYPE_ID ", exported for reviews by humans, ignored at import";
366 : #else
367 : = "name of " JSON_CONSTANTS_KEY_FEATURE_MAIN_TYPE ", exported for reviews by humans, ignored at import";
368 : #endif
369 0 : const char *const * F_TYPE_VALUES = json_type_name_map_get_feature_types_list( &((*this_).enum_map) );
370 0 : export_err |= json_schema_writer_private_declare_enum( this_,
371 : JSON_CONSTANTS_KEY_TYPE_NAME,
372 : F_TYPE_NAME,
373 : F_TYPE_VALUES
374 : );
375 : static const char *const F_TYPE_ID = "id of feature type, see source file data/include/entity/data_feature_type.h";
376 : #ifdef JSON_CONSTANTS_NEW_KEYS
377 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_TYPE_ID, F_TYPE_ID );
378 : #else
379 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_FEATURE_MAIN_TYPE, F_TYPE_ID );
380 : #endif
381 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_FEATURE_KEY, "name" );
382 : static const char *const F_VALUE = "valuetype in case of properties, value in case of tagges values, stereotype otherwise";
383 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_FEATURE_VALUE, F_VALUE );
384 0 : export_err |= json_schema_writer_private_declare_array_of_string( this_, JSON_CONSTANTS_KEY_FEATURE_DESCRIPTION, "", ANY_DESCR );
385 : #ifdef JSON_CONSTANTS_NEW_KEYS
386 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_ORDER, ANY_ORDER );
387 : #else
388 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_FEATURE_LIST_ORDER, ANY_ORDER );
389 : #endif
390 0 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_UUID, ANY_UUID, false );
391 :
392 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_FEATURES_FOOTER );
393 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_CLASSIFIER_FOOTER );
394 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_GRAPH_EDGES );
395 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_RELATIONSHIP_HEADER );
396 :
397 0 : (*this_).indent = 7;
398 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_ID, ANY_ID );
399 : /* generate an enum listing all options */
400 : static const char *const R_TYPE_NAME
401 : #ifdef JSON_CONSTANTS_NEW_KEYS
402 : = "name of " JSON_CONSTANTS_KEY_TYPE_ID ", exported for reviews by humans, ignored at import";
403 : #else
404 : = "name of " JSON_CONSTANTS_KEY_RELATIONSHIP_MAIN_TYPE ", exported for reviews by humans, ignored at import";
405 : #endif
406 0 : const char *const * R_TYPE_VALUES = json_type_name_map_get_relationship_types_list( &((*this_).enum_map) );
407 0 : export_err |= json_schema_writer_private_declare_enum( this_,
408 : JSON_CONSTANTS_KEY_TYPE_NAME,
409 : R_TYPE_NAME,
410 : R_TYPE_VALUES
411 : );
412 : static const char *const R_TYPE_ID = "id of relationship type, see source file data/include/entity/data_relationship_type.h";
413 : #ifdef JSON_CONSTANTS_NEW_KEYS
414 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_TYPE_ID, R_TYPE_ID );
415 : #else
416 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_MAIN_TYPE, R_TYPE_ID );
417 : #endif
418 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_STEREOTYPE, ANY_STEREO );
419 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_NAME, "" );
420 0 : export_err |= json_schema_writer_private_declare_array_of_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_DESCRIPTION, "", ANY_DESCR );
421 : #ifdef JSON_CONSTANTS_NEW_KEYS
422 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_ORDER, ANY_ORDER );
423 : #else
424 0 : export_err |= json_schema_writer_private_declare_integer( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_LIST_ORDER, ANY_ORDER );
425 : #endif
426 : #ifdef JSON_CONSTANTS_NEW_KEYS
427 : static const char *const E_FROM_NODE_C_NAME
428 : = "name of " JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_NODE_UUID "/classifier, exported for reviews by humans, ignored at import";
429 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_NODE_NAME, E_FROM_NODE_C_NAME );
430 : #else
431 : static const char *const E_FROM_NODE_C_NAME
432 : = "name of " JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_NODE "/classifier, exported for reviews by humans, ignored at import";
433 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_CLASSIFIER_NAME, E_FROM_NODE_C_NAME );
434 : #endif
435 : #ifdef JSON_CONSTANTS_NEW_KEYS
436 : static const char *const E_FROM_NODE_F_NAME
437 : = "key of " JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_NODE_UUID "/feature if applicable, exported for reviews by humans, ignored at import";
438 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_PORT_NAME, E_FROM_NODE_F_NAME );
439 : #else
440 : static const char *const E_FROM_NODE_F_NAME
441 : = "key of " JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_NODE "/feature if applicable, exported for reviews by humans, ignored at import";
442 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_FEATURE_KEY, E_FROM_NODE_F_NAME );
443 : #endif
444 : static const char *const E_FROM_NODE = "the uuid of the source: either the classifier or the feature";
445 : #ifdef JSON_CONSTANTS_NEW_KEYS
446 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_NODE_UUID, E_FROM_NODE, true );
447 : #else
448 0 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_FROM_NODE, E_FROM_NODE, true );
449 : #endif
450 : #ifdef JSON_CONSTANTS_NEW_KEYS
451 : static const char *const E_TO_NODE_C_NAME
452 : = "name of " JSON_CONSTANTS_KEY_RELATIONSHIP_TO_NODE_UUID "/classifier, exported for reviews by humans, ignored at import";
453 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_TO_NODE_NAME, E_TO_NODE_C_NAME );
454 : #else
455 : static const char *const E_TO_NODE_C_NAME
456 : = "name of " JSON_CONSTANTS_KEY_RELATIONSHIP_TO_NODE "/classifier, exported for reviews by humans, ignored at import";
457 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_TO_CLASSIFIER_NAME, E_TO_NODE_C_NAME );
458 : #endif
459 : #ifdef JSON_CONSTANTS_NEW_KEYS
460 : static const char *const E_TO_NODE_F_NAME
461 : = "key of " JSON_CONSTANTS_KEY_RELATIONSHIP_TO_NODE_UUID "/feature if applicable, exported for reviews by humans, ignored at import";
462 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_TO_PORT_NAME, E_TO_NODE_F_NAME );
463 : #else
464 : static const char *const E_TO_NODE_F_NAME
465 : = "key of " JSON_CONSTANTS_KEY_RELATIONSHIP_TO_NODE "/feature if applicable, exported for reviews by humans, ignored at import";
466 0 : export_err |= json_schema_writer_private_declare_string( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_TO_FEATURE_KEY, E_TO_NODE_F_NAME );
467 : #endif
468 : static const char *const E_TO_NODE = "the uuid of the destination: either the classifier or the feature";
469 : #ifdef JSON_CONSTANTS_NEW_KEYS
470 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_TO_NODE_UUID, E_TO_NODE, true );
471 : #else
472 0 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_RELATIONSHIP_TO_NODE, E_TO_NODE, true );
473 : #endif
474 0 : export_err |= json_schema_writer_private_declare_uuid( this_, JSON_CONSTANTS_KEY_UUID, ANY_UUID, false );
475 :
476 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_RELATIONSHIP_FOOTER );
477 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), SCHEMA_GRAPH_FOOTER );
478 :
479 0 : export_err |= utf8stream_writer_flush( &((*this_).writer) );
480 :
481 0 : U8_TRACE_END_ERR( export_err );
482 0 : return export_err;
483 : }
484 :
485 0 : u8_error_t json_schema_writer_private_declare_integer( json_schema_writer_t *this_,
486 : const char* name,
487 : const char* description )
488 : {
489 0 : U8_TRACE_BEGIN();
490 0 : assert( name != NULL );
491 0 : assert( description != NULL );
492 0 : u8_error_t export_err = U8_ERROR_NONE;
493 0 : const char *const indent = ((*this_).indent==10) ? INDENT_10 : INDENT_7;
494 :
495 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
496 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\"" );
497 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), name );
498 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\":\n" );
499 :
500 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
501 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "{\n" );
502 :
503 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
504 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"description\": \"" );
505 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), description );
506 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\",\n" );
507 :
508 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
509 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"type\": \"number\"\n" );
510 :
511 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
512 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "},\n" );
513 :
514 0 : U8_TRACE_END_ERR( export_err );
515 0 : return export_err;
516 : }
517 :
518 0 : u8_error_t json_schema_writer_private_declare_string( json_schema_writer_t *this_,
519 : const char* name,
520 : const char* description )
521 : {
522 0 : U8_TRACE_BEGIN();
523 0 : assert( name != NULL );
524 0 : assert( description != NULL );
525 0 : u8_error_t export_err = U8_ERROR_NONE;
526 0 : const char *const indent = ((*this_).indent==10) ? INDENT_10 : INDENT_7;
527 :
528 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
529 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\"" );
530 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), name );
531 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\":\n" );
532 :
533 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
534 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "{\n" );
535 :
536 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
537 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"description\": \"" );
538 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), description );
539 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\",\n" );
540 :
541 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
542 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"type\": \"string\"\n" );
543 :
544 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
545 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "},\n" );
546 :
547 0 : U8_TRACE_END_ERR( export_err );
548 0 : return export_err;
549 : }
550 :
551 0 : u8_error_t json_schema_writer_private_declare_array_of_string( json_schema_writer_t *this_,
552 : const char* name,
553 : const char* description,
554 : const char* element_description )
555 : {
556 0 : U8_TRACE_BEGIN();
557 0 : assert( name != NULL );
558 0 : assert( description != NULL );
559 0 : assert( element_description != NULL );
560 0 : u8_error_t export_err = U8_ERROR_NONE;
561 0 : const char *const indent = ((*this_).indent==10) ? INDENT_10 : INDENT_7;
562 :
563 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
564 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\"" );
565 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), name );
566 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\":\n" );
567 :
568 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
569 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "{\n" );
570 :
571 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
572 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"description\": \"" );
573 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), description );
574 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\",\n" );
575 :
576 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
577 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"type\": \"array\",\n" );
578 :
579 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
580 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"items\":\n" );
581 :
582 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
583 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " {\n" );
584 :
585 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
586 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"description\": \"" );
587 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), element_description );
588 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\",\n" );
589 :
590 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
591 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"type\": \"string\"\n" );
592 :
593 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
594 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " }\n" );
595 :
596 :
597 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
598 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "},\n");
599 :
600 0 : U8_TRACE_END_ERR( export_err );
601 0 : return export_err;
602 : }
603 :
604 0 : u8_error_t json_schema_writer_private_declare_enum( json_schema_writer_t *this_,
605 : const char* name,
606 : const char* description,
607 : const char *const * value_list )
608 : {
609 0 : U8_TRACE_BEGIN();
610 0 : assert( name != NULL );
611 0 : assert( description != NULL );
612 0 : assert( value_list != NULL );
613 0 : u8_error_t export_err = U8_ERROR_NONE;
614 0 : const char *const indent = ((*this_).indent==10) ? INDENT_10 : INDENT_7;
615 :
616 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
617 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\"" );
618 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), name );
619 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\":\n" );
620 :
621 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
622 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "{\n" );
623 :
624 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
625 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"description\": \"" );
626 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), description );
627 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\",\n" );
628 :
629 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
630 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"enum\":\n" );
631 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
632 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " [\n" );
633 :
634 0 : unsigned int index = 0;
635 0 : while ( value_list[index] != NULL )
636 : {
637 0 : const bool has_next = ( value_list[ index + 1 ] != NULL );
638 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
639 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"" );
640 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), value_list[index] );
641 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), has_next ? "\",\n": "\"\n" );
642 :
643 0 : index ++;
644 : }
645 :
646 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
647 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " ]\n" );
648 :
649 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
650 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "},\n" );
651 :
652 0 : U8_TRACE_END_ERR( export_err );
653 0 : return export_err;
654 : }
655 :
656 0 : u8_error_t json_schema_writer_private_declare_uuid( json_schema_writer_t *this_,
657 : const char* name,
658 : const char* description,
659 : bool has_next )
660 : {
661 0 : U8_TRACE_BEGIN();
662 0 : assert( name != NULL );
663 0 : assert( description != NULL );
664 0 : u8_error_t export_err = U8_ERROR_NONE;
665 0 : const char *const indent = ((*this_).indent==10) ? INDENT_10 : INDENT_7;
666 :
667 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
668 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\"" );
669 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), name );
670 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\":\n" );
671 :
672 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
673 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "{\n" );
674 :
675 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
676 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"description\": \"" );
677 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), description );
678 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), "\",\n" );
679 :
680 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
681 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), " \"type\": \"string\"\n" );
682 :
683 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), indent );
684 0 : export_err |= utf8stream_writer_write_str( &((*this_).writer), has_next ? "},\n" : "}\n" );
685 :
686 0 : U8_TRACE_END_ERR( export_err );
687 0 : return export_err;
688 : }
689 :
690 :
691 : /*
692 : Copyright 2023-2026 Andreas Warnke
693 :
694 : Licensed under the Apache License, Version 2.0 (the "License");
695 : you may not use this file except in compliance with the License.
696 : You may obtain a copy of the License at
697 :
698 : http://www.apache.org/licenses/LICENSE-2.0
699 :
700 : Unless required by applicable law or agreed to in writing, software
701 : distributed under the License is distributed on an "AS IS" BASIS,
702 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
703 : See the License for the specific language governing permissions and
704 : limitations under the License.
705 : */
|