Qore Swagger Module Reference 2.1.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
235namespace Swagger {
237const ValidIntFormats = ("int32", "int64");
239const ValidNumberFormats = ("double", "float");
241const ValidStringFormats = ("binary", "byte", "date", "date-time", "password");
242
245
246
249
250
252const ValidIntFormatsHash = map {$1: True}, ValidIntFormats;
257
260 "serialize": \make_yaml(),
261 "serialize_verbose": string sub (auto val) {return make_yaml(val, BlockStyle);},
262 "deserialize": \parse_yaml(),
263 "module": "yaml",
264};
265
268%ifndef NoJson
269 MimeTypeJson: (
270 "serialize": \make_json(),
271 "serialize_verbose": string sub (auto val) {return make_json(val, JGF_ADD_FORMATTING);},
272 "deserialize": \parse_json(),
273 "module": "json",
274 ),
275%endif
276%ifndef NoYaml
277 // issue #3699: more YAML MIME types must be supported
278 MimeTypeYaml: YamlSerialization,
279 MimeTypeYamlRpc: YamlSerialization,
280 "text/yaml": YamlSerialization,
281 "application/yaml": YamlSerialization,
282%endif
283%ifndef NoXml
284 MimeTypeXmlApp: (
285 "serialize": \make_xml(),
286 "serialize_verbose": string sub (auto val) {return make_xml(val, XGF_ADD_FORMATTING);},
287 "deserialize": \parse_xml(),
288 "module": "xml",
289 ),
290%endif
291 # Content-Type: application/x-www-form-urlencoded
292 MimeTypeFormUrlEncoded: (
293 "serialize": \mime_get_form_urlencoded_string(),
294 "serialize_verbose": \mime_get_form_urlencoded_string(),
295 "deserialize": \mime_parse_form_urlencoded_string(),
296 ),
297 # Content-Type: multipart/form-data (handled manually)
298 MimeTypeMultipartFormData: {},
299};
300
302const SerializationModules = keys (map {$1.module: True}, MimeDataTypes.iterator(), $1.module);
303
306
308const ValidSchemes = ("http", "https", "ws", "wss");
309const ValidSchemesHash = map {$1: True}, ValidSchemes;
310
313
314public:
316
321
324
325
327
330 constructor(hash<auto> oh);
331
332
335
336
338
341 initialize(hash<auto> oh);
342};
343
346
347public:
349 *float maximum;
350
352 *float minimum;
353
356
359
362
365
367 *string pattern;
368
371
374
377
379
382 hash<string, bool> enum;
383
386
388
391 constructor(string objType, hash<auto> oh);
392
393
396
397
399protected:
400 auto getExampleValue(string type, *string format);
401public:
402
403
405 private check(bool serialize, bool request, string type, *string format, *SchemaObject items, string path,
406 string method, string name, reference<auto> value) {
407 // accept a single value for an array (= one-element list)
408 if (type == 'array');
409 else {
410 checkIntern(serialize, request, type, format, path, method, name, value, \value);
411 }
412 }
413
414protected:
415 checkStringIntern(string path, string method, string name, string value);
416public:
417
418
419 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
420 string name, list<auto> v, reference<list> value) {
421 if (type != "list" && type != "any")
422 throw "SCHEMA-VALIDATION-ERROR", sprintf("Parameter %y for path %y and method %y is an array (%y), but "
423 "the expected type is %y", name, path, method, v, type);
424 }
425
426 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
427 string name, hash<auto> v, reference<hash> value) {
428 if (type != "file" && type != "any")
429 throw "SCHEMA-VALIDATION-ERROR", sprintf("Parameter %y for path %y and method %y is an object (%y), but "
430 "the expected type is %y", name, path, method, v, type);
431 }
432
433 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
434 string name, int v, reference<auto> value) {
435 // NOTE: "number" also accepts "int"
436 if (type == 'number');
437
438 if (type != "integer" && type != "any")
439 throwInvalidType(name, "integer", type, v);
440 if (exists maximum);
441
442
443 if (exists minimum);
444
445
446 if (enum && !enum{value})
447 throw "SCHEMA-VALIDATION-ERROR",
448 sprintf("Parameter %y for path %y and method %y does not fit the enumerated values (enum: %y, actual: %d)",
449 name, path, method, keys enum, value);
450 }
451
452protected:
453 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, number v, reference<number> value);
454public:
455
456
457protected:
458 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, float v, reference<number> value);
459public:
460
461
462protected:
463 checkInternNumber(bool serialize, bool request, string type, *string format, string path, string method, string name, auto v, reference<auto> value);
464public:
465
466
468 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
469 string name, binary v, reference value) {
470 if (type != "string" && type != "any")
471 throwInvalidType(name, "string", type, v);
472
473 if (serialize);
474
475 }
476
478 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
479 string name, string v, reference<auto> value) {
480 if (type != 'string' && type != 'any');
481
482
483 if (serialize);
484 # https://xml2rfc.tools.ietf.org//rfc/html/rfc3339.html#anchor14 if (value.typeCode() == NT_STRING);
485
486 }
487
489protected:
490 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, date v, reference value);
491public:
492
493
494protected:
495 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, bool v, reference<bool> value);
496public:
497
498
499protected:
500 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, nothing v, reference<nothing> value);
501public:
502
503
505 private checkArrayParam(bool serialize, bool request, SchemaObject items, string path, string method, string name,
506 reference<softlist<auto>> value) {
507 if (exists maxItems && value.size() > maxItems)
508 throw "SCHEMA-VALIDATION-ERROR",
509 sprintf("Parameter %y for path %y and method %y has too many items (maxItems: %d, actual: %d)",
510 name, path, method, maxItems, value.size());
511 if (exists minItems && value.size() < minItems)
512 throw "SCHEMA-VALIDATION-ERROR",
513 sprintf("Parameter %y for path %y and method %y has too few items (minItems: %d, actual: %d)",
514 name, path, method, minItems, value.size());
515
516 // check array element types
517 if (!uniqueItems || items.type != 'array');
518 else {
519 // perform slow array uniqueness check
520 list<auto> uniqueItems = ();
521 foreach auto val in (\value) {
522 items.check(serialize, request, path, method, name, \val);
523 if (uniqueItems.contains(val))
524 throw "SCHEMA-VALIDATION-ERROR",
525 sprintf("%s %s: Array parameter %y does not have unique items",
526 method, path, name);
527 uniqueItems += val;
528 }
529 }
530 }
531
533protected:
534 static throwInvalidType(string name, string actual, string expected, auto value);
535public:
536
537
539
541 static bool checkValueType(reference<auto> value, string type);
542};
543
546
547public:
549
557 static SwaggerSchema fromString(string swaggerSpecification, *bool json);
558
560
568 static SwaggerSchema fromFile(string filepath);
569
571
582 static SwaggerSchema fromUrl(string url, *bool json);
583
585
594 static hash<auto> parseSchemaContent(string filepath, string str);
595
597 static hash<auto> parseSchemaSource(string str, string ser);
598
600 static string detectSourceEncoding(string str);
601};
602
604class SwaggerSchema : public ObjectBase,public AbstractRestSchemaValidator {
605
606public:
608
613
616
619
621
627 *string host;
628
630
635 *string basePath;
636
638
643 hash<string, bool> schemes;
644
646
650 hash<string, bool> consumes;
651
653
657 hash<string, bool> produces;
658
660
663 hash<string, SchemaObject> definitions();
664
666
669 hash<string, AbstractParameterObject> parameters();
670
672
675 hash<string, ResponseObject> responses;
676
678
681 hash<string, SecuritySchemeObject> securityDefinitions;
682
684
695 hash<string, softlist<string>> security;
696
698
707 list<TagObject> tags;
708
711
713 const SwaggerOptions = ...;
714
715
716protected:
719
721 *string def_path;
722
724
727
729 string hash_str;
730
732 hash<string, hash<string, SchemaObject>> so_map;
733
734public:
735
736private:
739
740public:
741
743
759 constructor(string schema_source, hash<auto> oh, *hash<auto> opts) ;
760
761
763
779 constructor(Logger logger, string schema_source, hash<auto> oh, *hash<auto> opts) : ObjectBase(oh),
780 AbstractRestSchemaValidator(logger);
781
782
784protected:
785 constructorIntern(string schema_source, hash<auto> oh, *hash<auto> opts);
786public:
787
788
789 *SchemaObject tryGetSchemaObject(string name, hash<auto> oh, reference<string> hash_str);
790
791
792 cacheSchemaObject(string name, string hash_str, SchemaObject so);
793
794
796
798 SchemaObject resolveSchemaObject(string name, string refstr, hash<auto> oh);
799
800
802
804 ParameterItemsSchemaObject resolveParameterItemsSchemaObject(string name, string refstr, hash<auto> oh);
805
806
808
810 AbstractParameterObject resolveParameter(string name, string refstr, hash<auto> oh);
811
812
814
816 ResponseObject resolveResponse(string name, string refstr, hash<auto> oh);
817
818
820
824protected:
825 string getHashImpl();
826public:
827
828
830
834protected:
836public:
837
838
840
853 private hash<RestSchemaValidator::RestRequestClientInfo> processRequestImpl(string method, string path, auto body,
854 *hash<auto> headers, *softlist<string> content_types) {
855 return processRequestIntern(method, path, body, headers, content_types, compact_serialization);
856 }
857
859
870 private hash<RestSchemaValidator::RestRequestServerInfo> parseRequestImpl(string method, string path,
871 *data http_body, reference<hash> headers) {
872 auto body;
873 // deserialize body according to Content-Type
874 if (exists http_body);
875
876
877 // path must be absolute for matching to work correctly
878 if (path ==1)
879 path = "/" + path;
880
881 // remove basePath if present; note that "basePath" must always have a leading / if set
882 fixPath(\path);
883
884 hash<UriQueryInfo> h = parse_uri_query(path);
885 method = method.lwr();
886 PathItemObject pio = paths.match(h.method);
887 OperationObject op = pio.getOperation(method, h.method);
888
889 op.parseRequest(pio, \h, \body, \headers);
890 return <RestRequestServerInfo>{
891 "path": h.method,
892 "query": h.params,
893 "path_args": h.path_params,
894 "body": body,
895 };
896 }
897
899
918 private hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, auto response_body,
919 *hash<auto> headers, *softlist<string> content_types) {
920 return processResponseIntern(method, path, code, response_body, headers, content_types,
922 }
923
925
935 private hash<RestSchemaValidator::RestResponseClientInfo> parseResponseImpl(string method, string path, int code,
936 *data response_body, hash<auto> hdr) {
937 // remove basePath if present
938 fixPath(\path);
939
940 method = method.lwr();
941 PathItemObject pio = paths.match(path);
942 OperationObject op = pio.getOperation(method, path);
943
944 hash<RestResponseClientInfo> rv((
945 "code": code,
946 "hdr": hdr,
947 ));
948
949 *string content = hdr."content-type" ?? hdr."Content-Type";
950
951 // deserialize body according to Content-Type
952 if (exists response_body && content);
953
954
955 hash<string, bool> mime_types;
956 op.validateResponse(method, path, pio, code, \rv.body, \mime_types, False);
957
958 if (content && !mime_types{content})
959 throw "DESERIALIZATION-ERROR", sprintf("%s %s: content type %y is not accepted by this operation; "
960 "accepted content types: %y", method.upr(), path, content, keys mime_types);
961
962 return rv;
963 }
964
966protected:
967 fixPath(reference<string> path);
968public:
969
970
972
974protected:
975 hash<string, list<string>> getPathOperationHashImpl();
976public:
977
978
980
984protected:
986public:
987
988
990
992protected:
994public:
995
996
998
1003protected:
1004 hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
1005public:
1006
1007
1009
1015 private hash<RestSchemaValidator::RestExampleRequestInfo> getExampleRequestImpl(string method, string path,
1016 *softlist<string> content_types) {
1017 // remove basePath if present
1018 fixPath(\path);
1019
1020 method = method.lwr();
1021 PathItemObject pio = paths.match(path);
1022 OperationObject op = pio.getOperation(method, path);
1023
1024 auto body;
1025 hash<RestExampleRequestInfo> rv = op.getExampleRequest(method, path, pio, self, \body);
1026 if (exists body);
1027
1028
1029 return rv;
1030 }
1031
1033
1039protected:
1040 hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
1041public:
1042
1043
1045
1052 private hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code,
1053 *softlist<string> content_types) {
1054 // remove basePath if present
1055 fixPath(\path);
1056
1057 method = method.lwr();
1058 PathItemObject pio = paths.match(path);
1059 OperationObject op = pio.getOperation(method, path);
1060
1061 auto body;
1062 hash<RestExampleResponseInfo> rv = op.getExampleResponse(method, path, code, \body);
1063 if (exists body);
1064
1065
1066 return rv;
1067 }
1068
1070
1072protected:
1073 hash<auto> getExternalReference(string refstr);
1074public:
1075
1076
1078
1082protected:
1083 AbstractDataProvider getDataProviderImpl(HTTPClient rest);
1084public:
1085
1086
1088
1092protected:
1094public:
1095
1096
1098
1102protected:
1104public:
1105
1106
1108
1122 private:internal hash<RestSchemaValidator::RestRequestClientInfo> processRequestIntern(string method, string path,
1123 auto body, *hash<auto> headers, *softlist<string> content_types, bool compact_serialization) {
1124 // remove basePath if present
1125 fixPath(\path);
1126
1127 hash<UriQueryInfo> h = parse_uri_query(path);
1128
1129 // find path item object and operation
1130 method = method.lwr();
1131 PathItemObject pio = paths.match(h.method);
1132 OperationObject op = pio.getOperation(method, h.method);
1133
1134 // perform validation
1135 hash<string, bool> mime_types;
1136 op.validateRequest(True, pio, \h, \body, \headers, \mime_types);
1137
1138 hash<RestRequestClientInfo> rv((
1139 "uri_path": h.method,
1140 ));
1141
1142 if (op.produces);
1143
1144
1145 // add the basePath to the request
1146 if (exists basePath);
1147
1148
1149 // rebuild URI query after processing
1150 if (h.params);
1151
1152
1153 if (!body);
1154
1155
1156 if (!exists content_types);
1157
1158
1159 foreach string content in (content_types);
1160
1161
1162 // check if the \c Content-Type header is already set
1163 if (checkRequestContentTypeHeader(\rv, body, headers));
1164
1165
1166 if (content_types == MimeContentTypes);
1167 else {
1168 throw "SERIALIZATION-ERROR", sprintf("%s %s: message body cannot be serialized; requested MIME type(s): "
1169 "%y; available MIME types: %y; available serialization modules: %y", method.upr(), path,
1170 content_types, mime_types, SerializationModules);
1171 }
1172 }
1173
1175
1195 private:internal hash<HttpResponseInfo> processResponseIntern(string method, string path, int code,
1196 auto response_body, *hash<auto> headers, *softlist<string> content_types, bool compact_serialization) {
1197 // find path item object and operation
1198 method = method.lwr();
1199 PathItemObject pio = paths.match(path);
1200 OperationObject op = pio.getOperation(method, path);
1201
1202 // perform validation
1203 hash<string, bool> mime_types;
1204 op.validateResponse(method, path, pio, code, \response_body, \mime_types);
1205
1206 hash<HttpResponseInfo> rv((
1207 "code": code,
1208 "hdr": headers,
1209 ));
1210
1211 if (exists response_body);
1212
1213
1214 return rv;
1215 }
1216
1218
1226 private:internal bool checkRequestContentTypeHeader(reference<hash<RestRequestClientInfo>> req, auto body,
1227 *hash<auto> headers) {
1228 // quickly return if body is not in data format
1229 if (body.typeCode() != NT_BINARY && body.typeCode() != NT_STRING)
1230 return False;
1231
1232 // try to find \c Content-Type header
1233 *list<string> ct = map $1, keys headers, $1 ==1i;
1234
1235 // if found and it's not one of the default ones, use it
1236 if (ct && ct.size() == 1 && !MimeDataTypes{headers{ct[0]}});
1237
1238 return False;
1239 }
1240
1242
1250 private:internal bool checkResponseContentTypeHeader(reference<hash<HttpResponseInfo>> resp, auto body,
1251 *hash<auto> headers) {
1252 // quickly return if body is not in data format
1253 if (body.typeCode() != NT_BINARY && body.typeCode() != NT_STRING)
1254 return False;
1255
1256 // try to find \c Content-Type header
1257 *list<string> ct = map $1, keys headers, $1 ==1i;
1258
1259 // if found, use it and don't serialize the body
1260 if (ct && ct.size() == 1);
1261
1262 return False;
1263 }
1264
1266
1273 private:internal bool checkResponseTextPlain(reference<hash<HttpResponseInfo>> resp, auto body,
1274 hash<string, bool> mime_types, *list<auto> content_types) {
1275 // quickly return if body is not string
1276 if (body.typeCode() != NT_STRING)
1277 return False;
1278
1279 // return if text/plain is not allowed for this operation
1280 if (!mime_types."text/plain")
1281 return False;
1282
1283 if (content_types);
1284
1285
1286 resp.body = body;
1287 resp.hdr."Content-Type" = "text/plain";
1288 return True;
1289 }
1290
1292private:
1293 SchemaObject processDefinition(string key, auto value);
1294public:
1295
1296};
1297
1299class InfoObject : public ObjectBase {
1300
1301public:
1303 string title;
1304
1306 *string desc;
1307
1310
1312 string version;
1313
1316
1319
1321
1327 constructor(hash<auto> oh) ;
1328
1329};
1330
1333
1334public:
1336 *string name;
1337
1339 *string url;
1340
1342 *string email;
1343
1345
1350 constructor(hash<auto> oh) ;
1351
1352};
1353
1356
1357public:
1359 string name;
1360
1362 *string url;
1363
1365
1371 constructor(hash<auto> oh) ;
1372
1373};
1374
1376
1383
1384public:
1385protected:
1387 string pfx;
1388
1390 string name;
1391
1394
1397
1399 hash<string, PathComponent> paths;
1400
1401public:
1402
1404 constructor(hash<auto> oh, string pfx, SwaggerSchema swagger);
1405
1406
1408protected:
1409 constructor(string full_path, list<auto> l, int offset, hash<auto> oh);
1410public:
1411
1412
1414protected:
1415 add(string full_path, list<auto> l, int offset, hash<auto> oh, SwaggerSchema swagger);
1416public:
1417
1418
1420
1422 PathItemObject match(list<auto> path);
1423
1424
1426
1428 *PathItemObject tryMatch(list<auto> path);
1429
1430
1432
1434 getPathOperationHash(reference<hash<string, list<string>>> h);
1435
1436};
1437
1439class PathsObject : public ObjectBase {
1440
1441public:
1442protected:
1445
1446public:
1447
1449
1457 constructor(hash<auto> oh, SwaggerSchema swagger) ;
1458
1459
1461
1463 PathItemObject match(string path);
1464
1465
1467
1470
1471
1473
1475 hash<string, list<string>> getPathOperationHash();
1476
1477};
1478
1480
1486
1487public:
1489
1494 *string ref;
1495
1497
1506 hash<string, AbstractParameterObject> parameters();
1507
1510
1511protected:
1513
1523 hash<string, OperationObject> operations;
1524
1525public:
1526
1528
1537 constructor(string path, hash<auto> oh, SwaggerSchema swagger) ;
1538
1539
1541
1548 OperationObject getOperation(string method, string path);
1549
1550
1552
1554 softlist getMethods();
1555
1556};
1557
1560
1561public:
1563 string path;
1564
1566 string method;
1567
1569
1572 list tags;
1573
1575 *string summary;
1576
1578 *string desc;
1579
1581
1585 bool deprec = False;
1586
1589
1591
1598
1600
1605 hash<string, bool> consumes;
1606
1608
1613 hash<string, bool> produces;
1614
1616
1624 hash<string, AbstractParameterObject> parameters();
1625
1628
1630 hash<string, AbstractParameterObject> formData;
1631
1634
1636
1640 list<string> schemes;
1641
1643
1655 list<hash<string, list<string>>> security;
1656
1658
1667 constructor(string path, string method, hash<auto> oh, SwaggerSchema swagger) ;
1668
1669
1671 *data getRequestBody(PathItemObject pio, auto body, reference<hash<auto>> headers);
1672
1673
1675
1685 validateRequest(bool serialize, PathItemObject pio, reference<hash<UriQueryInfo>> h, reference<auto> body,
1686 reference<hash> headers, *reference<hash<string, bool>> mime_types) {
1687 // check query parameters
1688 foreach string key in (keys h.params);
1689
1690
1691 // check header parameters
1692 foreach string key in (keys headers);
1693
1694
1695 // check body parameters
1696 {
1697 *AbstractParameterObject body_po = self.body ?? pio.body;
1698 if (body_po) {
1699 body_po.check(serialize, True, path, method, "body", \body);
1700 } else if (formData) {
1701 foreach hash<auto> i in (formData.pairIterator()) {
1702 i.value.check(serialize, True, path, method, "formData." + i.key, \body{i.key});
1703 }
1704 } else if (body) {
1705 error("SCHEMA-VALIDATION-ERROR", "No message body is accepted; body keys passed: %y", keys body);
1706 }
1707 }
1708
1709 // check path parameters
1710 foreach string param in (path =~ x/{([^}]+)}/g);
1711
1712
1713 // check for missing required parameters
1714 checkMissingParams(h, headers, body, parameters);
1715 checkMissingParams(h, headers, body, pio.parameters, parameters);
1716
1717 if (consumes);
1718
1719 };
1720
1722
1732 parseRequest(PathItemObject pio, reference<hash<UriQueryInfo>> h, reference<auto> body, reference<hash> headers);
1733
1734
1736 validateResponse(string method, string path, PathItemObject pio, int http_code, reference<auto> response_body,
1737 reference<hash<string, bool>> mime_types, bool deserialize = True) {
1738 *ResponseObject res = getResponse(http_code);
1739 if (res.schema);
1740 else if (exists res && exists response_body);
1741
1742
1743 if (produces);
1744
1745 }
1746
1748
1755 hash<RestQoreExampleCodeInfo> getQoreExampleRequest(string method, string path, PathItemObject pio, SwaggerSchema swagger);
1756
1757
1759
1768 hash<RestSchemaValidator::RestExampleRequestInfo> getExampleRequest(string method, string path,
1769 PathItemObject pio, SwaggerSchema swagger, reference rbody) {
1770 hash<RestExampleRequestInfo> rv();
1771
1773 hash<auto> query;
1774
1775 getQoreExampleParams(\query, \rv.hdr, parameters);
1776 getQoreExampleParams(\query, \rv.hdr, pio.parameters, parameters);
1777
1778 rv.request_uri = sprintf("%s %s HTTP/1.1", method.upr(),
1779 make_uri_query(cast<hash<UriQueryInfo>>({"method": path, "params": query})));
1780
1782 *BodyParameter body_po = body ?? pio.body;
1783 if (body_po)
1784 rbody = body_po.getExampleValue();
1785
1786 return rv;
1787 }
1788
1790
1797 hash<RestQoreExampleCodeInfo> getQoreExampleResponse(string method, string path, int code);
1798
1799
1801
1809 hash<RestExampleResponseInfo> getExampleResponse(string method, string path, int code, reference<auto> body);
1810
1811
1812 private getQoreExampleParams(reference<hash<auto>> query, reference<hash<auto>> headers,
1813 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1814 foreach hash<auto> ph in (parameters.pairIterator());
1815
1816 }
1817
1819 private doDefaultParams(reference<hash<UriQueryInfo>> h, reference<hash> headers, reference<auto> body,
1820 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1821 foreach hash<auto> ph in (parameters.pairIterator());
1822
1823 }
1824
1826 private checkMissingParams(hash<UriQueryInfo> h, *hash<auto> headers, auto body,
1827 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1828 foreach hash<auto> ph in (parameters.pairIterator());
1829
1830 }
1831
1833
1835protected:
1837public:
1838
1839
1841protected:
1842 error(string err, string fmt);
1843public:
1844
1845}
1846
1848class ExternalDocumentationObject : public ObjectBase {
1849
1850public:
1852 *string desc;
1853
1855 string url;
1856
1858
1864 constructor(hash<auto> oh) ;
1865
1866};
1867
1869
1905class AbstractParameterObject : public ObjectBase {
1906
1907public:
1909
1916 string name;
1917
1919
1923 string inLoc;
1924
1926 *string desc;
1927
1929
1934 bool required = False;
1935
1936protected:
1937 const OtherParameterMap = ...;
1938
1939
1940public:
1941
1943
1950 constructor(hash<auto> oh) ;
1951
1952
1954 abstract check(bool serialize, bool request, string path, string method, string name, reference value);
1955
1958
1959
1961 static AbstractParameterObject newParameter(string name, hash<auto> oh, SwaggerSchema swagger);
1962};
1963
1966
1967public:
1970
1972
1979 constructor(hash<auto> oh, SwaggerSchema swagger) ;
1980
1981
1983 check(bool serialize, bool request, string path, string method, string name, reference value);
1984
1985
1987 string getQoreExample(reference<hash<RestQoreExampleCodeInfo>> rv);
1988
1989
1990 // returns an example value for a REST API call
1991 auto getExampleValue();
1992
1993};
1994
1996class OtherParameter : public AbstractParameterObject,public SchemaBase {
1997
1998public:
2000
2009 string type;
2010
2012 *string format;
2013
2015
2020 bool allowEmptyValue = False;
2021
2024
2026
2040
2042
2050
2052 const ParameterTypes = ...;
2053
2054
2056
2066 constructor(string name, hash<auto> oh, SwaggerSchema swagger)
2067 ;
2068
2069
2071 check(bool serialize, bool request, string path, string method, string name, reference<auto> value);
2072
2073
2076
2077
2080
2081
2083protected:
2084 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2085public:
2086
2087};
2088
2090class ResponsesObject : public ObjectBase {
2091
2092public:
2093 // The documentation of responses other than the ones declared for specific HTTP response codes.
2098
2099 // A hash mapping HTTP status codes to @ref ResponseObject "ResponseObjects".
2104 hash<string, ResponseObject> responses;
2105
2107
2117 constructor(string path, string method, hash<auto> oh, SwaggerSchema swagger) ;
2118
2119};
2120
2122class ResponseObject : public ObjectBase {
2123
2124public:
2126 string desc;
2127
2129
2136
2138
2141 hash<auto> headers;
2142
2144
2152
2154
2162protected:
2163 constructor(string key, hash<auto> oh, SwaggerSchema swagger) ;
2164public:
2165
2166
2168
2177 static ResponseObject newResponse(string key, hash<auto> oh, SwaggerSchema swagger);
2178};
2179
2181class HeaderObject : public ObjectBase,public SchemaBase {
2182
2183public:
2185 *string desc;
2186
2188
2192 string type;
2193
2195 *string format;
2196
2199
2201
2211
2213
2220
2222
2230 constructor(hash<auto> oh, SwaggerSchema swagger) ;
2231
2232
2234protected:
2235 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2236public:
2237
2238};
2239
2241class TagObject : public ObjectBase {
2242
2243public:
2245 string name;
2246
2248 *string desc;
2249
2252
2254
2260 constructor(hash<auto> oh) ;
2261
2262};
2263
2265class SchemaObject : public ObjectBase,public SchemaBase {
2266
2267public:
2269 string name;
2270
2272
2276 string type;
2277
2279 *string format;
2280
2282 *string title;
2283
2285 *string desc;
2286
2289
2292
2295
2298
2300
2302 bool nullable = False;
2303
2305
2309 hash<string, SchemaObject> properties;
2310
2312
2317
2319
2322 hash<string, bool> required;
2323
2325
2344
2346
2353 bool readOnly = False;
2354
2356
2364 list<SchemaObject> allOf();
2365
2367
2375
2378
2381
2383 const ScalarTypes = ...;
2384
2385
2387 const ReferenceTypes = ...;
2388
2389
2391
2404protected:
2405 constructor(string name, hash<auto> oh, SwaggerSchema swagger, *string hash_str, *bool require_items)
2406public:
2407
2408
2410 string getQoreExample(reference<hash<RestQoreExampleCodeInfo>> rv, string name, bool decl);
2411
2412
2413 // returns an example value for a REST API call
2415
2416
2418 check(bool serialize, bool request, string path, string method, string name, reference<auto> value);
2419
2420
2421protected:
2422 checkObjectProperty(string name, string prop);
2423public:
2424
2425
2427 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
2428 string name, hash<auto> v, reference<hash<auto>> value) {
2429 if (type != "object" && type != "any")
2430 throwInvalidType(name, "object", type, v);
2431
2432 // check "allOf" schemas, if any
2433 map $1.checkIntern(serialize, request, type, NOTHING, path, method, name, v, \value), allOf;
2434
2435 /*
2436 If additionalProperties is set to true, any number of additionalProperties may be present of any data
2437 type.
2438 If additionalProperties is a schema, additional properties (beyond what are defined in ‘properties’) are
2439 allowed and must match the schema
2440 */
2441 // check properties in this schema definition
2442 if (!additionalProperties && type != 'any');
2443
2444 // check for missing required properties
2445 foreach string prop in (keys required);
2446
2447 //printf("SchemaObject::checkIntern() %y type: %y val: %y self: %N\n", name, type, value, self);
2448 }
2449
2451protected:
2452 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2453public:
2454
2455
2457
2468 static SchemaObject newSchemaObject(string name, hash<auto> oh, SwaggerSchema swagger, *bool require_items);
2469
2471
2473 static SchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger);
2474};
2475
2478
2479public:
2481
2495
2497
2509protected:
2510 constructor(string name, hash<auto> oh, SwaggerSchema swagger) ;
2511public:
2512
2513
2515
2527 static ParameterItemsSchemaObject newSchemaObject(string name, hash<auto> oh, SwaggerSchema swagger);
2528
2530
2532 static ParameterItemsSchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger);
2533};
2534
2536
2541class XmlObject : public ObjectBase {
2542
2543public:
2545
2552 *string name;
2553
2555 *string ns;
2556
2558 *string prefix;
2559
2561 bool attribute = False;
2562
2564
2568 bool wrapped = False;
2569
2571
2576 constructor(hash<auto> oh) ;
2577
2578};
2579
2581
2586class SecuritySchemeObject : public ObjectBase {
2587
2588public:
2590 string type;
2591
2593 *string desc;
2594
2596
2599 *string name;
2600
2602
2605 *string inLoc;
2606
2608
2613 *string flow;
2614
2616
2620
2622
2625 *string tokenUrl;
2626
2628
2636
2638
2647 constructor(hash<auto> oh) ;
2648
2649};
2650
2652class ScopesObject : public ObjectBase {
2653
2654public:
2656
2659 hash<string, string> fields;
2660
2662
2667 constructor(hash<auto> oh) ;
2668
2669};
2670}
2671
2672// private namespace for internal definitions
2673namespace Priv {
2674 // a set of string values
2675 const SwaggerListToStringSet = -1;
2676 // a set of any type that can be converted to a string
2677 const SwaggerListToAnySet = -2;
2678 const SwaggerListToHashOfStrings = -3;
2679
2680 const TypeMap = ...;
2681
2682
2684
2694 required_field(string objType, hash<auto> oh, string name, int typeCode, reference<auto> target);
2695
2696
2698
2708 required_field(string objType, hash<auto> oh, string name, hash<string, bool> typeCodes, reference<auto> target);
2709
2710
2712
2723 bool optional_field(string objType, hash<auto> oh, string name, int typeCode, reference<auto> target);
2724
2725
2727
2738 bool optional_field(string objType, hash<auto> oh, string name, hash<string, bool> typeCodes,
2739 reference<auto> target) {
2740 if (!oh.hasKey(name))
2741 return False;
2742 auto val = oh{name};
2743 if (!typeCodes{val.typeCode()})
2744 throw "INVALID-FIELD-TYPE", sprintf("%s Object%s: %y field has invalid type %y", objType,
2745 oh.name ? sprintf(" %y", oh.name) : "", name, val.type());
2746 get_value(objType, name, val.typeCode(), val, \target);
2747 return True;
2748 }
2749
2751 check_type_code(string objType, hash<auto> oh, string name, auto val, int typeCode);
2752
2753
2755 get_value(string objType, string name, int typeCode, auto val, reference<auto> target);
2756
2757
2759 string get_qore_type(string name, string type, *string format, *SchemaObject items);
2760
2761}
Describes a single operation parameter.
Definition: Swagger.qm.dox.h:1905
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:1916
auto getDefaultValue()
returns the default value of the parameter (default: NOTHING)
string inLoc
Required. The location of the parameter.
Definition: Swagger.qm.dox.h:1923
*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:1926
bool required
Determines whether this parameter is mandatory.
Definition: Swagger.qm.dox.h:1934
AbstractParameterObject specialization for "body" parameters.
Definition: Swagger.qm.dox.h:1965
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:1969
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:1848
string url
Required. The URL for the target documentation. Value MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1855
*string desc
A short description of the target documentation. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1852
constructor(hash< auto > oh)
Constructor.
describes a single HTTP header
Definition: Swagger.qm.dox.h:2181
*string collectionFormat
Determines the format of the array if type array is used.
Definition: Swagger.qm.dox.h:2210
*SchemaObject items
Required if type is "array". Describes the type of items in the array.
Definition: Swagger.qm.dox.h:2198
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:2219
*string format
The extending format for the previously mentioned type. See Data Type Formats for further details.
Definition: Swagger.qm.dox.h:2195
*string desc
A short description of the header.
Definition: Swagger.qm.dox.h:2185
string type
Required. The type of the object.
Definition: Swagger.qm.dox.h:2192
constructor(hash< auto > oh, SwaggerSchema swagger)
Constructor.
AbstractParameterObject specialization for parameters other than "body".
Definition: Swagger.qm.dox.h:1996
const ParameterTypes
valid parameter types
Definition: Swagger.qm.dox.h:2052
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:2039
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:2012
bool allowEmptyValue
Sets the ability to pass empty-valued parameters.
Definition: Swagger.qm.dox.h:2020
auto defaultVal
Declares the value of the parameter that the server will use if none is provided.
Definition: Swagger.qm.dox.h:2049
string type
Required. The type of the parameter.
Definition: Swagger.qm.dox.h:2009
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:2023
items schema object for non-body parameters
Definition: Swagger.qm.dox.h:2477
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:2494
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:2122
hash< auto > headers
A hash of headers that are (can be) sent with the response.
Definition: Swagger.qm.dox.h:2141
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:2135
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:2126
hash examples
A hash of example response messages.
Definition: Swagger.qm.dox.h:2151
contains the possible responses for an operation
Definition: Swagger.qm.dox.h:2090
hash< string, ResponseObject > responses
Definition: Swagger.qm.dox.h:2104
ResponseObject defaultResp
Definition: Swagger.qm.dox.h:2097
constructor(string path, string method, hash< auto > oh, SwaggerSchema swagger)
Constructor.
defines an object in a schema
Definition: Swagger.qm.dox.h:2265
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:2387
constructor(string name, hash< auto > oh, SwaggerSchema swagger, *string hash_str, *bool require_items) public auto getExampleValue()
private constructor; use newSchemaObject() instead
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:2269
auto additionalProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.4.
Definition: Swagger.qm.dox.h:2316
static SchemaObject newSchemaObject(string name, hash< auto > oh, SwaggerSchema swagger, *bool require_items)
returns a SchemaObject for the schema definition; resolves references
*int maxProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.1.
Definition: Swagger.qm.dox.h:2294
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:2279
bool nullable
extension that allows types to be nullable
Definition: Swagger.qm.dox.h:2302
*string discriminator
Adds support for polymorphism.
Definition: Swagger.qm.dox.h:2343
const ScalarTypes
valid scalar types
Definition: Swagger.qm.dox.h:2383
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:2322
*int minProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.2.
Definition: Swagger.qm.dox.h:2297
auto defaultVal
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2.
Definition: Swagger.qm.dox.h:2291
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:2427
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:2276
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:2309
*ExternalDocumentationObject externalDocs
Additional external documentation for this schema.
Definition: Swagger.qm.dox.h:2377
*XmlObject xml
This MAY be used only on properties schemas. It has no effect on root schemas.
Definition: Swagger.qm.dox.h:2374
bool readOnly
Relevant only for Schema "properties" definitions. Declares the property as "read only".
Definition: Swagger.qm.dox.h:2353
*SchemaObject items
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.1.
Definition: Swagger.qm.dox.h:2288
*string title
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.1.
Definition: Swagger.qm.dox.h:2282
auto example
A free-form property to include an example of an instance for this schema.
Definition: Swagger.qm.dox.h:2380
*string desc
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.1.
Definition: Swagger.qm.dox.h:2285
Lists the available scopes for an OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2652
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:2659
constructor(hash< auto > oh)
Constructor.
Allows the definition of a security scheme that can be used by the operations.
Definition: Swagger.qm.dox.h:2586
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:2590
*string desc
A short description for security scheme.
Definition: Swagger.qm.dox.h:2593
*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:2619
*ScopesObject scopes
The available scopes for the OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2635
*string inLoc
The location of the API key. Valid values are "query" or "header".
Definition: Swagger.qm.dox.h:2605
*string name
The name of the header or query parameter to be used.
Definition: Swagger.qm.dox.h:2599
*string flow
The flow used by the OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2613
*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:2625
Contact information for the exposed API.
Definition: Swagger.qm.dox.h:1332
constructor(hash< auto > oh)
Constructor.
*string name
The identifying name of the contact person/organization.
Definition: Swagger.qm.dox.h:1336
*string url
The URL pointing to the contact information. MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1339
*string email
The email address of the contact person/organization. MUST be in the format of an email address.
Definition: Swagger.qm.dox.h:1342
The object provides metadata about the API. The metadata can be used by the clients if needed,...
Definition: Swagger.qm.dox.h:1299
string version
Required. Provides the version of the application API (not to be confused with the specification vers...
Definition: Swagger.qm.dox.h:1312
constructor(hash< auto > oh)
Constructor.
string title
Required. The title of the application.
Definition: Swagger.qm.dox.h:1303
*LicenseObject license
The license information for the exposed API.
Definition: Swagger.qm.dox.h:1318
*ContactObject contact
The contact information for the exposed API.
Definition: Swagger.qm.dox.h:1315
*string termsOfService
The Terms of Service for the API.
Definition: Swagger.qm.dox.h:1309
*string desc
A short description of the application. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1306
License information for the exposed API.
Definition: Swagger.qm.dox.h:1355
constructor(hash< auto > oh)
Constructor.
string name
Required. The license name used for the API.
Definition: Swagger.qm.dox.h:1359
*string url
A URL to the license used for the API. MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1362
Base class for the Swagger specification objects, wrapping the vendor extensions.
Definition: Swagger.qm.dox.h:312
initialize(hash< auto > oh)
Initialize.
hash< auto > vendorExtensions
Allows extensions to the Swagger Schema.
Definition: Swagger.qm.dox.h:320
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:1559
list< string > schemes
The transfer protocol for the operation.
Definition: Swagger.qm.dox.h:1640
*string desc
A verbose explanation of the operation behavior. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1578
hash< string, bool > produces
A hash of MIME types (strings) the operation can produce.
Definition: Swagger.qm.dox.h:1613
*ExternalDocumentationObject externalDocs
Additional external documentation for this operation.
Definition: Swagger.qm.dox.h:1588
string path
the URI path for the operation
Definition: Swagger.qm.dox.h:1563
*string summary
A short summary of what the operation does.
Definition: Swagger.qm.dox.h:1575
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:1566
AbstractParameterObject body
body parameter; if defined for this operation, formData parameter will be excluded
Definition: Swagger.qm.dox.h:1627
*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:1685
ResponsesObject responses
Required. The list of possible responses as they are returned from executing this operation.
Definition: Swagger.qm.dox.h:1633
list tags
A list of tags (strings or TagObjects) for API documentation control.
Definition: Swagger.qm.dox.h:1572
*string operationId
Unique string used to identify the operation.
Definition: Swagger.qm.dox.h:1597
hash< string, AbstractParameterObject > formData
formData parameter; if defined for this operation, body parameter will be excluded
Definition: Swagger.qm.dox.h:1630
list< hash< string, list< string > > > security
A declaration of which security schemes are applied for this operation.
Definition: Swagger.qm.dox.h:1655
hash< string, bool > consumes
A list of MIME types (strings) the operation can consume.
Definition: Swagger.qm.dox.h:1605
constructor(string path, string method, hash< auto > oh, SwaggerSchema swagger)
Constructor.
Holds the relative paths to the individual endpoints.
Definition: Swagger.qm.dox.h:1382
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:1399
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:1390
*PathComponent wildcard
if there is a wildcard to a PathComponent
Definition: Swagger.qm.dox.h:1393
string pfx
path prefix
Definition: Swagger.qm.dox.h:1387
*PathItemObject pio
the PathItemObject associated with this path (if any)
Definition: Swagger.qm.dox.h:1396
Describes the operations available on a single path.
Definition: Swagger.qm.dox.h:1485
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:1494
hash< string, OperationObject > operations
A hash of OperationObjects correspoding to different methods.
Definition: Swagger.qm.dox.h:1523
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:1509
constructor(string path, hash< auto > oh, SwaggerSchema swagger)
Constructor.
This class stores the path tree for URI path matching.
Definition: Swagger.qm.dox.h:1439
*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:1444
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:345
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:478
*bool exclusiveMin
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.
Definition: Swagger.qm.dox.h:358
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:373
*float multipleOf
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.1.
Definition: Swagger.qm.dox.h:385
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:405
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:370
*int minLength
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2.
Definition: Swagger.qm.dox.h:364
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:349
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:505
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:468
*int maxLength
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1.
Definition: Swagger.qm.dox.h:361
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:355
*bool uniqueItems
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.4.
Definition: Swagger.qm.dox.h:376
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:352
*string pattern
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.3.
Definition: Swagger.qm.dox.h:367
Used for loading the Swagger definitions.
Definition: Swagger.qm.dox.h:545
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:604
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:1015
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:1273
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:1122
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:1195
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:935
hash< string, bool > produces
A set of MIME types (strings) the APIs can produce.
Definition: Swagger.qm.dox.h:657
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:853
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:1250
hash< string, hash< string, SchemaObject > > so_map
maps name -> SHA1 hash of the config -> schema objects for recursive references
Definition: Swagger.qm.dox.h:732
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:738
*string def_path
the default path to use when retrieving external schema references
Definition: Swagger.qm.dox.h:721
hash< string, softlist< string > > security
A declaration of which security schemes are applied for the API as a whole.
Definition: Swagger.qm.dox.h:695
hash< string, ResponseObject > responses
Response definitions that can be used across operations. This property does not define global respons...
Definition: Swagger.qm.dox.h:675
*ExternalDocumentationObject externalDocs
Additional external documentation.
Definition: Swagger.qm.dox.h:710
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:726
*string basePath
The base path on which the API is served, which is relative to the host.
Definition: Swagger.qm.dox.h:635
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:729
hash< string, SecuritySchemeObject > securityDefinitions
Security scheme definitions that can be used across the specification.
Definition: Swagger.qm.dox.h:681
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:918
SchemaObject processDefinition(string key, auto value)
Processes a schema definition.
string swaggerSpec
Swagger Specification version being used.
Definition: Swagger.qm.dox.h:612
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:1052
InfoObject info
Required. Provides metadata about the API. The metadata can be used by the clients if needed.
Definition: Swagger.qm.dox.h:615
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:718
const SwaggerOptions
SwaggerSchema options.
Definition: Swagger.qm.dox.h:713
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:870
*string host
The host (name or IP) serving the API.
Definition: Swagger.qm.dox.h:627
hash< string, bool > consumes
A set of MIME types (strings) the APIs can consume.
Definition: Swagger.qm.dox.h:650
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:1226
hash< string, bool > schemes
The transfer protocol of the API.
Definition: Swagger.qm.dox.h:643
PathsObject paths
Required. The available paths and operations for the API.
Definition: Swagger.qm.dox.h:618
list< TagObject > tags
A list of tags used by the specification with additional metadata.
Definition: Swagger.qm.dox.h:707
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:2241
constructor(hash< auto > oh)
Constructor.
*ExternalDocumentationObject externalDocs
Additional external documentation for this tag.
Definition: Swagger.qm.dox.h:2251
*string desc
A short description for the tag. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:2248
string name
Required. The name of the tag.
Definition: Swagger.qm.dox.h:2245
A metadata object that allows for more fine-tuned XML model definitions.
Definition: Swagger.qm.dox.h:2541
*string ns
The URL of the namespace definition. Value SHOULD be in the form of a URL.
Definition: Swagger.qm.dox.h:2555
constructor(hash< auto > oh)
Constructor.
*string prefix
The prefix to be used for the name.
Definition: Swagger.qm.dox.h:2558
bool wrapped
MAY be used only for an array definition. Signifies whether the array is wrapped (for example,...
Definition: Swagger.qm.dox.h:2568
*string name
Replaces the name of the element/attribute used for the described schema property.
Definition: Swagger.qm.dox.h:2552
bool attribute
Declares whether the property definition translates to an attribute instead of an element....
Definition: Swagger.qm.dox.h:2561
const True
const False
string sprintf(string fmt,...)
main namespace for all public Swagger declarations
Definition: Swagger.qm.dox.h:235
const CollectionFormats
allowed collection formats
Definition: Swagger.qm.dox.h:244
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:1736
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:1819
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:239
const ValidStringFormatsHash
A hash of valid string type formats.
Definition: Swagger.qm.dox.h:256
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:1768
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:254
const ParameterCollectionFormats
valid parameter collection formats
Definition: Swagger.qm.dox.h:248
const SerializationModules
modules available for data serialization and/or deserialization
Definition: Swagger.qm.dox.h:302
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:241
const ValidIntFormatsHash
A hash of valid integer type formats.
Definition: Swagger.qm.dox.h:252
const MimeDataTypes
supported mime types for de/serializing data
Definition: Swagger.qm.dox.h:267
const MimeContentTypes
MIME types for data serialization.
Definition: Swagger.qm.dox.h:305
const ValidIntFormats
Valid integer type formats.
Definition: Swagger.qm.dox.h:237
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:259
*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:1826
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:308