Qore Swagger Module Reference 2.2.0
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
239namespace Swagger {
246
248const LM_LAX_COLLECTIONFORMAT = (1 << 1);
249
252
255
257const LM_ALL = ...;
258
260
262const ValidIntFormats = ("int32", "int64");
264const ValidNumberFormats = ("double", "float");
266const ValidStringFormats = ("binary", "byte", "date", "date-time", "password");
267
270
271
274
275
277const ValidIntFormatsHash = map {$1: True}, ValidIntFormats;
282
285 "serialize": \make_yaml(),
286 "serialize_verbose": string sub (auto val) {return make_yaml(val, BlockStyle);},
287 "deserialize": \parse_yaml(),
288 "module": "yaml",
289};
290
293%ifndef NoJson
294 MimeTypeJson: (
295 "serialize": \make_json(),
296 "serialize_verbose": string sub (auto val) {return make_json(val, JGF_ADD_FORMATTING);},
297 "deserialize": \parse_json(),
298 "module": "json",
299 ),
300%endif
301%ifndef NoYaml
302 // issue #3699: more YAML MIME types must be supported
303 MimeTypeYaml: YamlSerialization,
304 MimeTypeYamlRpc: YamlSerialization,
305 "text/yaml": YamlSerialization,
306 "application/yaml": YamlSerialization,
307%endif
308%ifndef NoXml
309 MimeTypeXmlApp: (
310 "serialize": \make_xml(),
311 "serialize_verbose": string sub (auto val) {return make_xml(val, XGF_ADD_FORMATTING);},
312 "deserialize": \parse_xml(),
313 "module": "xml",
314 ),
315%endif
316 # Content-Type: application/x-www-form-urlencoded
317 MimeTypeFormUrlEncoded: (
318 "serialize": \mime_get_form_urlencoded_string(),
319 "serialize_verbose": \mime_get_form_urlencoded_string(),
320 "deserialize": \mime_parse_form_urlencoded_string(),
321 ),
322 # Content-Type: multipart/form-data (handled manually)
323 MimeTypeMultipartFormData: {},
324};
325
327const SerializationModules = keys (map {$1.module: True}, MimeDataTypes.iterator(), $1.module);
328
331
333const ValidSchemes = ("http", "https", "ws", "wss");
334const ValidSchemesHash = map {$1: True}, ValidSchemes;
335
338
339public:
341
346
349
350
352
355 constructor(hash<auto> oh);
356
357
360
361
363
366 initialize(hash<auto> oh);
367};
368
371
372public:
374 *float maximum;
375
377 *float minimum;
378
381
384
387
390
392 *string pattern;
393
396
399
402
404
407 hash<string, bool> enum;
408
411
413
416 constructor(string objType, hash<auto> oh);
417
418
421
422
424protected:
425 auto getExampleValue(string type, *string format);
426public:
427
428
430 private check(bool serialize, bool request, string type, *string format, *SchemaObject items, string path,
431 string method, string name, reference<auto> value) {
432 // accept a single value for an array (= one-element list)
433 if (type == 'array');
434 else {
435 checkIntern(serialize, request, type, format, path, method, name, value, \value);
436 }
437 }
438
439protected:
440 checkStringIntern(string path, string method, string name, string value);
441public:
442
443
444 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
445 string name, list<auto> v, reference<list> value) {
446 if (type != "list" && type != "any")
447 throw "SCHEMA-VALIDATION-ERROR", sprintf("Parameter %y for path %y and method %y is an array (%y), but "
448 "the expected type is %y", name, path, method, v, type);
449 }
450
451 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
452 string name, hash<auto> v, reference<hash> value) {
453 if (type != "file" && type != "any")
454 throw "SCHEMA-VALIDATION-ERROR", sprintf("Parameter %y for path %y and method %y is an object (%y), but "
455 "the expected type is %y", name, path, method, v, type);
456 }
457
458 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
459 string name, int v, reference<auto> value) {
460 // NOTE: "number" also accepts "int"
461 if (type == 'number');
462
463 if (type != "integer" && type != "any")
464 throwInvalidType(name, "integer", type, v);
465 if (exists maximum);
466
467
468 if (exists minimum);
469
470
471 if (enum && !enum{value})
472 throw "SCHEMA-VALIDATION-ERROR",
473 sprintf("Parameter %y for path %y and method %y does not fit the enumerated values (enum: %y, actual: %d)",
474 name, path, method, keys enum, value);
475 }
476
477protected:
478 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, number v, reference<number> value);
479public:
480
481
482protected:
483 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, float v, reference<number> value);
484public:
485
486
487protected:
488 checkInternNumber(bool serialize, bool request, string type, *string format, string path, string method, string name, auto v, reference<auto> value);
489public:
490
491
493 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
494 string name, binary v, reference value) {
495 if (type != "string" && type != "any")
496 throwInvalidType(name, "string", type, v);
497
498 if (serialize);
499
500 }
501
503 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
504 string name, string v, reference<auto> value) {
505 if (type != 'string' && type != 'any');
506
507
508 if (serialize);
509 # https://xml2rfc.tools.ietf.org//rfc/html/rfc3339.html#anchor14 if (value.typeCode() == NT_STRING);
510
511 }
512
514protected:
515 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, date v, reference value);
516public:
517
518
519protected:
520 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, bool v, reference<bool> value);
521public:
522
523
524protected:
525 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, nothing v, reference<nothing> value);
526public:
527
528
530 private checkArrayParam(bool serialize, bool request, SchemaObject items, string path, string method, string name,
531 reference<softlist<auto>> value) {
532 if (exists maxItems && value.size() > maxItems)
533 throw "SCHEMA-VALIDATION-ERROR",
534 sprintf("Parameter %y for path %y and method %y has too many items (maxItems: %d, actual: %d)",
535 name, path, method, maxItems, value.size());
536 if (exists minItems && value.size() < minItems)
537 throw "SCHEMA-VALIDATION-ERROR",
538 sprintf("Parameter %y for path %y and method %y has too few items (minItems: %d, actual: %d)",
539 name, path, method, minItems, value.size());
540
541 // check array element types
542 if (!uniqueItems || items.type != 'array');
543 else {
544 // perform slow array uniqueness check
545 list<auto> uniqueItems = ();
546 foreach auto val in (\value) {
547 items.check(serialize, request, path, method, name, \val);
548 if (uniqueItems.contains(val))
549 throw "SCHEMA-VALIDATION-ERROR",
550 sprintf("%s %s: Array parameter %y does not have unique items",
551 method, path, name);
552 uniqueItems += val;
553 }
554 }
555 }
556
558protected:
559 static throwInvalidType(string name, string actual, string expected, auto value);
560public:
561
562
564
566 static bool checkValueType(reference<auto> value, string type);
567};
568
571
572public:
574
590 static SwaggerSchema fromString(string swaggerSpecification, *bool json, *hash<auto> opts);
591
593
609 static SwaggerSchema fromFile(string filepath, *hash<auto> opts);
610
612
631 static SwaggerSchema fromUrl(string url, *bool json, *hash<auto> opts);
632
634
643 static hash<auto> parseSchemaContent(string filepath, string str);
644
646 static hash<auto> parseSchemaSource(string str, string ser);
647
649 static string detectSourceEncoding(string str);
650};
651
653class SwaggerSchema : public ObjectBase,public AbstractRestSchemaValidator {
654
655public:
657
662
665
668
670
676 *string host;
677
679
684 *string basePath;
685
687
692 hash<string, bool> schemes;
693
695
699 hash<string, bool> consumes;
700
702
706 hash<string, bool> produces;
707
709
712 hash<string, SchemaObject> definitions();
713
715
718 hash<string, AbstractParameterObject> parameters();
719
721
724 hash<string, ResponseObject> responses;
725
727
730 hash<string, SecuritySchemeObject> securityDefinitions;
731
733
744 hash<string, softlist<string>> security;
745
747
756 list<TagObject> tags;
757
760
762 const SwaggerOptions = ...;
763
764
765protected:
768
770 *string def_path;
771
773
776
778 string hash_str;
779
782
784 hash<string, hash<string, SchemaObject>> so_map;
785
786public:
787
788private:
791
792public:
793
795
814 constructor(string schema_source, hash<auto> oh, *hash<auto> opts) ;
815
816
818
837 constructor(Logger logger, string schema_source, hash<auto> oh, *hash<auto> opts) : ObjectBase(oh),
838 AbstractRestSchemaValidator(logger);
839
840
842protected:
843 constructorIntern(string schema_source, hash<auto> oh, *hash<auto> opts);
844public:
845
846
847 *int getParseFlags();
848
849
850 *SchemaObject tryGetSchemaObject(string name, hash<auto> oh, reference<string> hash_str);
851
852
853 cacheSchemaObject(string name, string hash_str, SchemaObject so);
854
855
857
859 SchemaObject resolveSchemaObject(string name, string refstr, hash<auto> oh);
860
861
863
865 ParameterItemsSchemaObject resolveParameterItemsSchemaObject(string name, string refstr, hash<auto> oh);
866
867
869
871 AbstractParameterObject resolveParameter(string name, string refstr, hash<auto> oh);
872
873
875
877 ResponseObject resolveResponse(string name, string refstr, hash<auto> oh);
878
879
881
885protected:
886 string getHashImpl();
887public:
888
889
891
895protected:
897public:
898
899
901
914 private hash<RestSchemaValidator::RestRequestClientInfo> processRequestImpl(string method, string path, auto body,
915 *hash<auto> headers, *softlist<string> content_types) {
916 return processRequestIntern(method, path, body, headers, content_types, compact_serialization);
917 }
918
920
931 private hash<RestSchemaValidator::RestRequestServerInfo> parseRequestImpl(string method, string path,
932 *data http_body, reference<hash> headers) {
933 auto body;
934 // deserialize body according to Content-Type
935 if (exists http_body);
936
937
938 // path must be absolute for matching to work correctly
939 if (path ==1)
940 path = "/" + path;
941
942 // remove basePath if present; note that "basePath" must always have a leading / if set
943 fixPath(\path);
944
945 hash<UriQueryInfo> h = parse_uri_query(path);
946 method = method.lwr();
947 PathItemObject pio = paths.match(h.method);
948 OperationObject op = pio.getOperation(method, h.method);
949
950 op.parseRequest(pio, \h, \body, \headers);
951 return <RestRequestServerInfo>{
952 "path": h.method,
953 "query": h.params,
954 "path_args": h.path_params,
955 "body": body,
956 };
957 }
958
960
979 private hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, auto response_body,
980 *hash<auto> headers, *softlist<string> content_types) {
981 return processResponseIntern(method, path, code, response_body, headers, content_types,
983 }
984
986
996 private hash<RestSchemaValidator::RestResponseClientInfo> parseResponseImpl(string method, string path, int code,
997 *data response_body, hash<auto> hdr) {
998 // remove basePath if present
999 fixPath(\path);
1000
1001 method = method.lwr();
1002 PathItemObject pio = paths.match(path);
1003 OperationObject op = pio.getOperation(method, path);
1004
1005 hash<RestResponseClientInfo> rv((
1006 "code": code,
1007 "hdr": hdr,
1008 ));
1009
1010 *string content = hdr."content-type" ?? hdr."Content-Type";
1011
1012 // deserialize body according to Content-Type
1013 if (exists response_body && content);
1014
1015
1016 hash<string, bool> mime_types;
1017 op.validateResponse(method, path, pio, code, \rv.body, \mime_types, False);
1018
1019 if (content && !mime_types{content})
1020 throw "DESERIALIZATION-ERROR", sprintf("%s %s: content type %y is not accepted by this operation; "
1021 "accepted content types: %y", method.upr(), path, content, keys mime_types);
1022
1023 return rv;
1024 }
1025
1027protected:
1028 fixPath(reference<string> path);
1029public:
1030
1031
1033
1035protected:
1036 hash<string, list<string>> getPathOperationHashImpl();
1037public:
1038
1039
1041
1045protected:
1047public:
1048
1049
1051
1053protected:
1055public:
1056
1057
1059
1064protected:
1065 hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
1066public:
1067
1068
1070
1076 private hash<RestSchemaValidator::RestExampleRequestInfo> getExampleRequestImpl(string method, string path,
1077 *softlist<string> content_types) {
1078 // remove basePath if present
1079 fixPath(\path);
1080
1081 method = method.lwr();
1082 PathItemObject pio = paths.match(path);
1083 OperationObject op = pio.getOperation(method, path);
1084
1085 auto body;
1086 hash<RestExampleRequestInfo> rv = op.getExampleRequest(method, path, pio, self, \body);
1087 if (exists body);
1088
1089
1090 return rv;
1091 }
1092
1094
1100protected:
1101 hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
1102public:
1103
1104
1106
1113 private hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code,
1114 *softlist<string> content_types) {
1115 // remove basePath if present
1116 fixPath(\path);
1117
1118 method = method.lwr();
1119 PathItemObject pio = paths.match(path);
1120 OperationObject op = pio.getOperation(method, path);
1121
1122 auto body;
1123 hash<RestExampleResponseInfo> rv = op.getExampleResponse(method, path, code, \body);
1124 if (exists body);
1125
1126
1127 return rv;
1128 }
1129
1131
1133protected:
1134 hash<auto> getExternalReference(string refstr);
1135public:
1136
1137
1139
1143protected:
1144 AbstractDataProvider getDataProviderImpl(HTTPClient rest);
1145public:
1146
1147
1149
1153protected:
1155public:
1156
1157
1159
1163protected:
1165public:
1166
1167
1169
1183 private:internal hash<RestSchemaValidator::RestRequestClientInfo> processRequestIntern(string method, string path,
1184 auto body, *hash<auto> headers, *softlist<string> content_types, bool compact_serialization) {
1185 // remove basePath if present
1186 fixPath(\path);
1187
1188 hash<UriQueryInfo> h = parse_uri_query(path);
1189
1190 // find path item object and operation
1191 method = method.lwr();
1192 PathItemObject pio = paths.match(h.method);
1193 OperationObject op = pio.getOperation(method, h.method);
1194
1195 // perform validation
1196 hash<string, bool> mime_types;
1197 op.validateRequest(True, pio, \h, \body, \headers, \mime_types);
1198
1199 hash<RestRequestClientInfo> rv((
1200 "uri_path": h.method,
1201 ));
1202
1203 if (op.produces);
1204
1205
1206 // add the basePath to the request
1207 if (exists basePath);
1208
1209
1210 // rebuild URI query after processing
1211 if (h.params);
1212
1213
1214 if (!body);
1215
1216
1217 if (!exists content_types);
1218
1219
1220 foreach string content in (content_types);
1221
1222
1223 // check if the \c Content-Type header is already set
1224 if (checkRequestContentTypeHeader(\rv, body, headers));
1225
1226
1227 if (content_types == MimeContentTypes);
1228 else {
1229 throw "SERIALIZATION-ERROR", sprintf("%s %s: message body cannot be serialized; requested MIME type(s): "
1230 "%y; available MIME types: %y; available serialization modules: %y", method.upr(), path,
1231 content_types, mime_types, SerializationModules);
1232 }
1233 }
1234
1236
1256 private:internal hash<HttpResponseInfo> processResponseIntern(string method, string path, int code,
1257 auto response_body, *hash<auto> headers, *softlist<string> content_types, bool compact_serialization) {
1258 // find path item object and operation
1259 method = method.lwr();
1260 PathItemObject pio = paths.match(path);
1261 OperationObject op = pio.getOperation(method, path);
1262
1263 // perform validation
1264 hash<string, bool> mime_types;
1265 op.validateResponse(method, path, pio, code, \response_body, \mime_types);
1266
1267 hash<HttpResponseInfo> rv((
1268 "code": code,
1269 "hdr": headers,
1270 ));
1271
1272 if (exists response_body);
1273
1274
1275 return rv;
1276 }
1277
1279
1287 private:internal bool checkRequestContentTypeHeader(reference<hash<RestRequestClientInfo>> req, auto body,
1288 *hash<auto> headers) {
1289 // quickly return if body is not in data format
1290 if (body.typeCode() != NT_BINARY && body.typeCode() != NT_STRING)
1291 return False;
1292
1293 // try to find \c Content-Type header
1294 *list<string> ct = map $1, keys headers, $1 ==1i;
1295
1296 // if found and it's not one of the default ones, use it
1297 if (ct && ct.size() == 1 && !MimeDataTypes{headers{ct[0]}});
1298
1299 return False;
1300 }
1301
1303
1311 private:internal bool checkResponseContentTypeHeader(reference<hash<HttpResponseInfo>> resp, auto body,
1312 *hash<auto> headers) {
1313 // quickly return if body is not in data format
1314 if (body.typeCode() != NT_BINARY && body.typeCode() != NT_STRING)
1315 return False;
1316
1317 // try to find \c Content-Type header
1318 *list<string> ct = map $1, keys headers, $1 ==1i;
1319
1320 // if found, use it and don't serialize the body
1321 if (ct && ct.size() == 1);
1322
1323 return False;
1324 }
1325
1327
1334 private:internal bool checkResponseTextPlain(reference<hash<HttpResponseInfo>> resp, auto body,
1335 hash<string, bool> mime_types, *list<auto> content_types) {
1336 // quickly return if body is not string
1337 if (body.typeCode() != NT_STRING)
1338 return False;
1339
1340 // return if text/plain is not allowed for this operation
1341 if (!mime_types."text/plain")
1342 return False;
1343
1344 if (content_types);
1345
1346
1347 resp.body = body;
1348 resp.hdr."Content-Type" = "text/plain";
1349 return True;
1350 }
1351
1353private:
1354 SchemaObject processDefinition(string key, auto value);
1355public:
1356
1357};
1358
1360class InfoObject : public ObjectBase {
1361
1362public:
1364 string title;
1365
1367 *string desc;
1368
1371
1373 string version;
1374
1377
1380
1382
1388 constructor(hash<auto> oh) ;
1389
1390};
1391
1394
1395public:
1397 *string name;
1398
1400 *string url;
1401
1403 *string email;
1404
1406
1411 constructor(hash<auto> oh) ;
1412
1413};
1414
1417
1418public:
1420 string name;
1421
1423 *string url;
1424
1426
1432 constructor(hash<auto> oh) ;
1433
1434};
1435
1437
1444
1445public:
1446protected:
1448 string pfx;
1449
1451 string name;
1452
1455
1458
1460 hash<string, PathComponent> paths;
1461
1462public:
1463
1465 constructor(hash<auto> oh, string pfx, SwaggerSchema swagger);
1466
1467
1469protected:
1470 constructor(string full_path, list<auto> l, int offset, hash<auto> oh);
1471public:
1472
1473
1475protected:
1476 add(string full_path, list<auto> l, int offset, hash<auto> oh, SwaggerSchema swagger);
1477public:
1478
1479
1481
1483 PathItemObject match(list<auto> path);
1484
1485
1487
1489 *PathItemObject tryMatch(list<auto> path);
1490
1491
1493
1495 getPathOperationHash(reference<hash<string, list<string>>> h);
1496
1497};
1498
1500class PathsObject : public ObjectBase {
1501
1502public:
1503protected:
1506
1507public:
1508
1510
1518 constructor(hash<auto> oh, SwaggerSchema swagger) ;
1519
1520
1522
1524 PathItemObject match(string path);
1525
1526
1528
1531
1532
1534
1536 hash<string, list<string>> getPathOperationHash();
1537
1538};
1539
1541
1547
1548public:
1550
1555 *string ref;
1556
1558
1567 hash<string, AbstractParameterObject> parameters();
1568
1571
1572protected:
1574
1584 hash<string, OperationObject> operations;
1585
1586public:
1587
1589
1598 constructor(string path, hash<auto> oh, SwaggerSchema swagger) ;
1599
1600
1602
1609 OperationObject getOperation(string method, string path);
1610
1611
1613
1615 softlist getMethods();
1616
1617};
1618
1621
1622public:
1624 string path;
1625
1627 string method;
1628
1630
1633 list tags;
1634
1636 *string summary;
1637
1639 *string desc;
1640
1642
1646 bool deprec = False;
1647
1650
1652
1659
1661
1666 hash<string, bool> consumes;
1667
1669
1674 hash<string, bool> produces;
1675
1677
1685 hash<string, AbstractParameterObject> parameters();
1686
1689
1691 hash<string, AbstractParameterObject> formData;
1692
1695
1697
1701 list<string> schemes;
1702
1704
1716 list<hash<string, list<string>>> security;
1717
1719
1728 constructor(string path, string method, hash<auto> oh, SwaggerSchema swagger) ;
1729
1730
1732 *data getRequestBody(PathItemObject pio, auto body, reference<hash<auto>> headers);
1733
1734
1736
1746 validateRequest(bool serialize, PathItemObject pio, reference<hash<UriQueryInfo>> h, reference<auto> body,
1747 reference<hash> headers, *reference<hash<string, bool>> mime_types) {
1748 // check query parameters
1749 foreach string key in (keys h.params);
1750
1751
1752 // check header parameters
1753 foreach string key in (keys headers);
1754
1755
1756 // check body parameters
1757 {
1758 *AbstractParameterObject body_po = self.body ?? pio.body;
1759 if (body_po) {
1760 body_po.check(serialize, True, path, method, "body", \body);
1761 } else if (formData) {
1762 foreach hash<auto> i in (formData.pairIterator()) {
1763 i.value.check(serialize, True, path, method, "formData." + i.key, \body{i.key});
1764 }
1765 } else if (body) {
1766 error("SCHEMA-VALIDATION-ERROR", "No message body is accepted; body keys passed: %y", keys body);
1767 }
1768 }
1769
1770 // check path parameters
1771 foreach string param in (path =~ x/{([^}]+)}/g);
1772
1773
1774 // check for missing required parameters
1775 checkMissingParams(h, headers, body, parameters);
1776 checkMissingParams(h, headers, body, pio.parameters, parameters);
1777
1778 if (consumes);
1779
1780 };
1781
1783
1793 parseRequest(PathItemObject pio, reference<hash<UriQueryInfo>> h, reference<auto> body, reference<hash> headers);
1794
1795
1797 validateResponse(string method, string path, PathItemObject pio, int http_code, reference<auto> response_body,
1798 reference<hash<string, bool>> mime_types, bool deserialize = True) {
1799 *ResponseObject res = getResponse(http_code);
1800 if (res.schema);
1801 else if (exists res && exists response_body);
1802
1803
1804 if (produces);
1805
1806 }
1807
1809
1816 hash<RestQoreExampleCodeInfo> getQoreExampleRequest(string method, string path, PathItemObject pio, SwaggerSchema swagger);
1817
1818
1820
1829 hash<RestSchemaValidator::RestExampleRequestInfo> getExampleRequest(string method, string path,
1830 PathItemObject pio, SwaggerSchema swagger, reference rbody) {
1831 hash<RestExampleRequestInfo> rv();
1832
1834 hash<auto> query;
1835
1836 getQoreExampleParams(\query, \rv.hdr, parameters);
1837 getQoreExampleParams(\query, \rv.hdr, pio.parameters, parameters);
1838
1839 rv.request_uri = sprintf("%s %s HTTP/1.1", method.upr(),
1840 make_uri_query(cast<hash<UriQueryInfo>>({"method": path, "params": query})));
1841
1843 *BodyParameter body_po = body ?? pio.body;
1844 if (body_po)
1845 rbody = body_po.getExampleValue();
1846
1847 return rv;
1848 }
1849
1851
1858 hash<RestQoreExampleCodeInfo> getQoreExampleResponse(string method, string path, int code);
1859
1860
1862
1870 hash<RestExampleResponseInfo> getExampleResponse(string method, string path, int code, reference<auto> body);
1871
1872
1873 private getQoreExampleParams(reference<hash<auto>> query, reference<hash<auto>> headers,
1874 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1875 foreach hash<auto> ph in (parameters.pairIterator());
1876
1877 }
1878
1880 private doDefaultParams(reference<hash<UriQueryInfo>> h, reference<hash> headers, reference<auto> body,
1881 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1882 foreach hash<auto> ph in (parameters.pairIterator());
1883
1884 }
1885
1887 private checkMissingParams(hash<UriQueryInfo> h, *hash<auto> headers, auto body,
1888 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1889 foreach hash<auto> ph in (parameters.pairIterator());
1890
1891 }
1892
1894
1896protected:
1898public:
1899
1900
1902protected:
1903 error(string err, string fmt);
1904public:
1905
1906}
1907
1909class ExternalDocumentationObject : public ObjectBase {
1910
1911public:
1913 *string desc;
1914
1916 string url;
1917
1919
1925 constructor(hash<auto> oh) ;
1926
1927};
1928
1930
1966class AbstractParameterObject : public ObjectBase {
1967
1968public:
1970
1977 string name;
1978
1980
1984 string inLoc;
1985
1987 *string desc;
1988
1990
1995 bool required = False;
1996
1997protected:
1998 const OtherParameterMap = ...;
1999
2000
2001public:
2002
2004
2011 constructor(hash<auto> oh, *int opt_flags) ;
2012
2013
2015 abstract check(bool serialize, bool request, string path, string method, string name, reference value);
2016
2019
2020
2022 static AbstractParameterObject newParameter(string name, hash<auto> oh, SwaggerSchema swagger);
2023};
2024
2027
2028public:
2031
2033
2040 constructor(hash<auto> oh, SwaggerSchema swagger) ;
2041
2042
2044 check(bool serialize, bool request, string path, string method, string name, reference value);
2045
2046
2048 string getQoreExample(reference<hash<RestQoreExampleCodeInfo>> rv);
2049
2050
2051 // returns an example value for a REST API call
2052 auto getExampleValue();
2053
2054};
2055
2057class OtherParameter : public AbstractParameterObject,public SchemaBase {
2058
2059public:
2061
2070 string type;
2071
2073 *string format;
2074
2076
2081 bool allowEmptyValue = False;
2082
2085
2087
2101
2103
2111
2113 const ParameterTypes = ...;
2114
2115
2117
2127 constructor(string name, hash<auto> oh, SwaggerSchema swagger)
2128 ;
2129
2130
2132 check(bool serialize, bool request, string path, string method, string name, reference<auto> value);
2133
2134
2137
2138
2141
2142
2144protected:
2145 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2146public:
2147
2148};
2149
2151class ResponsesObject : public ObjectBase {
2152
2153public:
2154 // The documentation of responses other than the ones declared for specific HTTP response codes.
2159
2160 // A hash mapping HTTP status codes to @ref ResponseObject "ResponseObjects".
2165 hash<string, ResponseObject> responses;
2166
2168
2178 constructor(string path, string method, hash<auto> oh, SwaggerSchema swagger) ;
2179
2180};
2181
2183class ResponseObject : public ObjectBase {
2184
2185public:
2187 string desc;
2188
2190
2197
2199
2202 hash<auto> headers;
2203
2205
2213
2215
2223protected:
2224 constructor(string key, hash<auto> oh, SwaggerSchema swagger) ;
2225public:
2226
2227
2229
2238 static ResponseObject newResponse(string key, hash<auto> oh, SwaggerSchema swagger);
2239};
2240
2242class HeaderObject : public ObjectBase,public SchemaBase {
2243
2244public:
2246 *string desc;
2247
2249
2253 string type;
2254
2256 *string format;
2257
2260
2262
2272
2274
2281
2283
2291 constructor(hash<auto> oh, SwaggerSchema swagger) ;
2292
2293
2295protected:
2296 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2297public:
2298
2299};
2300
2302class TagObject : public ObjectBase {
2303
2304public:
2306 string name;
2307
2309 *string desc;
2310
2313
2315
2321 constructor(hash<auto> oh) ;
2322
2323};
2324
2326class SchemaObject : public ObjectBase,public SchemaBase {
2327
2328public:
2330 string name;
2331
2333
2337 string type;
2338
2340 *string format;
2341
2343 *string title;
2344
2346 *string desc;
2347
2350
2353
2356
2359
2361
2363 bool nullable = False;
2364
2366
2370 hash<string, SchemaObject> properties;
2371
2373
2378
2380
2383 hash<string, bool> required;
2384
2386
2405
2407
2414 bool readOnly = False;
2415
2417
2425 list<SchemaObject> allOf();
2426
2428
2436
2439
2442
2444 const ScalarTypes = ...;
2445
2446
2448 const ReferenceTypes = ...;
2449
2450
2452
2465protected:
2466 constructor(string name, hash<auto> oh, SwaggerSchema swagger, *string hash_str, *bool require_items)
2467public:
2468
2469
2471 string getQoreExample(reference<hash<RestQoreExampleCodeInfo>> rv, string name, bool decl);
2472
2473
2474 // returns an example value for a REST API call
2476
2477
2479 check(bool serialize, bool request, string path, string method, string name, reference<auto> value);
2480
2481
2482protected:
2483 checkObjectProperty(string name, string prop);
2484public:
2485
2486
2488 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
2489 string name, hash<auto> v, reference<hash<auto>> value) {
2490 if (type != "object" && type != "any")
2491 throwInvalidType(name, "object", type, v);
2492
2493 // check "allOf" schemas, if any
2494 map $1.checkIntern(serialize, request, type, NOTHING, path, method, name, v, \value), allOf;
2495
2496 /*
2497 If additionalProperties is set to true, any number of additionalProperties may be present of any data
2498 type.
2499 If additionalProperties is a schema, additional properties (beyond what are defined in ‘properties’) are
2500 allowed and must match the schema
2501 */
2502 // check properties in this schema definition
2503 if (!additionalProperties && type != 'any');
2504
2505 // check for missing required properties
2506 foreach string prop in (keys required);
2507
2508 //printf("SchemaObject::checkIntern() %y type: %y val: %y self: %N\n", name, type, value, self);
2509 }
2510
2512protected:
2513 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2514public:
2515
2516
2518
2529 static SchemaObject newSchemaObject(string name, hash<auto> oh, SwaggerSchema swagger, *bool require_items);
2530
2532
2534 static SchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger);
2535};
2536
2539
2540public:
2542
2556
2558
2570protected:
2571 constructor(string name, hash<auto> oh, SwaggerSchema swagger) ;
2572public:
2573
2574
2576
2588 static ParameterItemsSchemaObject newSchemaObject(string name, hash<auto> oh, SwaggerSchema swagger);
2589
2591
2593 static ParameterItemsSchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger);
2594};
2595
2597
2602class XmlObject : public ObjectBase {
2603
2604public:
2606
2613 *string name;
2614
2616 *string ns;
2617
2619 *string prefix;
2620
2622 bool attribute = False;
2623
2625
2629 bool wrapped = False;
2630
2632
2637 constructor(hash<auto> oh) ;
2638
2639};
2640
2642
2647class SecuritySchemeObject : public ObjectBase {
2648
2649public:
2651 string type;
2652
2654 *string desc;
2655
2657
2660 *string name;
2661
2663
2666 *string inLoc;
2667
2669
2674 *string flow;
2675
2677
2681
2683
2686 *string tokenUrl;
2687
2689
2697
2699
2708 constructor(hash<auto> oh) ;
2709
2710};
2711
2713class ScopesObject : public ObjectBase {
2714
2715public:
2717
2720 hash<string, string> fields;
2721
2723
2728 constructor(hash<auto> oh) ;
2729
2730};
2731}
2732
2733// private namespace for internal definitions
2734namespace Priv {
2735 // a set of string values
2736 const SwaggerListToStringSet = -1;
2737 // a set of any type that can be converted to a string
2738 const SwaggerListToAnySet = -2;
2739 const SwaggerListToHashOfStrings = -3;
2740
2741 const TypeMap = ...;
2742
2743
2745
2755 required_field(string objType, hash<auto> oh, string name, int typeCode, reference<auto> target, *int opt_flags);
2756
2757
2759
2769 required_field(string objType, hash<auto> oh, string name, hash<string, bool> typeCodes, reference<auto> target);
2770
2771
2773
2784 bool optional_field(string objType, hash<auto> oh, string name, int typeCode, reference<auto> target,
2785 *int opt_flags) {
2786 if (!oh.hasKey(name))
2787 return False;
2788 auto val = oh{name};
2789 if (check_type_code(objType, oh, name, val, typeCode, opt_flags));
2790
2791 get_value(objType, name, typeCode, val, \target);
2792 return True;
2793 }
2794
2796
2807 bool optional_field(string objType, hash<auto> oh, string name, hash<string, bool> typeCodes,
2808 reference<auto> target) {
2809 if (!oh.hasKey(name))
2810 return False;
2811 auto val = oh{name};
2812 if (!typeCodes{val.typeCode()})
2813 throw "INVALID-FIELD-TYPE", sprintf("%s Object%s: %y field has invalid type %y", objType,
2814 oh.name ? sprintf(" %y", oh.name) : "", name, val.type());
2815 get_value(objType, name, val.typeCode(), val, \target);
2816 return True;
2817 }
2818
2820 *bool check_type_code(string objType, hash<auto> oh, string name, auto val, int typeCode, *int opt_flags);
2821
2822
2824 get_value(string objType, string name, int typeCode, auto val, reference<auto> target);
2825
2826
2828 string get_qore_type(string name, string type, *string format, *SchemaObject items);
2829
2830}
Describes a single operation parameter.
Definition: Swagger.qm.dox.h:1966
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:1977
auto getDefaultValue()
returns the default value of the parameter (default: NOTHING)
string inLoc
Required. The location of the parameter.
Definition: Swagger.qm.dox.h:1984
*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:1987
bool required
Determines whether this parameter is mandatory.
Definition: Swagger.qm.dox.h:1995
constructor(hash< auto > oh, *int opt_flags)
Constructor.
AbstractParameterObject specialization for "body" parameters.
Definition: Swagger.qm.dox.h:2026
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:2030
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:1909
string url
Required. The URL for the target documentation. Value MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1916
*string desc
A short description of the target documentation. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1913
constructor(hash< auto > oh)
Constructor.
describes a single HTTP header
Definition: Swagger.qm.dox.h:2242
*string collectionFormat
Determines the format of the array if type array is used.
Definition: Swagger.qm.dox.h:2271
*SchemaObject items
Required if type is "array". Describes the type of items in the array.
Definition: Swagger.qm.dox.h:2259
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:2280
*string format
The extending format for the previously mentioned type. See Data Type Formats for further details.
Definition: Swagger.qm.dox.h:2256
*string desc
A short description of the header.
Definition: Swagger.qm.dox.h:2246
string type
Required. The type of the object.
Definition: Swagger.qm.dox.h:2253
constructor(hash< auto > oh, SwaggerSchema swagger)
Constructor.
AbstractParameterObject specialization for parameters other than "body".
Definition: Swagger.qm.dox.h:2057
const ParameterTypes
valid parameter types
Definition: Swagger.qm.dox.h:2113
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:2100
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:2073
bool allowEmptyValue
Sets the ability to pass empty-valued parameters.
Definition: Swagger.qm.dox.h:2081
auto defaultVal
Declares the value of the parameter that the server will use if none is provided.
Definition: Swagger.qm.dox.h:2110
string type
Required. The type of the parameter.
Definition: Swagger.qm.dox.h:2070
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:2084
items schema object for non-body parameters
Definition: Swagger.qm.dox.h:2538
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:2555
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:2183
hash< auto > headers
A hash of headers that are (can be) sent with the response.
Definition: Swagger.qm.dox.h:2202
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:2196
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:2187
hash examples
A hash of example response messages.
Definition: Swagger.qm.dox.h:2212
contains the possible responses for an operation
Definition: Swagger.qm.dox.h:2151
hash< string, ResponseObject > responses
Definition: Swagger.qm.dox.h:2165
ResponseObject defaultResp
Definition: Swagger.qm.dox.h:2158
constructor(string path, string method, hash< auto > oh, SwaggerSchema swagger)
Constructor.
defines an object in a schema
Definition: Swagger.qm.dox.h:2326
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:2448
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:2330
auto additionalProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.4.
Definition: Swagger.qm.dox.h:2377
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:2355
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:2340
bool nullable
extension that allows types to be nullable
Definition: Swagger.qm.dox.h:2363
*string discriminator
Adds support for polymorphism.
Definition: Swagger.qm.dox.h:2404
const ScalarTypes
valid scalar types
Definition: Swagger.qm.dox.h:2444
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:2383
*int minProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.2.
Definition: Swagger.qm.dox.h:2358
auto defaultVal
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2.
Definition: Swagger.qm.dox.h:2352
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:2488
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:2337
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:2370
*ExternalDocumentationObject externalDocs
Additional external documentation for this schema.
Definition: Swagger.qm.dox.h:2438
*XmlObject xml
This MAY be used only on properties schemas. It has no effect on root schemas.
Definition: Swagger.qm.dox.h:2435
bool readOnly
Relevant only for Schema "properties" definitions. Declares the property as "read only".
Definition: Swagger.qm.dox.h:2414
*SchemaObject items
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.1.
Definition: Swagger.qm.dox.h:2349
*string title
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.1.
Definition: Swagger.qm.dox.h:2343
auto example
A free-form property to include an example of an instance for this schema.
Definition: Swagger.qm.dox.h:2441
*string desc
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.1.
Definition: Swagger.qm.dox.h:2346
Lists the available scopes for an OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2713
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:2720
constructor(hash< auto > oh)
Constructor.
Allows the definition of a security scheme that can be used by the operations.
Definition: Swagger.qm.dox.h:2647
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:2651
*string desc
A short description for security scheme.
Definition: Swagger.qm.dox.h:2654
*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:2680
*ScopesObject scopes
The available scopes for the OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2696
*string inLoc
The location of the API key. Valid values are "query" or "header".
Definition: Swagger.qm.dox.h:2666
*string name
The name of the header or query parameter to be used.
Definition: Swagger.qm.dox.h:2660
*string flow
The flow used by the OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2674
*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:2686
Contact information for the exposed API.
Definition: Swagger.qm.dox.h:1393
constructor(hash< auto > oh)
Constructor.
*string name
The identifying name of the contact person/organization.
Definition: Swagger.qm.dox.h:1397
*string url
The URL pointing to the contact information. MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1400
*string email
The email address of the contact person/organization. MUST be in the format of an email address.
Definition: Swagger.qm.dox.h:1403
The object provides metadata about the API. The metadata can be used by the clients if needed,...
Definition: Swagger.qm.dox.h:1360
string version
Required. Provides the version of the application API (not to be confused with the specification vers...
Definition: Swagger.qm.dox.h:1373
constructor(hash< auto > oh)
Constructor.
string title
Required. The title of the application.
Definition: Swagger.qm.dox.h:1364
*LicenseObject license
The license information for the exposed API.
Definition: Swagger.qm.dox.h:1379
*ContactObject contact
The contact information for the exposed API.
Definition: Swagger.qm.dox.h:1376
*string termsOfService
The Terms of Service for the API.
Definition: Swagger.qm.dox.h:1370
*string desc
A short description of the application. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1367
License information for the exposed API.
Definition: Swagger.qm.dox.h:1416
constructor(hash< auto > oh)
Constructor.
string name
Required. The license name used for the API.
Definition: Swagger.qm.dox.h:1420
*string url
A URL to the license used for the API. MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1423
Base class for the Swagger specification objects, wrapping the vendor extensions.
Definition: Swagger.qm.dox.h:337
initialize(hash< auto > oh)
Initialize.
hash< auto > vendorExtensions
Allows extensions to the Swagger Schema.
Definition: Swagger.qm.dox.h:345
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:1620
list< string > schemes
The transfer protocol for the operation.
Definition: Swagger.qm.dox.h:1701
*string desc
A verbose explanation of the operation behavior. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1639
hash< string, bool > produces
A hash of MIME types (strings) the operation can produce.
Definition: Swagger.qm.dox.h:1674
*ExternalDocumentationObject externalDocs
Additional external documentation for this operation.
Definition: Swagger.qm.dox.h:1649
string path
the URI path for the operation
Definition: Swagger.qm.dox.h:1624
*string summary
A short summary of what the operation does.
Definition: Swagger.qm.dox.h:1636
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:1627
AbstractParameterObject body
body parameter; if defined for this operation, formData parameter will be excluded
Definition: Swagger.qm.dox.h:1688
*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:1746
ResponsesObject responses
Required. The list of possible responses as they are returned from executing this operation.
Definition: Swagger.qm.dox.h:1694
list tags
A list of tags (strings or TagObjects) for API documentation control.
Definition: Swagger.qm.dox.h:1633
*string operationId
Unique string used to identify the operation.
Definition: Swagger.qm.dox.h:1658
hash< string, AbstractParameterObject > formData
formData parameter; if defined for this operation, body parameter will be excluded
Definition: Swagger.qm.dox.h:1691
list< hash< string, list< string > > > security
A declaration of which security schemes are applied for this operation.
Definition: Swagger.qm.dox.h:1716
hash< string, bool > consumes
A list of MIME types (strings) the operation can consume.
Definition: Swagger.qm.dox.h:1666
constructor(string path, string method, hash< auto > oh, SwaggerSchema swagger)
Constructor.
Holds the relative paths to the individual endpoints.
Definition: Swagger.qm.dox.h:1443
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:1460
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:1451
*PathComponent wildcard
if there is a wildcard to a PathComponent
Definition: Swagger.qm.dox.h:1454
string pfx
path prefix
Definition: Swagger.qm.dox.h:1448
*PathItemObject pio
the PathItemObject associated with this path (if any)
Definition: Swagger.qm.dox.h:1457
Describes the operations available on a single path.
Definition: Swagger.qm.dox.h:1546
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:1555
hash< string, OperationObject > operations
A hash of OperationObjects correspoding to different methods.
Definition: Swagger.qm.dox.h:1584
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:1570
constructor(string path, hash< auto > oh, SwaggerSchema swagger)
Constructor.
This class stores the path tree for URI path matching.
Definition: Swagger.qm.dox.h:1500
*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:1505
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:370
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:503
*bool exclusiveMin
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.
Definition: Swagger.qm.dox.h:383
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:398
*float multipleOf
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.1.
Definition: Swagger.qm.dox.h:410
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:430
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:395
*int minLength
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2.
Definition: Swagger.qm.dox.h:389
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:374
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:530
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:493
*int maxLength
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1.
Definition: Swagger.qm.dox.h:386
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:380
*bool uniqueItems
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.4.
Definition: Swagger.qm.dox.h:401
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:377
*string pattern
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.3.
Definition: Swagger.qm.dox.h:392
Used for loading the Swagger definitions.
Definition: Swagger.qm.dox.h:570
static string detectSourceEncoding(string str)
tries to determine the Swagger schema source encoding automatically
static SwaggerSchema fromString(string swaggerSpecification, *bool json, *hash< auto > opts)
Load Swagger definition from a string.
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 fromUrl(string url, *bool json, *hash< auto > opts)
Load Swagger definition from a URL or file path.
static SwaggerSchema fromFile(string filepath, *hash< auto > opts)
Load Swagger definition from a file.
This is the root document object for the API specification. It combines what previously was the Resou...
Definition: Swagger.qm.dox.h:653
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:1076
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:1334
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:1183
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:1256
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:996
hash< string, bool > produces
A set of MIME types (strings) the APIs can produce.
Definition: Swagger.qm.dox.h:706
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:914
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:1311
hash< string, hash< string, SchemaObject > > so_map
maps name -> SHA1 hash of the config -> schema objects for recursive references
Definition: Swagger.qm.dox.h:784
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:790
*string def_path
the default path to use when retrieving external schema references
Definition: Swagger.qm.dox.h:770
hash< string, softlist< string > > security
A declaration of which security schemes are applied for the API as a whole.
Definition: Swagger.qm.dox.h:744
hash< string, ResponseObject > responses
Response definitions that can be used across operations. This property does not define global respons...
Definition: Swagger.qm.dox.h:724
*ExternalDocumentationObject externalDocs
Additional external documentation.
Definition: Swagger.qm.dox.h:759
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:775
*string basePath
The base path on which the API is served, which is relative to the host.
Definition: Swagger.qm.dox.h:684
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:778
hash< string, SecuritySchemeObject > securityDefinitions
Security scheme definitions that can be used across the specification.
Definition: Swagger.qm.dox.h:730
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:979
*int opt_flags
parse option flags
Definition: Swagger.qm.dox.h:781
SchemaObject processDefinition(string key, auto value)
Processes a schema definition.
string swaggerSpec
Swagger Specification version being used.
Definition: Swagger.qm.dox.h:661
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:1113
InfoObject info
Required. Provides metadata about the API. The metadata can be used by the clients if needed.
Definition: Swagger.qm.dox.h:664
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:767
const SwaggerOptions
SwaggerSchema options.
Definition: Swagger.qm.dox.h:762
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:931
*string host
The host (name or IP) serving the API.
Definition: Swagger.qm.dox.h:676
hash< string, bool > consumes
A set of MIME types (strings) the APIs can consume.
Definition: Swagger.qm.dox.h:699
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:1287
hash< string, bool > schemes
The transfer protocol of the API.
Definition: Swagger.qm.dox.h:692
PathsObject paths
Required. The available paths and operations for the API.
Definition: Swagger.qm.dox.h:667
list< TagObject > tags
A list of tags used by the specification with additional metadata.
Definition: Swagger.qm.dox.h:756
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:2302
constructor(hash< auto > oh)
Constructor.
*ExternalDocumentationObject externalDocs
Additional external documentation for this tag.
Definition: Swagger.qm.dox.h:2312
*string desc
A short description for the tag. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:2309
string name
Required. The name of the tag.
Definition: Swagger.qm.dox.h:2306
A metadata object that allows for more fine-tuned XML model definitions.
Definition: Swagger.qm.dox.h:2602
*string ns
The URL of the namespace definition. Value SHOULD be in the form of a URL.
Definition: Swagger.qm.dox.h:2616
constructor(hash< auto > oh)
Constructor.
*string prefix
The prefix to be used for the name.
Definition: Swagger.qm.dox.h:2619
bool wrapped
MAY be used only for an array definition. Signifies whether the array is wrapped (for example,...
Definition: Swagger.qm.dox.h:2629
*string name
Replaces the name of the element/attribute used for the described schema property.
Definition: Swagger.qm.dox.h:2613
bool attribute
Declares whether the property definition translates to an attribute instead of an element....
Definition: Swagger.qm.dox.h:2622
const LM_IGNORE_INVALID_REQUIRED
parse option: ignore invalid "required" properties
Definition: Swagger.qm.dox.h:251
const LM_ALL
parse options: all options
Definition: Swagger.qm.dox.h:257
const LM_ACCEPT_INVALID_BODY_PARAMS
parse option: reconstruct invalid body parameters
Definition: Swagger.qm.dox.h:254
const LM_LAX_COLLECTIONFORMAT
parse option: allow collectionFormat on non-array types
Definition: Swagger.qm.dox.h:248
const LM_IGNORE_MISSING_REQUIRED
Definition: Swagger.qm.dox.h:245
const True
const False
string sprintf(string fmt,...)
main namespace for all public Swagger declarations
Definition: Swagger.qm.dox.h:239
const CollectionFormats
allowed collection formats
Definition: Swagger.qm.dox.h:269
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:1797
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:1880
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:264
const ValidStringFormatsHash
A hash of valid string type formats.
Definition: Swagger.qm.dox.h:281
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:1829
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:279
const ParameterCollectionFormats
valid parameter collection formats
Definition: Swagger.qm.dox.h:273
const SerializationModules
modules available for data serialization and/or deserialization
Definition: Swagger.qm.dox.h:327
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:266
const ValidIntFormatsHash
A hash of valid integer type formats.
Definition: Swagger.qm.dox.h:277
const MimeDataTypes
supported mime types for de/serializing data
Definition: Swagger.qm.dox.h:292
const MimeContentTypes
MIME types for data serialization.
Definition: Swagger.qm.dox.h:330
const ValidIntFormats
Valid integer type formats.
Definition: Swagger.qm.dox.h:262
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:284
*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:1887
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:333