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