Qore Swagger Module Reference 2.1
Loading...
Searching...
No Matches
Swagger.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* Swagger.qm Copyright (C) 2017 - 2023 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25
26// make sure we have the required qore version
27
28// try importing JSON and YAML modules
29
30
31
32
33
229namespace Swagger {
231const ValidIntFormats = ("int32", "int64");
233const ValidNumberFormats = ("double", "float");
235const ValidStringFormats = ("binary", "byte", "date", "date-time", "password");
236
239
240
243
244
246const ValidIntFormatsHash = map {$1: True}, ValidIntFormats;
251
254 "serialize": \make_yaml(),
255 "serialize_verbose": string sub (auto val) {return make_yaml(val, BlockStyle);},
256 "deserialize": \parse_yaml(),
257 "module": "yaml",
258};
259
262%ifndef NoJson
263 MimeTypeJson: (
264 "serialize": \make_json(),
265 "serialize_verbose": string sub (auto val) {return make_json(val, JGF_ADD_FORMATTING);},
266 "deserialize": \parse_json(),
267 "module": "json",
268 ),
269%endif
270%ifndef NoYaml
271 // issue #3699: more YAML MIME types must be supported
272 MimeTypeYaml: YamlSerialization,
273 MimeTypeYamlRpc: YamlSerialization,
274 "text/yaml": YamlSerialization,
275 "application/yaml": YamlSerialization,
276%endif
277%ifndef NoXml
278 MimeTypeXmlApp: (
279 "serialize": \make_xml(),
280 "serialize_verbose": string sub (auto val) {return make_xml(val, XGF_ADD_FORMATTING);},
281 "deserialize": \parse_xml(),
282 "module": "xml",
283 ),
284%endif
285 # Content-Type: application/x-www-form-urlencoded
286 MimeTypeFormUrlEncoded: (
287 "serialize": \mime_get_form_urlencoded_string(),
288 "serialize_verbose": \mime_get_form_urlencoded_string(),
289 "deserialize": \mime_parse_form_urlencoded_string(),
290 ),
291 # Content-Type: multipart/form-data (handled manually)
292 MimeTypeMultipartFormData: {},
293};
294
296const SerializationModules = keys (map {$1.module: True}, MimeDataTypes.iterator(), $1.module);
297
300
302const ValidSchemes = ("http", "https", "ws", "wss");
303const ValidSchemesHash = map {$1: True}, ValidSchemes;
304
307
308public:
310
315
318
319
321
324 constructor(hash<auto> oh);
325
326
329
330
332
335 initialize(hash<auto> oh);
336};
337
340
341public:
343 *float maximum;
344
346 *float minimum;
347
350
353
356
359
361 *string pattern;
362
365
368
371
373
376 hash<string, bool> enum;
377
380
382
385 constructor(string objType, hash<auto> oh);
386
387
390
391
393protected:
394 auto getExampleValue(string type, *string format);
395public:
396
397
399 private check(bool serialize, bool request, string type, *string format, *SchemaObject items, string path,
400 string method, string name, reference<auto> value) {
401 // accept a single value for an array (= one-element list)
402 if (type == 'array');
403 else {
404 checkIntern(serialize, request, type, format, path, method, name, value, \value);
405 }
406 }
407
408protected:
409 checkStringIntern(string path, string method, string name, string value);
410public:
411
412
413 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
414 string name, list<auto> v, reference<list> value) {
415 if (type != "list" && type != "any")
416 throw "SCHEMA-VALIDATION-ERROR", sprintf("Parameter %y for path %y and method %y is an array (%y), but "
417 "the expected type is %y", name, path, method, v, type);
418 }
419
420 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
421 string name, hash<auto> v, reference<hash> value) {
422 if (type != "file" && type != "any")
423 throw "SCHEMA-VALIDATION-ERROR", sprintf("Parameter %y for path %y and method %y is an object (%y), but "
424 "the expected type is %y", name, path, method, v, type);
425 }
426
427 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
428 string name, int v, reference<auto> value) {
429 // NOTE: "number" also accepts "int"
430 if (type == 'number');
431
432 if (type != "integer" && type != "any")
433 throwInvalidType(name, "integer", type, v);
434 if (exists maximum);
435
436
437 if (exists minimum);
438
439
440 if (enum && !enum{value})
441 throw "SCHEMA-VALIDATION-ERROR",
442 sprintf("Parameter %y for path %y and method %y does not fit the enumerated values (enum: %y, actual: %d)",
443 name, path, method, keys enum, value);
444 }
445
446protected:
447 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, number v, reference<number> value);
448public:
449
450
451protected:
452 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, float v, reference<number> value);
453public:
454
455
456protected:
457 checkInternNumber(bool serialize, bool request, string type, *string format, string path, string method, string name, auto v, reference<auto> value);
458public:
459
460
462 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
463 string name, binary v, reference value) {
464 if (type != "string" && type != "any")
465 throwInvalidType(name, "string", type, v);
466
467 if (serialize);
468
469 }
470
472 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
473 string name, string v, reference<auto> value) {
474 if (type != 'string' && type != 'any');
475
476
477 if (serialize);
478 # https://xml2rfc.tools.ietf.org//rfc/html/rfc3339.html#anchor14 if (value.typeCode() == NT_STRING);
479
480 }
481
483protected:
484 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, date v, reference value);
485public:
486
487
488protected:
489 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, bool v, reference<bool> value);
490public:
491
492
493protected:
494 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, nothing v, reference<nothing> value);
495public:
496
497
499 private checkArrayParam(bool serialize, bool request, SchemaObject items, string path, string method, string name,
500 reference<softlist<auto>> value) {
501 if (exists maxItems && value.size() > maxItems)
502 throw "SCHEMA-VALIDATION-ERROR",
503 sprintf("Parameter %y for path %y and method %y has too many items (maxItems: %d, actual: %d)",
504 name, path, method, maxItems, value.size());
505 if (exists minItems && value.size() < minItems)
506 throw "SCHEMA-VALIDATION-ERROR",
507 sprintf("Parameter %y for path %y and method %y has too few items (minItems: %d, actual: %d)",
508 name, path, method, minItems, value.size());
509
510 // check array element types
511 if (!uniqueItems || items.type != 'array');
512 else {
513 // perform slow array uniqueness check
514 list<auto> uniqueItems = ();
515 foreach auto val in (\value) {
516 items.check(serialize, request, path, method, name, \val);
517 if (uniqueItems.contains(val))
518 throw "SCHEMA-VALIDATION-ERROR",
519 sprintf("%s %s: Array parameter %y does not have unique items",
520 method, path, name);
521 uniqueItems += val;
522 }
523 }
524 }
525
527protected:
528 static throwInvalidType(string name, string actual, string expected, auto value);
529public:
530
531
533
535 static bool checkValueType(reference<auto> value, string type);
536};
537
540
541public:
543
551 static SwaggerSchema fromString(string swaggerSpecification, *bool json);
552
554
562 static SwaggerSchema fromFile(string filepath);
563
565
576 static SwaggerSchema fromUrl(string url, *bool json);
577
579
588 static hash<auto> parseSchemaContent(string filepath, string str);
589
591 static hash<auto> parseSchemaSource(string str, string ser);
592
594 static string detectSourceEncoding(string str);
595};
596
598class SwaggerSchema : public ObjectBase,public AbstractRestSchemaValidator {
599
600public:
602
607
610
613
615
621 *string host;
622
624
629 *string basePath;
630
632
637 hash<string, bool> schemes;
638
640
644 hash<string, bool> consumes;
645
647
651 hash<string, bool> produces;
652
654
657 hash<string, SchemaObject> definitions();
658
660
663 hash<string, AbstractParameterObject> parameters();
664
666
669 hash<string, ResponseObject> responses;
670
672
675 hash<string, SecuritySchemeObject> securityDefinitions;
676
678
689 hash<string, softlist<string>> security;
690
692
701 list<TagObject> tags;
702
705
707 const SwaggerOptions = ...;
708
709
710protected:
713
715 *string def_path;
716
718
721
723 string hash_str;
724
726 hash<string, hash<string, SchemaObject>> so_map;
727
728public:
729
730private:
733
734public:
735
737
753 constructor(string schema_source, hash<auto> oh, *hash<auto> opts) ;
754
755
757
773 constructor(Logger logger, string schema_source, hash<auto> oh, *hash<auto> opts) : ObjectBase(oh),
774 AbstractRestSchemaValidator(logger);
775
776
778protected:
779 constructorIntern(string schema_source, hash<auto> oh, *hash<auto> opts);
780public:
781
782
783 *SchemaObject tryGetSchemaObject(string name, hash<auto> oh, reference<string> hash_str);
784
785
786 cacheSchemaObject(string name, string hash_str, SchemaObject so);
787
788
790
792 SchemaObject resolveSchemaObject(string name, string refstr, hash<auto> oh);
793
794
796
798 ParameterItemsSchemaObject resolveParameterItemsSchemaObject(string name, string refstr, hash<auto> oh);
799
800
802
804 AbstractParameterObject resolveParameter(string name, string refstr, hash<auto> oh);
805
806
808
810 ResponseObject resolveResponse(string name, string refstr, hash<auto> oh);
811
812
814
818protected:
819 string getHashImpl();
820public:
821
822
824
828protected:
830public:
831
832
834
847 private hash<RestSchemaValidator::RestRequestClientInfo> processRequestImpl(string method, string path, auto body,
848 *hash<auto> headers, *softlist<string> content_types) {
849 return processRequestIntern(method, path, body, headers, content_types, compact_serialization);
850 }
851
853
864 private hash<RestSchemaValidator::RestRequestServerInfo> parseRequestImpl(string method, string path,
865 *data http_body, reference<hash> headers) {
866 auto body;
867 // deserialize body according to Content-Type
868 if (exists http_body);
869
870
871 // path must be absolute for matching to work correctly
872 if (path ==1)
873 path = "/" + path;
874
875 // remove basePath if present; note that "basePath" must always have a leading /
876 fixPath(\path);
877
878 hash<UriQueryInfo> h = parse_uri_query(path);
879 method = method.lwr();
880 PathItemObject pio = paths.match(h.method);
881 OperationObject op = pio.getOperation(method, h.method);
882
883 op.parseRequest(pio, \h, \body, \headers);
884 return <RestRequestServerInfo>{
885 "path": h.method,
886 "query": h.params,
887 "path_args": h.path_params,
888 "body": body,
889 };
890 }
891
893
912 private hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, auto response_body,
913 *hash<auto> headers, *softlist<string> content_types) {
914 return processResponseIntern(method, path, code, response_body, headers, content_types,
916 }
917
919
929 private hash<RestSchemaValidator::RestResponseClientInfo> parseResponseImpl(string method, string path, int code,
930 *data response_body, hash<auto> hdr) {
931 // remove basePath if present
932 fixPath(\path);
933
934 method = method.lwr();
935 PathItemObject pio = paths.match(path);
936 OperationObject op = pio.getOperation(method, path);
937
938 hash<RestResponseClientInfo> rv((
939 "code": code,
940 "hdr": hdr,
941 ));
942
943 *string content = hdr."content-type" ?? hdr."Content-Type";
944
945 // deserialize body according to Content-Type
946 if (exists response_body && content);
947
948
949 hash<string, bool> mime_types;
950 op.validateResponse(method, path, pio, code, \rv.body, \mime_types, False);
951
952 if (content && !mime_types{content})
953 throw "DESERIALIZATION-ERROR", sprintf("%s %s: content type %y is not accepted by this operation; "
954 "accepted content types: %y", method.upr(), path, content, keys mime_types);
955
956 return rv;
957 }
958
960protected:
961 fixPath(reference<string> path);
962public:
963
964
966
968protected:
969 hash<string, list<string>> getPathOperationHashImpl();
970public:
971
972
974
978protected:
980public:
981
982
984
986protected:
988public:
989
990
992
997protected:
998 hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
999public:
1000
1001
1003
1009 private hash<RestSchemaValidator::RestExampleRequestInfo> getExampleRequestImpl(string method, string path,
1010 *softlist<string> content_types) {
1011 // remove basePath if present
1012 fixPath(\path);
1013
1014 method = method.lwr();
1015 PathItemObject pio = paths.match(path);
1016 OperationObject op = pio.getOperation(method, path);
1017
1018 auto body;
1019 hash<RestExampleRequestInfo> rv = op.getExampleRequest(method, path, pio, self, \body);
1020 if (exists body);
1021
1022
1023 return rv;
1024 }
1025
1027
1033protected:
1034 hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
1035public:
1036
1037
1039
1046 private hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code,
1047 *softlist<string> content_types) {
1048 // remove basePath if present
1049 fixPath(\path);
1050
1051 method = method.lwr();
1052 PathItemObject pio = paths.match(path);
1053 OperationObject op = pio.getOperation(method, path);
1054
1055 auto body;
1056 hash<RestExampleResponseInfo> rv = op.getExampleResponse(method, path, code, \body);
1057 if (exists body);
1058
1059
1060 return rv;
1061 }
1062
1064
1066protected:
1067 hash<auto> getExternalReference(string refstr);
1068public:
1069
1070
1072
1076protected:
1077 AbstractDataProvider getDataProviderImpl(HTTPClient rest);
1078public:
1079
1080
1082
1086protected:
1088public:
1089
1090
1092
1096protected:
1098public:
1099
1100
1102
1116 private:internal hash<RestSchemaValidator::RestRequestClientInfo> processRequestIntern(string method, string path,
1117 auto body, *hash<auto> headers, *softlist<string> content_types, bool compact_serialization) {
1118 // remove basePath if present
1119 fixPath(\path);
1120
1121 hash<UriQueryInfo> h = parse_uri_query(path);
1122
1123 // find path item object and operation
1124 method = method.lwr();
1125 PathItemObject pio = paths.match(h.method);
1126 OperationObject op = pio.getOperation(method, h.method);
1127
1128 // perform validation
1129 hash<string, bool> mime_types;
1130 op.validateRequest(True, pio, \h, \body, \headers, \mime_types);
1131
1132 hash<RestRequestClientInfo> rv((
1133 "uri_path": h.method,
1134 ));
1135
1136 if (op.produces);
1137
1138
1139 // add the basePath to the request
1140 if (exists basePath);
1141
1142
1143 // rebuild URI query after processing
1144 if (h.params);
1145
1146
1147 if (!body);
1148
1149
1150 if (!exists content_types);
1151
1152
1153 foreach string content in (content_types);
1154
1155
1156 // check if the \c Content-Type header is already set
1157 if (checkRequestContentTypeHeader(\rv, body, headers));
1158
1159
1160 if (content_types == MimeContentTypes);
1161 else {
1162 throw "SERIALIZATION-ERROR", sprintf("%s %s: message body cannot be serialized; requested MIME type(s): "
1163 "%y; available MIME types: %y; available serialization modules: %y", method.upr(), path,
1164 content_types, mime_types, SerializationModules);
1165 }
1166 }
1167
1169
1189 private:internal hash<HttpResponseInfo> processResponseIntern(string method, string path, int code,
1190 auto response_body, *hash<auto> headers, *softlist<string> content_types, bool compact_serialization) {
1191 // find path item object and operation
1192 method = method.lwr();
1193 PathItemObject pio = paths.match(path);
1194 OperationObject op = pio.getOperation(method, path);
1195
1196 // perform validation
1197 hash<string, bool> mime_types;
1198 op.validateResponse(method, path, pio, code, \response_body, \mime_types);
1199
1200 hash<HttpResponseInfo> rv((
1201 "code": code,
1202 "hdr": headers,
1203 ));
1204
1205 if (exists response_body);
1206
1207
1208 return rv;
1209 }
1210
1212
1220 private:internal bool checkRequestContentTypeHeader(reference<hash<RestRequestClientInfo>> req, auto body,
1221 *hash<auto> headers) {
1222 // quickly return if body is not in data format
1223 if (body.typeCode() != NT_BINARY && body.typeCode() != NT_STRING)
1224 return False;
1225
1226 // try to find \c Content-Type header
1227 *list<string> ct = map $1, keys headers, $1 ==1i;
1228
1229 // if found and it's not one of the default ones, use it
1230 if (ct && ct.size() == 1 && !MimeDataTypes{headers{ct[0]}});
1231
1232 return False;
1233 }
1234
1236
1244 private:internal bool checkResponseContentTypeHeader(reference<hash<HttpResponseInfo>> resp, auto body,
1245 *hash<auto> headers) {
1246 // quickly return if body is not in data format
1247 if (body.typeCode() != NT_BINARY && body.typeCode() != NT_STRING)
1248 return False;
1249
1250 // try to find \c Content-Type header
1251 *list<string> ct = map $1, keys headers, $1 ==1i;
1252
1253 // if found, use it and don't serialize the body
1254 if (ct && ct.size() == 1);
1255
1256 return False;
1257 }
1258
1260
1267 private:internal bool checkResponseTextPlain(reference<hash<HttpResponseInfo>> resp, auto body,
1268 hash<string, bool> mime_types, *list<auto> content_types) {
1269 // quickly return if body is not string
1270 if (body.typeCode() != NT_STRING)
1271 return False;
1272
1273 // return if text/plain is not allowed for this operation
1274 if (!mime_types."text/plain")
1275 return False;
1276
1277 if (content_types);
1278
1279
1280 resp.body = body;
1281 resp.hdr."Content-Type" = "text/plain";
1282 return True;
1283 }
1284
1286private:
1287 SchemaObject processDefinition(string key, auto value);
1288public:
1289
1290};
1291
1293class InfoObject : public ObjectBase {
1294
1295public:
1297 string title;
1298
1300 *string desc;
1301
1304
1306 string version;
1307
1310
1313
1315
1321 constructor(hash<auto> oh) ;
1322
1323};
1324
1327
1328public:
1330 *string name;
1331
1333 *string url;
1334
1336 *string email;
1337
1339
1344 constructor(hash<auto> oh) ;
1345
1346};
1347
1350
1351public:
1353 string name;
1354
1356 *string url;
1357
1359
1365 constructor(hash<auto> oh) ;
1366
1367};
1368
1370
1377
1378public:
1379protected:
1381 string pfx;
1382
1384 string name;
1385
1388
1391
1393 hash<string, PathComponent> paths;
1394
1395public:
1396
1398 constructor(hash<auto> oh, string pfx, SwaggerSchema swagger);
1399
1400
1402protected:
1403 constructor(string full_path, list<auto> l, int offset, hash<auto> oh);
1404public:
1405
1406
1408protected:
1409 add(string full_path, list<auto> l, int offset, hash<auto> oh, SwaggerSchema swagger);
1410public:
1411
1412
1414
1416 PathItemObject match(list<auto> path);
1417
1418
1420
1422 *PathItemObject tryMatch(list<auto> path);
1423
1424
1426
1428 getPathOperationHash(reference<hash<string, list<string>>> h);
1429
1430};
1431
1433class PathsObject : public ObjectBase {
1434
1435public:
1436protected:
1439
1440public:
1441
1443
1451 constructor(hash<auto> oh, SwaggerSchema swagger) ;
1452
1453
1455
1457 PathItemObject match(string path);
1458
1459
1461
1464
1465
1467
1469 hash<string, list<string>> getPathOperationHash();
1470
1471};
1472
1474
1480
1481public:
1483
1488 *string ref;
1489
1491
1500 hash<string, AbstractParameterObject> parameters();
1501
1504
1505protected:
1507
1517 hash<string, OperationObject> operations;
1518
1519public:
1520
1522
1531 constructor(string path, hash<auto> oh, SwaggerSchema swagger) ;
1532
1533
1535
1542 OperationObject getOperation(string method, string path);
1543
1544
1546
1548 softlist getMethods();
1549
1550};
1551
1554
1555public:
1557 string path;
1558
1560 string method;
1561
1563
1566 list tags;
1567
1569 *string summary;
1570
1572 *string desc;
1573
1575
1579 bool deprec = False;
1580
1583
1585
1592
1594
1599 hash<string, bool> consumes;
1600
1602
1607 hash<string, bool> produces;
1608
1610
1618 hash<string, AbstractParameterObject> parameters();
1619
1622
1624 hash<string, AbstractParameterObject> formData;
1625
1628
1630
1634 list<string> schemes;
1635
1637
1649 list<hash<string, list<string>>> security;
1650
1652
1661 constructor(string path, string method, hash<auto> oh, SwaggerSchema swagger) ;
1662
1663
1665 *data getRequestBody(PathItemObject pio, auto body, reference<hash<auto>> headers);
1666
1667
1669
1679 validateRequest(bool serialize, PathItemObject pio, reference<hash<UriQueryInfo>> h, reference<auto> body,
1680 reference<hash> headers, *reference<hash<string, bool>> mime_types) {
1681 // check query parameters
1682 foreach string key in (keys h.params);
1683
1684
1685 // check header parameters
1686 foreach string key in (keys headers);
1687
1688
1689 // check body parameters
1690 {
1691 *AbstractParameterObject body_po = self.body ?? pio.body;
1692 if (body_po) {
1693 body_po.check(serialize, True, path, method, "body", \body);
1694 } else if (formData) {
1695 foreach hash<auto> i in (formData.pairIterator()) {
1696 i.value.check(serialize, True, path, method, "formData." + i.key, \body{i.key});
1697 }
1698 } else if (body) {
1699 error("SCHEMA-VALIDATION-ERROR", "No message body is accepted; body keys passed: %y", keys body);
1700 }
1701 }
1702
1703 // check path parameters
1704 foreach string param in (path =~ x/{([^}]+)}/g);
1705
1706
1707 // check for missing required parameters
1708 checkMissingParams(h, headers, body, parameters);
1709 checkMissingParams(h, headers, body, pio.parameters, parameters);
1710
1711 if (consumes);
1712
1713 };
1714
1716
1726 parseRequest(PathItemObject pio, reference<hash<UriQueryInfo>> h, reference<auto> body, reference<hash> headers);
1727
1728
1730 validateResponse(string method, string path, PathItemObject pio, int http_code, reference<auto> response_body,
1731 reference<hash<string, bool>> mime_types, bool deserialize = True) {
1732 *ResponseObject res = getResponse(http_code);
1733 if (res.schema);
1734 else if (exists res && exists response_body);
1735
1736
1737 if (produces);
1738
1739 }
1740
1742
1749 hash<RestQoreExampleCodeInfo> getQoreExampleRequest(string method, string path, PathItemObject pio, SwaggerSchema swagger);
1750
1751
1753
1762 hash<RestSchemaValidator::RestExampleRequestInfo> getExampleRequest(string method, string path,
1763 PathItemObject pio, SwaggerSchema swagger, reference rbody) {
1764 hash<RestExampleRequestInfo> rv();
1765
1767 hash<auto> query;
1768
1769 getQoreExampleParams(\query, \rv.hdr, parameters);
1770 getQoreExampleParams(\query, \rv.hdr, pio.parameters, parameters);
1771
1772 rv.request_uri = sprintf("%s %s HTTP/1.1", method.upr(),
1773 make_uri_query(cast<hash<UriQueryInfo>>({"method": path, "params": query})));
1774
1776 *BodyParameter body_po = body ?? pio.body;
1777 if (body_po)
1778 rbody = body_po.getExampleValue();
1779
1780 return rv;
1781 }
1782
1784
1791 hash<RestQoreExampleCodeInfo> getQoreExampleResponse(string method, string path, int code);
1792
1793
1795
1803 hash<RestExampleResponseInfo> getExampleResponse(string method, string path, int code, reference<auto> body);
1804
1805
1806 private getQoreExampleParams(reference<hash<auto>> query, reference<hash<auto>> headers,
1807 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1808 foreach hash<auto> ph in (parameters.pairIterator());
1809
1810 }
1811
1813 private doDefaultParams(reference<hash<UriQueryInfo>> h, reference<hash> headers, reference<auto> body,
1814 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1815 foreach hash<auto> ph in (parameters.pairIterator());
1816
1817 }
1818
1820 private checkMissingParams(hash<UriQueryInfo> h, *hash<auto> headers, auto body,
1821 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1822 foreach hash<auto> ph in (parameters.pairIterator());
1823
1824 }
1825
1827
1829protected:
1831public:
1832
1833
1835protected:
1836 error(string err, string fmt);
1837public:
1838
1839}
1840
1842class ExternalDocumentationObject : public ObjectBase {
1843
1844public:
1846 *string desc;
1847
1849 string url;
1850
1852
1858 constructor(hash<auto> oh) ;
1859
1860};
1861
1863
1899class AbstractParameterObject : public ObjectBase {
1900
1901public:
1903
1910 string name;
1911
1913
1917 string inLoc;
1918
1920 *string desc;
1921
1923
1928 bool required = False;
1929
1930protected:
1931 const OtherParameterMap = ...;
1932
1933
1934public:
1935
1937
1944 constructor(hash<auto> oh) ;
1945
1946
1948 abstract check(bool serialize, bool request, string path, string method, string name, reference value);
1949
1952
1953
1955 static AbstractParameterObject newParameter(string name, hash<auto> oh, SwaggerSchema swagger);
1956};
1957
1960
1961public:
1964
1966
1973 constructor(hash<auto> oh, SwaggerSchema swagger) ;
1974
1975
1977 check(bool serialize, bool request, string path, string method, string name, reference value);
1978
1979
1981 string getQoreExample(reference<hash<RestQoreExampleCodeInfo>> rv);
1982
1983
1984 // returns an example value for a REST API call
1985 auto getExampleValue();
1986
1987};
1988
1990class OtherParameter : public AbstractParameterObject,public SchemaBase {
1991
1992public:
1994
2003 string type;
2004
2006 *string format;
2007
2009
2014 bool allowEmptyValue = False;
2015
2018
2020
2034
2036
2044
2046 const ParameterTypes = ...;
2047
2048
2050
2060 constructor(string name, hash<auto> oh, SwaggerSchema swagger)
2061 ;
2062
2063
2065 check(bool serialize, bool request, string path, string method, string name, reference<auto> value);
2066
2067
2070
2071
2074
2075
2077protected:
2078 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2079public:
2080
2081};
2082
2084class ResponsesObject : public ObjectBase {
2085
2086public:
2087 // The documentation of responses other than the ones declared for specific HTTP response codes.
2092
2093 // A hash mapping HTTP status codes to @ref ResponseObject "ResponseObjects".
2098 hash<string, ResponseObject> responses;
2099
2101
2111 constructor(string path, string method, hash<auto> oh, SwaggerSchema swagger) ;
2112
2113};
2114
2116class ResponseObject : public ObjectBase {
2117
2118public:
2120 string desc;
2121
2123
2130
2132
2135 hash<auto> headers;
2136
2138
2146
2148
2156protected:
2157 constructor(string key, hash<auto> oh, SwaggerSchema swagger) ;
2158public:
2159
2160
2162
2171 static ResponseObject newResponse(string key, hash<auto> oh, SwaggerSchema swagger);
2172};
2173
2175class HeaderObject : public ObjectBase,public SchemaBase {
2176
2177public:
2179 *string desc;
2180
2182
2186 string type;
2187
2189 *string format;
2190
2193
2195
2205
2207
2214
2216
2224 constructor(hash<auto> oh, SwaggerSchema swagger) ;
2225
2226
2228protected:
2229 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2230public:
2231
2232};
2233
2235class TagObject : public ObjectBase {
2236
2237public:
2239 string name;
2240
2242 *string desc;
2243
2246
2248
2254 constructor(hash<auto> oh) ;
2255
2256};
2257
2259class SchemaObject : public ObjectBase,public SchemaBase {
2260
2261public:
2263 string name;
2264
2266
2270 string type;
2271
2273 *string format;
2274
2276 *string title;
2277
2279 *string desc;
2280
2283
2286
2289
2292
2294
2296 bool nullable = False;
2297
2299
2303 hash<string, SchemaObject> properties;
2304
2306
2311
2313
2316 hash<string, bool> required;
2317
2319
2338
2340
2347 bool readOnly = False;
2348
2350
2358 list<SchemaObject> allOf();
2359
2361
2369
2372
2375
2377 const ScalarTypes = ...;
2378
2379
2381 const ReferenceTypes = ...;
2382
2383
2385
2396protected:
2397 constructor(string name, hash<auto> oh, SwaggerSchema swagger, *string hash_str)
2398public:
2399
2400
2402 string getQoreExample(reference<hash<RestQoreExampleCodeInfo>> rv, string name, bool decl);
2403
2404
2405 // returns an example value for a REST API call
2407
2408
2410 check(bool serialize, bool request, string path, string method, string name, reference<auto> value);
2411
2412
2413protected:
2414 checkObjectProperty(string name, string prop);
2415public:
2416
2417
2419 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
2420 string name, hash<auto> v, reference<hash<auto>> value) {
2421 if (type != "object" && type != "any")
2422 throwInvalidType(name, "object", type, v);
2423
2424 // check "allOf" schemas, if any
2425 map $1.checkIntern(serialize, request, type, NOTHING, path, method, name, v, \value), allOf;
2426
2427 /*
2428 If additionalProperties is set to true, any number of additionalProperties may be present of any data
2429 type.
2430 If additionalProperties is a schema, additional properties (beyond what are defined in ‘properties’) are
2431 allowed and must match the schema
2432 */
2433 // check properties in this schema definition
2434 if (!additionalProperties && type != 'any');
2435
2436 // check for missing required properties
2437 foreach string prop in (keys required);
2438
2439 //printf("SchemaObject::checkIntern() %y type: %y val: %y self: %N\n", name, type, value, self);
2440 }
2441
2443protected:
2444 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2445public:
2446
2447
2449
2460 static SchemaObject newSchemaObject(string name, hash<auto> oh, SwaggerSchema swagger);
2461
2463
2465 static SchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger);
2466};
2467
2470
2471public:
2473
2487
2489
2501protected:
2502 constructor(string name, hash<auto> oh, SwaggerSchema swagger) ;
2503public:
2504
2505
2507
2519 static ParameterItemsSchemaObject newSchemaObject(string name, hash<auto> oh, SwaggerSchema swagger);
2520
2522
2524 static ParameterItemsSchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger);
2525};
2526
2528
2533class XmlObject : public ObjectBase {
2534
2535public:
2537
2544 *string name;
2545
2547 *string ns;
2548
2550 *string prefix;
2551
2553 bool attribute = False;
2554
2556
2560 bool wrapped = False;
2561
2563
2568 constructor(hash<auto> oh) ;
2569
2570};
2571
2573
2578class SecuritySchemeObject : public ObjectBase {
2579
2580public:
2582 string type;
2583
2585 *string desc;
2586
2588
2591 *string name;
2592
2594
2597 *string inLoc;
2598
2600
2605 *string flow;
2606
2608
2612
2614
2617 *string tokenUrl;
2618
2620
2628
2630
2639 constructor(hash<auto> oh) ;
2640
2641};
2642
2644class ScopesObject : public ObjectBase {
2645
2646public:
2648
2651 hash<string, string> fields;
2652
2654
2659 constructor(hash<auto> oh) ;
2660
2661};
2662}
2663
2664// private namespace for internal definitions
2665namespace Priv {
2666 // a set of string values
2667 const SwaggerListToStringSet = -1;
2668 // a set of any type that can be converted to a string
2669 const SwaggerListToAnySet = -2;
2670 const SwaggerListToHashOfStrings = -3;
2671
2672 const TypeMap = ...;
2673
2674
2676
2686 required_field(string objType, hash<auto> oh, string name, int typeCode, reference<auto> target);
2687
2688
2690
2700 required_field(string objType, hash<auto> oh, string name, hash<string, bool> typeCodes, reference<auto> target);
2701
2702
2704
2715 bool optional_field(string objType, hash<auto> oh, string name, int typeCode, reference<auto> target);
2716
2717
2719
2730 bool optional_field(string objType, hash<auto> oh, string name, hash<string, bool> typeCodes,
2731 reference<auto> target) {
2732 if (!oh.hasKey(name))
2733 return False;
2734 auto val = oh{name};
2735 if (!typeCodes{val.typeCode()})
2736 throw "INVALID-FIELD-TYPE", sprintf("%s Object%s: %y field has invalid type %y", objType,
2737 oh.name ? sprintf(" %y", oh.name) : "", name, val.type());
2738 get_value(objType, name, val.typeCode(), val, \target);
2739 return True;
2740 }
2741
2743 check_type_code(string objType, hash<auto> oh, string name, auto val, int typeCode);
2744
2745
2747 get_value(string objType, string name, int typeCode, auto val, reference<auto> target);
2748
2749
2751 string get_qore_type(string name, string type, *string format, *SchemaObject items);
2752
2753}
Describes a single operation parameter.
Definition: Swagger.qm.dox.h:1899
constructor(hash< auto > oh)
Constructor.
static AbstractParameterObject newParameter(string name, hash< auto > oh, SwaggerSchema swagger)
gets a concrete instance of an AbstractParameterObject
abstract check(bool serialize, bool request, string path, string method, string name, reference value)
verifies the parameter in an actual REST API call
string name
Required. The name of the parameter. Parameter names are case sensitive.
Definition: Swagger.qm.dox.h:1910
auto getDefaultValue()
returns the default value of the parameter (default: NOTHING)
string inLoc
Required. The location of the parameter.
Definition: Swagger.qm.dox.h:1917
*string desc
A brief description of the parameter. This could contain examples of use. GFM syntax can be used for ...
Definition: Swagger.qm.dox.h:1920
bool required
Determines whether this parameter is mandatory.
Definition: Swagger.qm.dox.h:1928
AbstractParameterObject specialization for "body" parameters.
Definition: Swagger.qm.dox.h:1959
string getQoreExample(reference< hash< RestQoreExampleCodeInfo > > rv)
generates Qore example code for a REST API call
SchemaObject schema
Required. The schema defining the type used for the body parameter.
Definition: Swagger.qm.dox.h:1963
check(bool serialize, bool request, string path, string method, string name, reference value)
verifies the parameter in an actual REST API call
constructor(hash< auto > oh, SwaggerSchema swagger)
Constructor.
Allows referencing an external resource for extended documentation.
Definition: Swagger.qm.dox.h:1842
string url
Required. The URL for the target documentation. Value MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1849
*string desc
A short description of the target documentation. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1846
constructor(hash< auto > oh)
Constructor.
describes a single HTTP header
Definition: Swagger.qm.dox.h:2175
*string collectionFormat
Determines the format of the array if type array is used.
Definition: Swagger.qm.dox.h:2204
*SchemaObject items
Required if type is "array". Describes the type of items in the array.
Definition: Swagger.qm.dox.h:2192
static checkValueType(reference< auto > value, string type, *SchemaObject items, *string loc)
validates default values
auto defaultVal
Declares the value of the header that the server will use if none is provided.
Definition: Swagger.qm.dox.h:2213
*string format
The extending format for the previously mentioned type. See Data Type Formats for further details.
Definition: Swagger.qm.dox.h:2189
*string desc
A short description of the header.
Definition: Swagger.qm.dox.h:2179
string type
Required. The type of the object.
Definition: Swagger.qm.dox.h:2186
constructor(hash< auto > oh, SwaggerSchema swagger)
Constructor.
AbstractParameterObject specialization for parameters other than "body".
Definition: Swagger.qm.dox.h:1990
const ParameterTypes
valid parameter types
Definition: Swagger.qm.dox.h:2046
check(bool serialize, bool request, string path, string method, string name, reference< auto > value)
validates the value against the schema definition
*string collectionFormat
Determines the format of the array if type array is used.
Definition: Swagger.qm.dox.h:2033
auto getExampleValue()
returns an example value of the parameter (default: NOTHING)
static checkValueType(reference< auto > value, string type, *SchemaObject items, *string loc)
validates default values
*string format
The extending format for the previously mentioned type. See Data Type Formats for further details.
Definition: Swagger.qm.dox.h:2006
bool allowEmptyValue
Sets the ability to pass empty-valued parameters.
Definition: Swagger.qm.dox.h:2014
auto defaultVal
Declares the value of the parameter that the server will use if none is provided.
Definition: Swagger.qm.dox.h:2043
string type
Required. The type of the parameter.
Definition: Swagger.qm.dox.h:2003
auto getDefaultValue()
returns the default value of the parameter (default: NOTHING)
constructor(string name, hash< auto > oh, SwaggerSchema swagger)
Constructor.
*ParameterItemsSchemaObject items
Required if type is "array". Describes the type of items in the array.
Definition: Swagger.qm.dox.h:2017
items schema object for non-body parameters
Definition: Swagger.qm.dox.h:2469
static ParameterItemsSchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger)
throws an "INVALID-FIELD-TYPE" exception
*string collectionFormat
Determines the format of the array if type array is used.
Definition: Swagger.qm.dox.h:2486
constructor(string name, hash< auto > oh, SwaggerSchema swagger)
private constructor; use newSchemaObject() instead
static ParameterItemsSchemaObject newSchemaObject(string name, hash< auto > oh, SwaggerSchema swagger)
returns a SchemaObject for the schema definition; resolves references
Describes a single response from an API Operation.
Definition: Swagger.qm.dox.h:2116
hash< auto > headers
A hash of headers that are (can be) sent with the response.
Definition: Swagger.qm.dox.h:2135
constructor(string key, hash< auto > oh, SwaggerSchema swagger)
private constructor; use newResponse() instead
*SchemaObject schema
A definition of the response structure.
Definition: Swagger.qm.dox.h:2129
static ResponseObject newResponse(string key, hash< auto > oh, SwaggerSchema swagger)
returns a new ResponseObject corresponding to the schema definition passed
string desc
Required. A short description of the response. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:2120
hash examples
A hash of example response messages.
Definition: Swagger.qm.dox.h:2145
contains the possible responses for an operation
Definition: Swagger.qm.dox.h:2084
hash< string, ResponseObject > responses
Definition: Swagger.qm.dox.h:2098
ResponseObject defaultResp
Definition: Swagger.qm.dox.h:2091
constructor(string path, string method, hash< auto > oh, SwaggerSchema swagger)
Constructor.
defines an object in a schema
Definition: Swagger.qm.dox.h:2259
check(bool serialize, bool request, string path, string method, string name, reference< auto > value)
validates the value against the schema definition
const ReferenceTypes
valid reference types
Definition: Swagger.qm.dox.h:2381
static SchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger)
throws an "INVALID-FIELD-TYPE" exception
string name
the name of this object for documentation and example purposes
Definition: Swagger.qm.dox.h:2263
constructor(string name, hash< auto > oh, SwaggerSchema swagger, *string hash_str) public auto getExampleValue()
private constructor; use newSchemaObject() instead
auto additionalProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.4.
Definition: Swagger.qm.dox.h:2310
*int maxProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.1.
Definition: Swagger.qm.dox.h:2288
list< SchemaObject > allOf()
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.3.
*string format
The extending format for the previously mentioned type. See Data Type Formats for further details.
Definition: Swagger.qm.dox.h:2273
bool nullable
extension that allows types to be nullable
Definition: Swagger.qm.dox.h:2296
*string discriminator
Adds support for polymorphism.
Definition: Swagger.qm.dox.h:2337
const ScalarTypes
valid scalar types
Definition: Swagger.qm.dox.h:2377
hash< string, bool > required
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.3.
Definition: Swagger.qm.dox.h:2316
*int minProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.2.
Definition: Swagger.qm.dox.h:2291
auto defaultVal
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2.
Definition: Swagger.qm.dox.h:2285
private checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, hash< auto > v, reference< hash< auto > > value)
validates a schema object against a value
Definition: Swagger.qm.dox.h:2419
static checkValueType(reference< auto > value, string type, *SchemaObject items, *string loc)
validates default values
string type
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.2.
Definition: Swagger.qm.dox.h:2270
hash< string, SchemaObject > properties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.4.
Definition: Swagger.qm.dox.h:2303
*ExternalDocumentationObject externalDocs
Additional external documentation for this schema.
Definition: Swagger.qm.dox.h:2371
*XmlObject xml
This MAY be used only on properties schemas. It has no effect on root schemas.
Definition: Swagger.qm.dox.h:2368
bool readOnly
Relevant only for Schema "properties" definitions. Declares the property as "read only".
Definition: Swagger.qm.dox.h:2347
*SchemaObject items
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.1.
Definition: Swagger.qm.dox.h:2282
*string title
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.1.
Definition: Swagger.qm.dox.h:2276
auto example
A free-form property to include an example of an instance for this schema.
Definition: Swagger.qm.dox.h:2374
static SchemaObject newSchemaObject(string name, hash< auto > oh, SwaggerSchema swagger)
returns a SchemaObject for the schema definition; resolves references
*string desc
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.1.
Definition: Swagger.qm.dox.h:2279
Lists the available scopes for an OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2644
hash< string, string > fields
Maps between a name of a scope to a short description of it (as the value of the property).
Definition: Swagger.qm.dox.h:2651
constructor(hash< auto > oh)
Constructor.
Allows the definition of a security scheme that can be used by the operations.
Definition: Swagger.qm.dox.h:2578
constructor(hash< auto > oh)
Constructor.
string type
Required. The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2".
Definition: Swagger.qm.dox.h:2582
*string desc
A short description for security scheme.
Definition: Swagger.qm.dox.h:2585
*string authorizationUrl
The authorization URL to be used for this flow. This SHOULD be in the form of a URL.
Definition: Swagger.qm.dox.h:2611
*ScopesObject scopes
The available scopes for the OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2627
*string inLoc
The location of the API key. Valid values are "query" or "header".
Definition: Swagger.qm.dox.h:2597
*string name
The name of the header or query parameter to be used.
Definition: Swagger.qm.dox.h:2591
*string flow
The flow used by the OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2605
*string tokenUrl
The token URL to be used for this flow. This SHOULD be in the form of a URL.
Definition: Swagger.qm.dox.h:2617
Contact information for the exposed API.
Definition: Swagger.qm.dox.h:1326
constructor(hash< auto > oh)
Constructor.
*string name
The identifying name of the contact person/organization.
Definition: Swagger.qm.dox.h:1330
*string url
The URL pointing to the contact information. MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1333
*string email
The email address of the contact person/organization. MUST be in the format of an email address.
Definition: Swagger.qm.dox.h:1336
The object provides metadata about the API. The metadata can be used by the clients if needed,...
Definition: Swagger.qm.dox.h:1293
string version
Required. Provides the version of the application API (not to be confused with the specification vers...
Definition: Swagger.qm.dox.h:1306
constructor(hash< auto > oh)
Constructor.
string title
Required. The title of the application.
Definition: Swagger.qm.dox.h:1297
*LicenseObject license
The license information for the exposed API.
Definition: Swagger.qm.dox.h:1312
*ContactObject contact
The contact information for the exposed API.
Definition: Swagger.qm.dox.h:1309
*string termsOfService
The Terms of Service for the API.
Definition: Swagger.qm.dox.h:1303
*string desc
A short description of the application. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1300
License information for the exposed API.
Definition: Swagger.qm.dox.h:1349
constructor(hash< auto > oh)
Constructor.
string name
Required. The license name used for the API.
Definition: Swagger.qm.dox.h:1353
*string url
A URL to the license used for the API. MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1356
Base class for the Swagger specification objects, wrapping the vendor extensions.
Definition: Swagger.qm.dox.h:306
initialize(hash< auto > oh)
Initialize.
hash< auto > vendorExtensions
Allows extensions to the Swagger Schema.
Definition: Swagger.qm.dox.h:314
constructor(ObjectBase other)
copy constructor
constructor(hash< auto > oh)
Constructor.
constructor()
Constructor.
Describes a single API operation on a path.
Definition: Swagger.qm.dox.h:1553
list< string > schemes
The transfer protocol for the operation.
Definition: Swagger.qm.dox.h:1634
*string desc
A verbose explanation of the operation behavior. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1572
hash< string, bool > produces
A hash of MIME types (strings) the operation can produce.
Definition: Swagger.qm.dox.h:1607
*ExternalDocumentationObject externalDocs
Additional external documentation for this operation.
Definition: Swagger.qm.dox.h:1582
string path
the URI path for the operation
Definition: Swagger.qm.dox.h:1557
*string summary
A short summary of what the operation does.
Definition: Swagger.qm.dox.h:1569
hash< string, AbstractParameterObject > parameters()
A hash of parameters that are applicable for this operation.
string method
the HTTP method for the operation
Definition: Swagger.qm.dox.h:1560
AbstractParameterObject body
body parameter; if defined for this operation, formData parameter will be excluded
Definition: Swagger.qm.dox.h:1621
*data getRequestBody(PathItemObject pio, auto body, reference< hash< auto > > headers)
Processes a generated request.
validateRequest(bool serialize, PathItemObject pio, reference< hash< UriQueryInfo > > h, reference< auto > body, reference< hash > headers, *reference< hash< string, bool > > mime_types)
processes a REST API client-side request to the operation
Definition: Swagger.qm.dox.h:1679
ResponsesObject responses
Required. The list of possible responses as they are returned from executing this operation.
Definition: Swagger.qm.dox.h:1627
list tags
A list of tags (strings or TagObjects) for API documentation control.
Definition: Swagger.qm.dox.h:1566
*string operationId
Unique string used to identify the operation.
Definition: Swagger.qm.dox.h:1591
hash< string, AbstractParameterObject > formData
formData parameter; if defined for this operation, body parameter will be excluded
Definition: Swagger.qm.dox.h:1624
list< hash< string, list< string > > > security
A declaration of which security schemes are applied for this operation.
Definition: Swagger.qm.dox.h:1649
hash< string, bool > consumes
A list of MIME types (strings) the operation can consume.
Definition: Swagger.qm.dox.h:1599
constructor(string path, string method, hash< auto > oh, SwaggerSchema swagger)
Constructor.
Holds the relative paths to the individual endpoints.
Definition: Swagger.qm.dox.h:1376
constructor(hash< auto > oh, string pfx, SwaggerSchema swagger)
creates the object
constructor(string full_path, list< auto > l, int offset, hash< auto > oh)
private constructor
add(string full_path, list< auto > l, int offset, hash< auto > oh, SwaggerSchema swagger)
adds a component or a Path Item Object to the tree
hash< string, PathComponent > paths
hash of non-wildcard paths to the next level
Definition: Swagger.qm.dox.h:1393
PathItemObject match(list< auto > path)
returns either a PathItemObject for the path
getPathOperationHash(reference< hash< string, list< string > > > h)
returns a hash of URI paths as keys with values as lists of supported HTTP methods
*PathItemObject tryMatch(list< auto > path)
returns either a PathItemObject for the path
string name
current component name
Definition: Swagger.qm.dox.h:1384
*PathComponent wildcard
if there is a wildcard to a PathComponent
Definition: Swagger.qm.dox.h:1387
string pfx
path prefix
Definition: Swagger.qm.dox.h:1381
*PathItemObject pio
the PathItemObject associated with this path (if any)
Definition: Swagger.qm.dox.h:1390
Describes the operations available on a single path.
Definition: Swagger.qm.dox.h:1479
hash< string, AbstractParameterObject > parameters()
A hash of parameters that are applicable for all the operations described under this path.
softlist getMethods()
returns a list of HTTP methods supported by this object
*string ref
Allows for an external definition of this path item.
Definition: Swagger.qm.dox.h:1488
hash< string, OperationObject > operations
A hash of OperationObjects correspoding to different methods.
Definition: Swagger.qm.dox.h:1517
OperationObject getOperation(string method, string path)
returns the operation object for the given method
AbstractParameterObject body
The body parameter, if defined for this path.
Definition: Swagger.qm.dox.h:1503
constructor(string path, hash< auto > oh, SwaggerSchema swagger)
Constructor.
This class stores the path tree for URI path matching.
Definition: Swagger.qm.dox.h:1433
*PathItemObject tryMatch(string path)
matches a URI path with a PathItemObject
PathItemObject match(string path)
matches a URI path with a PathItemObject
constructor(hash< auto > oh, SwaggerSchema swagger)
Constructor.
PathComponent paths
the tree of path components for path matching with wildcards
Definition: Swagger.qm.dox.h:1438
hash< string, list< string > > getPathOperationHash()
returns a hash of URI paths as keys with values as lists of supported HTTP methods
Base used by OtherParameter, HeaderObject and SchemaObject.
Definition: Swagger.qm.dox.h:339
private checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, string v, reference< auto > value)
validates string values
Definition: Swagger.qm.dox.h:472
*bool exclusiveMin
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.
Definition: Swagger.qm.dox.h:352
auto getExampleValue(string type, *string format)
returns an example value for the given type
*int minItems
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.3.
Definition: Swagger.qm.dox.h:367
*float multipleOf
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.1.
Definition: Swagger.qm.dox.h:379
private check(bool serialize, bool request, string type, *string format, *SchemaObject items, string path, string method, string name, reference< auto > value)
validates the value against the schema definition
Definition: Swagger.qm.dox.h:399
constructor(string objType, hash< auto > oh)
Constructor.
*int maxItems
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.2.
Definition: Swagger.qm.dox.h:364
*int minLength
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2.
Definition: Swagger.qm.dox.h:358
static throwInvalidType(string name, string actual, string expected, auto value)
throws an SCHEMA-VALIDATION-ERROR exception
*float maximum
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.
Definition: Swagger.qm.dox.h:343
constructor(SchemaBase other)
Copy constructor.
private checkArrayParam(bool serialize, bool request, SchemaObject items, string path, string method, string name, reference< softlist< auto > > value)
validates the value against the schema definition
Definition: Swagger.qm.dox.h:499
private checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, binary v, reference value)
converts binary values to strings for supported formats
Definition: Swagger.qm.dox.h:462
*int maxLength
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1.
Definition: Swagger.qm.dox.h:355
checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, date v, reference value)
converts strings to/from date/time values for supported formats
*bool exclusiveMax
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2.
Definition: Swagger.qm.dox.h:349
*bool uniqueItems
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.4.
Definition: Swagger.qm.dox.h:370
static bool checkValueType(reference< auto > value, string type)
Checks the value against the type.
*float minimum
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.
Definition: Swagger.qm.dox.h:346
*string pattern
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.3.
Definition: Swagger.qm.dox.h:361
Used for loading the Swagger definitions.
Definition: Swagger.qm.dox.h:539
static SwaggerSchema fromUrl(string url, *bool json)
Load Swagger definition from a URL or file path.
static string detectSourceEncoding(string str)
tries to determine the Swagger schema source encoding automatically
static hash< auto > parseSchemaSource(string str, string ser)
parses the source encoding from the given string
static hash< auto > parseSchemaContent(string filepath, string str)
Load a schema definition from a file.
static SwaggerSchema fromFile(string filepath)
Load Swagger definition from a file.
static SwaggerSchema fromString(string swaggerSpecification, *bool json)
Load Swagger definition from a string.
This is the root document object for the API specification. It combines what previously was the Resou...
Definition: Swagger.qm.dox.h:598
hash< RestQoreExampleCodeInfo > getQoreExampleResponseImpl(string method, string path, int code)
returns example Qore code for the given response
private hash< RestSchemaValidator::RestExampleRequestInfo > getExampleRequestImpl(string method, string path, *softlist< string > content_types)
returns a hash of example message information for the given request
Definition: Swagger.qm.dox.h:1009
AbstractDataProvider getDataProviderImpl(HTTPClient rest)
returns a data provider object for this connection
setTimeZoneLocaleImpl(*TimeZone tz)
Allows the time zone locale to be set for serialization / deserialization.
internal bool checkResponseTextPlain(reference< hash< HttpResponseInfo > > resp, auto body, hash< string, bool > mime_types, *list< auto > content_types)
Check if the response body can be sent as text/plain and if so, modify the response hash.
Definition: Swagger.qm.dox.h:1267
internal hash< RestSchemaValidator::RestRequestClientInfo > processRequestIntern(string method, string path, auto body, *hash< auto > headers, *softlist< string > content_types, bool compact_serialization)
processes a client-side REST request and returns a hash that can be used to make the outgoing client-...
Definition: Swagger.qm.dox.h:1116
internal hash< HttpResponseInfo > processResponseIntern(string method, string path, int code, auto response_body, *hash< auto > headers, *softlist< string > content_types, bool compact_serialization)
processes a REST response with a serialized message body, validates any response data against schema ...
Definition: Swagger.qm.dox.h:1189
private hash< RestSchemaValidator::RestResponseClientInfo > parseResponseImpl(string method, string path, int code, *data response_body, hash< auto > hdr)
parses and validates the response from the server and returns a hash of the processed info
Definition: Swagger.qm.dox.h:929
hash< string, bool > produces
A set of MIME types (strings) the APIs can produce.
Definition: Swagger.qm.dox.h:651
hash< RestQoreExampleCodeInfo > getQoreExampleRequestImpl(string method, string path)
returns example Qore code for the given request
string getTargetUrlImpl()
returns the target URL for the schema
private hash< RestSchemaValidator::RestRequestClientInfo > processRequestImpl(string method, string path, auto body, *hash< auto > headers, *softlist< string > content_types)
processes a client-side REST request and returns a hash that can be used to make the outgoing client-...
Definition: Swagger.qm.dox.h:847
setBasePathImpl(string basePath)
overrides the basePath value
hash< string, SchemaObject > definitions()
An object to hold data types produced and consumed by operations.
internal bool checkResponseContentTypeHeader(reference< hash< HttpResponseInfo > > resp, auto body, *hash< auto > headers)
Check if the headers contain a content-type header and if so, modify the response hash.
Definition: Swagger.qm.dox.h:1244
hash< string, hash< string, SchemaObject > > so_map
maps name -> SHA1 hash of the config -> schema objects for recursive references
Definition: Swagger.qm.dox.h:726
hash< string, list< string > > getPathOperationHashImpl()
returns a hash of URI paths as keys with values as lists of supported HTTP methods
*hash< auto > source_definition_hash
the raw parsed definitions; used for resolving out-of-order references
Definition: Swagger.qm.dox.h:732
*string def_path
the default path to use when retrieving external schema references
Definition: Swagger.qm.dox.h:715
hash< string, softlist< string > > security
A declaration of which security schemes are applied for the API as a whole.
Definition: Swagger.qm.dox.h:689
hash< string, ResponseObject > responses
Response definitions that can be used across operations. This property does not define global respons...
Definition: Swagger.qm.dox.h:669
*ExternalDocumentationObject externalDocs
Additional external documentation.
Definition: Swagger.qm.dox.h:704
string getBasePathImpl()
returns the base path prefix for all requests in this schema
ResponseObject resolveResponse(string name, string refstr, hash< auto > oh)
resolves a reference to a response
AbstractParameterObject resolveParameter(string name, string refstr, hash< auto > oh)
resolves a reference to a parameter
*code try_import
a call reference or closure to be passed a string name for external schema references
Definition: Swagger.qm.dox.h:720
*string basePath
The base path on which the API is served, which is relative to the host.
Definition: Swagger.qm.dox.h:629
constructorIntern(string schema_source, hash< auto > oh, *hash< auto > opts)
Builds the schema representation from the deserialized schema hash describing the root document objec...
string hash_str
the hash for the schema
Definition: Swagger.qm.dox.h:723
hash< string, SecuritySchemeObject > securityDefinitions
Security scheme definitions that can be used across the specification.
Definition: Swagger.qm.dox.h:675
ParameterItemsSchemaObject resolveParameterItemsSchemaObject(string name, string refstr, hash< auto > oh)
resolves a reference to a parameter items schema object
private hash< HttpResponseInfo > processResponseImpl(string method, string path, int code, auto response_body, *hash< auto > headers, *softlist< string > content_types)
processes a REST response with a serialized message body, validates any response data against schema ...
Definition: Swagger.qm.dox.h:912
SchemaObject processDefinition(string key, auto value)
Processes a schema definition.
string swaggerSpec
Swagger Specification version being used.
Definition: Swagger.qm.dox.h:606
SchemaObject resolveSchemaObject(string name, string refstr, hash< auto > oh)
resolves a reference to a schema object
*TimeZone getTimeZoneLocaleImpl()
Returns the time zone locale used for serialization / deserialization.
private hash< RestExampleResponseInfo > getExampleResponseImpl(string method, string path, int code, *softlist< string > content_types)
returns a hash of example message information for the given request
Definition: Swagger.qm.dox.h:1046
InfoObject info
Required. Provides metadata about the API. The metadata can be used by the clients if needed.
Definition: Swagger.qm.dox.h:609
string getHashImpl()
returns a unique hash for the schema that can be used to compare schemas
hash< auto > getExternalReference(string refstr)
retrieves external references
bool compact_serialization
if serialized data should be subject to compact serialization (default: True)
Definition: Swagger.qm.dox.h:712
const SwaggerOptions
SwaggerSchema options.
Definition: Swagger.qm.dox.h:707
fixPath(reference< string > path)
removes the base path from the beginning of the path, if present
constructor(string schema_source, hash< auto > oh, *hash< auto > opts)
Builds the schema representation from the deserialized schema hash describing the root document objec...
private hash< RestSchemaValidator::RestRequestServerInfo > parseRequestImpl(string method, string path, *data http_body, reference< hash > headers)
processes and parses a client request and returns the deserialized message body (if any)
Definition: Swagger.qm.dox.h:864
*string host
The host (name or IP) serving the API.
Definition: Swagger.qm.dox.h:621
hash< string, bool > consumes
A set of MIME types (strings) the APIs can consume.
Definition: Swagger.qm.dox.h:644
internal bool checkRequestContentTypeHeader(reference< hash< RestRequestClientInfo > > req, auto body, *hash< auto > headers)
Check if the headers contain a content-type header and if so, modify the request hash.
Definition: Swagger.qm.dox.h:1220
hash< string, bool > schemes
The transfer protocol of the API.
Definition: Swagger.qm.dox.h:637
PathsObject paths
Required. The available paths and operations for the API.
Definition: Swagger.qm.dox.h:612
list< TagObject > tags
A list of tags used by the specification with additional metadata.
Definition: Swagger.qm.dox.h:701
hash< string, AbstractParameterObject > parameters()
Parameter definitions that can be used across operations. This property does not define global parame...
Allows adding metadata to a single tag that is used by the OperationObject. It is not mandatory to ha...
Definition: Swagger.qm.dox.h:2235
constructor(hash< auto > oh)
Constructor.
*ExternalDocumentationObject externalDocs
Additional external documentation for this tag.
Definition: Swagger.qm.dox.h:2245
*string desc
A short description for the tag. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:2242
string name
Required. The name of the tag.
Definition: Swagger.qm.dox.h:2239
A metadata object that allows for more fine-tuned XML model definitions.
Definition: Swagger.qm.dox.h:2533
*string ns
The URL of the namespace definition. Value SHOULD be in the form of a URL.
Definition: Swagger.qm.dox.h:2547
constructor(hash< auto > oh)
Constructor.
*string prefix
The prefix to be used for the name.
Definition: Swagger.qm.dox.h:2550
bool wrapped
MAY be used only for an array definition. Signifies whether the array is wrapped (for example,...
Definition: Swagger.qm.dox.h:2560
*string name
Replaces the name of the element/attribute used for the described schema property.
Definition: Swagger.qm.dox.h:2544
bool attribute
Declares whether the property definition translates to an attribute instead of an element....
Definition: Swagger.qm.dox.h:2553
const True
const False
string sprintf(string fmt,...)
main namespace for all public Swagger declarations
Definition: Swagger.qm.dox.h:229
const CollectionFormats
allowed collection formats
Definition: Swagger.qm.dox.h:238
validateResponse(string method, string path, PathItemObject pio, int http_code, reference< auto > response_body, reference< hash< string, bool > > mime_types, bool deserialize=True)
validates a response against the response definition, if any
Definition: Swagger.qm.dox.h:1730
private doDefaultParams(reference< hash< UriQueryInfo > > h, reference< hash > headers, reference< auto > body, hash< string, AbstractParameterObject > parameters, *hash< string, AbstractParameterObject > child_params)
add default parameters
Definition: Swagger.qm.dox.h:1813
hash< RestQoreExampleCodeInfo > getQoreExampleResponse(string method, string path, int code)
returns example Qore code for the given response
const ValidNumberFormats
Valid number type formats.
Definition: Swagger.qm.dox.h:233
const ValidStringFormatsHash
A hash of valid string type formats.
Definition: Swagger.qm.dox.h:250
hash< RestSchemaValidator::RestExampleRequestInfo > getExampleRequest(string method, string path, PathItemObject pio, SwaggerSchema swagger, reference rbody)
returns a hash of example message information for the given request
Definition: Swagger.qm.dox.h:1762
error(string err, string fmt)
raises an exception with context information
const ValidNumberFormatsHash
A hash of valid number type formats.
Definition: Swagger.qm.dox.h:248
const ParameterCollectionFormats
valid parameter collection formats
Definition: Swagger.qm.dox.h:242
const SerializationModules
modules available for data serialization and/or deserialization
Definition: Swagger.qm.dox.h:296
hash< RestExampleResponseInfo > getExampleResponse(string method, string path, int code, reference< auto > body)
returns a hash of example message information for the given request
const ValidStringFormats
Valid string type formats.
Definition: Swagger.qm.dox.h:235
const ValidIntFormatsHash
A hash of valid integer type formats.
Definition: Swagger.qm.dox.h:246
const MimeDataTypes
supported mime types for de/serializing data
Definition: Swagger.qm.dox.h:261
const MimeContentTypes
MIME types for data serialization.
Definition: Swagger.qm.dox.h:299
const ValidIntFormats
Valid integer type formats.
Definition: Swagger.qm.dox.h:231
parseRequest(PathItemObject pio, reference< hash< UriQueryInfo > > h, reference< auto > body, reference< hash > headers)
parses and processes a REST request on the server side
const YamlSerialization
Yaml serialization.
Definition: Swagger.qm.dox.h:253
*ResponseObject getResponse(int code)
returns the ResponseObject for hthe given HTTP code or NOTHING if none is configured
private checkMissingParams(hash< UriQueryInfo > h, *hash< auto > headers, auto body, hash< string, AbstractParameterObject > parameters, *hash< string, AbstractParameterObject > child_params)
checks for missing params
Definition: Swagger.qm.dox.h:1820
hash< RestQoreExampleCodeInfo > getQoreExampleRequest(string method, string path, PathItemObject pio, SwaggerSchema swagger)
returns example Qore code for the given request
const ValidSchemes
Valid transfer protocol schemes.
Definition: Swagger.qm.dox.h:302