Qore Swagger Module Reference 2.0.10
Loading...
Searching...
No Matches
Swagger.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* Swagger.qm Copyright (C) 2017 - 2022 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
225namespace Swagger {
227const ValidIntFormats = ("int32", "int64");
229const ValidNumberFormats = ("double", "float");
231const ValidStringFormats = ("binary", "byte", "date", "date-time", "password");
232
235
236
239
240
242const ValidIntFormatsHash = map {$1: True}, ValidIntFormats;
247
250 "serialize": \make_yaml(),
251 "serialize_verbose": string sub (auto val) {return make_yaml(val, BlockStyle);},
252 "deserialize": \parse_yaml(),
253 "module": "yaml",
254};
255
258%ifndef NoJson
259 MimeTypeJson: (
260 "serialize": \make_json(),
261 "serialize_verbose": string sub (auto val) {return make_json(val, JGF_ADD_FORMATTING);},
262 "deserialize": \parse_json(),
263 "module": "json",
264 ),
265%endif
266%ifndef NoYaml
267 // issue #3699: more YAML MIME types must be supported
268 MimeTypeYaml: YamlSerialization,
269 MimeTypeYamlRpc: YamlSerialization,
270 "text/yaml": YamlSerialization,
271 "application/yaml": YamlSerialization,
272%endif
273%ifndef NoXml
274 MimeTypeXmlApp: (
275 "serialize": \make_xml(),
276 "serialize_verbose": string sub (auto val) {return make_xml(val, XGF_ADD_FORMATTING);},
277 "deserialize": \parse_xml(),
278 "module": "xml",
279 ),
280%endif
281 # Content-Type: application/x-www-form-urlencoded
282 MimeTypeFormUrlEncoded: (
283 "serialize": \mime_get_form_urlencoded_string(),
284 "serialize_verbose": \mime_get_form_urlencoded_string(),
285 "deserialize": \mime_parse_form_urlencoded_string(),
286 ),
287 # Content-Type: multipart/form-data (handled manually)
288 MimeTypeMultipartFormData: {},
289};
290
292const SerializationModules = keys (map {$1.module: True}, MimeDataTypes.iterator(), $1.module);
293
296
298const ValidSchemes = ("http", "https", "ws", "wss");
299const ValidSchemesHash = map {$1: True}, ValidSchemes;
300
303
304public:
306
311
314
315
317
320 constructor(hash<auto> oh);
321
322
325
326
328
331 initialize(hash<auto> oh);
332};
333
336
337public:
339 *float maximum;
340
342 *float minimum;
343
346
349
352
355
357 *string pattern;
358
361
364
367
369
372 hash<string, bool> enum;
373
376
378
381 constructor(string objType, hash<auto> oh);
382
383
386
387
389protected:
390 auto getExampleValue(string type, *string format);
391public:
392
393
395 private check(bool serialize, bool request, string type, *string format, *SchemaObject items, string path,
396 string method, string name, reference<auto> value) {
397 // accept a single value for an array (= one-element list)
398 if (type == 'array');
399 else {
400 checkIntern(serialize, request, type, format, path, method, name, value, \value);
401 }
402 }
403
404protected:
405 checkStringIntern(string path, string method, string name, string value);
406public:
407
408
409 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
410 string name, list<auto> v, reference<list> value) {
411 if (type != "list" && type != "any")
412 throw "SCHEMA-VALIDATION-ERROR", sprintf("Parameter %y for path %y and method %y is an array (%y), but "
413 "the expected type is %y", name, path, method, v, type);
414 }
415
416 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
417 string name, hash<auto> v, reference<hash> value) {
418 if (type != "file" && type != "any")
419 throw "SCHEMA-VALIDATION-ERROR", sprintf("Parameter %y for path %y and method %y is an object (%y), but "
420 "the expected type is %y", name, path, method, v, type);
421 }
422
423 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
424 string name, int v, reference<auto> value) {
425 // NOTE: "number" also accepts "int"
426 if (type == 'number');
427
428 if (type != "integer" && type != "any")
429 throwInvalidType(name, "integer", type, v);
430 if (exists maximum);
431
432
433 if (exists minimum);
434
435
436 if (enum && !enum{value})
437 throw "SCHEMA-VALIDATION-ERROR",
438 sprintf("Parameter %y for path %y and method %y does not fit the enumerated values (enum: %y, actual: %d)",
439 name, path, method, keys enum, value);
440 }
441
442protected:
443 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, number v, reference<number> value);
444public:
445
446
447protected:
448 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, float v, reference<number> value);
449public:
450
451
452protected:
453 checkInternNumber(bool serialize, bool request, string type, *string format, string path, string method, string name, auto v, reference<auto> value);
454public:
455
456
458 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
459 string name, binary v, reference value) {
460 if (type != "string" && type != "any")
461 throwInvalidType(name, "string", type, v);
462
463 if (serialize);
464
465 }
466
468 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
469 string name, string v, reference<auto> value) {
470 if (type != 'string' && type != 'any');
471
472
473 if (serialize);
474 # https://xml2rfc.tools.ietf.org//rfc/html/rfc3339.html#anchor14 if (value.typeCode() == NT_STRING);
475
476 }
477
479protected:
480 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, date v, reference value);
481public:
482
483
484protected:
485 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, bool v, reference<bool> value);
486public:
487
488
489protected:
490 checkIntern(bool serialize, bool request, string type, *string format, string path, string method, string name, nothing v, reference<nothing> value);
491public:
492
493
495 private checkArrayParam(bool serialize, bool request, SchemaObject items, string path, string method, string name,
496 reference<softlist<auto>> value) {
497 if (exists maxItems && value.size() > maxItems)
498 throw "SCHEMA-VALIDATION-ERROR",
499 sprintf("Parameter %y for path %y and method %y has too many items (maxItems: %d, actual: %d)",
500 name, path, method, maxItems, value.size());
501 if (exists minItems && value.size() < minItems)
502 throw "SCHEMA-VALIDATION-ERROR",
503 sprintf("Parameter %y for path %y and method %y has too few items (minItems: %d, actual: %d)",
504 name, path, method, minItems, value.size());
505
506 // check array element types
507 if (!uniqueItems || items.type != 'array');
508 else {
509 // perform slow array uniqueness check
510 list<auto> uniqueItems = ();
511 foreach auto val in (\value) {
512 items.check(serialize, request, path, method, name, \val);
513 if (uniqueItems.contains(val))
514 throw "SCHEMA-VALIDATION-ERROR",
515 sprintf("%s %s: Array parameter %y does not have unique items",
516 method, path, name);
517 uniqueItems += val;
518 }
519 }
520 }
521
523protected:
524 static throwInvalidType(string name, string actual, string expected, auto value);
525public:
526
527
529
531 static bool checkValueType(reference<auto> value, string type);
532};
533
536
537public:
539
547 static SwaggerSchema fromString(string swaggerSpecification, *bool json);
548
550
558 static SwaggerSchema fromFile(string filepath);
559
561
572 static SwaggerSchema fromUrl(string url, *bool json);
573
575
584 static hash<auto> parseSchemaContent(string filepath, string str);
585
587 static hash<auto> parseSchemaSource(string str, string ser);
588
590 static string detectSourceEncoding(string str);
591};
592
594class SwaggerSchema : public ObjectBase,public AbstractRestSchemaValidator {
595
596public:
598
603
606
609
611
617 *string host;
618
620
625 *string basePath;
626
628
633 hash<string, bool> schemes;
634
636
640 hash<string, bool> consumes;
641
643
647 hash<string, bool> produces;
648
650
653 hash<string, SchemaObject> definitions();
654
656
659 hash<string, AbstractParameterObject> parameters();
660
662
665 hash<string, ResponseObject> responses;
666
668
671 hash<string, SecuritySchemeObject> securityDefinitions;
672
674
685 hash<string, softlist<string>> security;
686
688
697 list<TagObject> tags;
698
701
703 const SwaggerOptions = ...;
704
705
706protected:
709
711 *string def_path;
712
714
717
719 string hash_str;
720
722 hash<string, hash<string, SchemaObject>> so_map;
723
724public:
725
726private:
729
730public:
731
733
749 constructor(string schema_source, hash<auto> oh, *hash<auto> opts) ;
750
751
753
769 constructor(Logger logger, string schema_source, hash<auto> oh, *hash<auto> opts) : ObjectBase(oh),
770 AbstractRestSchemaValidator(logger);
771
772
774protected:
775 constructorIntern(string schema_source, hash<auto> oh, *hash<auto> opts);
776public:
777
778
779 *SchemaObject tryGetSchemaObject(string name, hash<auto> oh, reference<string> hash_str);
780
781
782 cacheSchemaObject(string name, string hash_str, SchemaObject so);
783
784
786
788 SchemaObject resolveSchemaObject(string name, string refstr, hash<auto> oh);
789
790
792
794 ParameterItemsSchemaObject resolveParameterItemsSchemaObject(string name, string refstr, hash<auto> oh);
795
796
798
800 AbstractParameterObject resolveParameter(string name, string refstr, hash<auto> oh);
801
802
804
806 ResponseObject resolveResponse(string name, string refstr, hash<auto> oh);
807
808
810
814protected:
815 string getHashImpl();
816public:
817
818
820
824protected:
826public:
827
828
830
843 private hash<RestSchemaValidator::RestRequestClientInfo> processRequestImpl(string method, string path, auto body,
844 *hash<auto> headers, *softlist<string> content_types) {
845 return processRequestIntern(method, path, body, headers, content_types, compact_serialization);
846 }
847
849
860 private hash<RestSchemaValidator::RestRequestServerInfo> parseRequestImpl(string method, string path,
861 *data http_body, reference<hash> headers) {
862 auto body;
863 // deserialize body according to Content-Type
864 if (exists http_body);
865
866
867 // path must be absolute for matching to work correctly
868 if (path ==1)
869 path = "/" + path;
870
871 // remove basePath if present; note that "basePath" must always have a leading /
872 fixPath(\path);
873
874 hash<UriQueryInfo> h = parse_uri_query(path);
875 method = method.lwr();
876 PathItemObject pio = paths.match(h.method);
877 OperationObject op = pio.getOperation(method, h.method);
878
879 op.parseRequest(pio, \h, \body, \headers);
880 return <RestRequestServerInfo>{
881 "path": h.method,
882 "query": h.params,
883 "body": body,
884 };
885 }
886
888
907 private hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, auto response_body,
908 *hash<auto> headers, *softlist<string> content_types) {
909 return processResponseIntern(method, path, code, response_body, headers, content_types,
911 }
912
914
924 private hash<RestSchemaValidator::RestResponseClientInfo> parseResponseImpl(string method, string path, int code,
925 *data response_body, hash<auto> hdr) {
926 // remove basePath if present
927 fixPath(\path);
928
929 method = method.lwr();
930 PathItemObject pio = paths.match(path);
931 OperationObject op = pio.getOperation(method, path);
932
933 hash<RestResponseClientInfo> rv((
934 "code": code,
935 "hdr": hdr,
936 ));
937
938 *string content = hdr."content-type" ?? hdr."Content-Type";
939
940 // deserialize body according to Content-Type
941 if (exists response_body && content);
942
943
944 hash<string, bool> mime_types;
945 op.validateResponse(method, path, pio, code, \rv.body, \mime_types, False);
946
947 if (content && !mime_types{content})
948 throw "DESERIALIZATION-ERROR", sprintf("%s %s: content type %y is not accepted by this operation; "
949 "accepted content types: %y", method.upr(), path, content, keys mime_types);
950
951 return rv;
952 }
953
955protected:
956 fixPath(reference<string> path);
957public:
958
959
961
963protected:
964 hash<string, list<string>> getPathOperationHashImpl();
965public:
966
967
969
973protected:
975public:
976
977
979
981protected:
983public:
984
985
987
992protected:
993 hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
994public:
995
996
998
1004 private hash<RestSchemaValidator::RestExampleRequestInfo> getExampleRequestImpl(string method, string path,
1005 *softlist<string> content_types) {
1006 // remove basePath if present
1007 fixPath(\path);
1008
1009 method = method.lwr();
1010 PathItemObject pio = paths.match(path);
1011 OperationObject op = pio.getOperation(method, path);
1012
1013 auto body;
1014 hash<RestExampleRequestInfo> rv = op.getExampleRequest(method, path, pio, self, \body);
1015 if (exists body);
1016
1017
1018 return rv;
1019 }
1020
1022
1028protected:
1029 hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
1030public:
1031
1032
1034
1041 private hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code,
1042 *softlist<string> content_types) {
1043 // remove basePath if present
1044 fixPath(\path);
1045
1046 method = method.lwr();
1047 PathItemObject pio = paths.match(path);
1048 OperationObject op = pio.getOperation(method, path);
1049
1050 auto body;
1051 hash<RestExampleResponseInfo> rv = op.getExampleResponse(method, path, code, \body);
1052 if (exists body);
1053
1054
1055 return rv;
1056 }
1057
1059
1061protected:
1062 hash<auto> getExternalReference(string refstr);
1063public:
1064
1065
1067
1071protected:
1072 AbstractDataProvider getDataProviderImpl(HTTPClient rest);
1073public:
1074
1075
1077
1081protected:
1083public:
1084
1085
1087
1091protected:
1093public:
1094
1095
1097
1111 private:internal hash<RestSchemaValidator::RestRequestClientInfo> processRequestIntern(string method, string path,
1112 auto body, *hash<auto> headers, *softlist<string> content_types, bool compact_serialization) {
1113 // remove basePath if present
1114 fixPath(\path);
1115
1116 hash<UriQueryInfo> h = parse_uri_query(path);
1117
1118 // find path item object and operation
1119 method = method.lwr();
1120 PathItemObject pio = paths.match(h.method);
1121 OperationObject op = pio.getOperation(method, h.method);
1122
1123 // perform validation
1124 hash<string, bool> mime_types;
1125 op.validateRequest(True, pio, \h, \body, \headers, \mime_types);
1126
1127 hash<RestRequestClientInfo> rv((
1128 "uri_path": h.method,
1129 ));
1130
1131 if (op.produces);
1132
1133
1134 // add the basePath to the request
1135 if (exists basePath);
1136
1137
1138 // rebuild URI query after processing
1139 if (h.params);
1140
1141
1142 if (!body);
1143
1144
1145 if (!exists content_types);
1146
1147
1148 foreach string content in (content_types);
1149
1150
1151 // check if the \c Content-Type header is already set
1152 if (checkRequestContentTypeHeader(\rv, body, headers));
1153
1154
1155 if (content_types == MimeContentTypes);
1156 else {
1157 throw "SERIALIZATION-ERROR", sprintf("%s %s: message body cannot be serialized; requested MIME type(s): "
1158 "%y; available MIME types: %y; available serialization modules: %y", method.upr(), path,
1159 content_types, mime_types, SerializationModules);
1160 }
1161 }
1162
1164
1184 private:internal hash<HttpResponseInfo> processResponseIntern(string method, string path, int code,
1185 auto response_body, *hash<auto> headers, *softlist<string> content_types, bool compact_serialization) {
1186 // find path item object and operation
1187 method = method.lwr();
1188 PathItemObject pio = paths.match(path);
1189 OperationObject op = pio.getOperation(method, path);
1190
1191 // perform validation
1192 hash<string, bool> mime_types;
1193 op.validateResponse(method, path, pio, code, \response_body, \mime_types);
1194
1195 hash<HttpResponseInfo> rv((
1196 "code": code,
1197 "hdr": headers,
1198 ));
1199
1200 if (exists response_body);
1201
1202
1203 return rv;
1204 }
1205
1207
1215 private:internal bool checkRequestContentTypeHeader(reference<hash<RestRequestClientInfo>> req, auto body,
1216 *hash<auto> headers) {
1217 // quickly return if body is not in data format
1218 if (body.typeCode() != NT_BINARY && body.typeCode() != NT_STRING)
1219 return False;
1220
1221 // try to find \c Content-Type header
1222 *list<string> ct = map $1, keys headers, $1 ==1i;
1223
1224 // if found and it's not one of the default ones, use it
1225 if (ct && ct.size() == 1 && !MimeDataTypes{headers{ct[0]}});
1226
1227 return False;
1228 }
1229
1231
1239 private:internal bool checkResponseContentTypeHeader(reference<hash<HttpResponseInfo>> resp, auto body,
1240 *hash<auto> headers) {
1241 // quickly return if body is not in data format
1242 if (body.typeCode() != NT_BINARY && body.typeCode() != NT_STRING)
1243 return False;
1244
1245 // try to find \c Content-Type header
1246 *list<string> ct = map $1, keys headers, $1 ==1i;
1247
1248 // if found, use it and don't serialize the body
1249 if (ct && ct.size() == 1);
1250
1251 return False;
1252 }
1253
1255
1262 private:internal bool checkResponseTextPlain(reference<hash<HttpResponseInfo>> resp, auto body,
1263 hash<string, bool> mime_types, *list<auto> content_types) {
1264 // quickly return if body is not string
1265 if (body.typeCode() != NT_STRING)
1266 return False;
1267
1268 // return if text/plain is not allowed for this operation
1269 if (!mime_types."text/plain")
1270 return False;
1271
1272 if (content_types);
1273
1274
1275 resp.body = body;
1276 resp.hdr."Content-Type" = "text/plain";
1277 return True;
1278 }
1279
1281private:
1282 SchemaObject processDefinition(string key, auto value);
1283public:
1284
1285};
1286
1288class InfoObject : public ObjectBase {
1289
1290public:
1292 string title;
1293
1295 *string desc;
1296
1299
1301 string version;
1302
1305
1308
1310
1316 constructor(hash<auto> oh) ;
1317
1318};
1319
1322
1323public:
1325 *string name;
1326
1328 *string url;
1329
1331 *string email;
1332
1334
1339 constructor(hash<auto> oh) ;
1340
1341};
1342
1345
1346public:
1348 string name;
1349
1351 *string url;
1352
1354
1360 constructor(hash<auto> oh) ;
1361
1362};
1363
1365
1372
1373public:
1374protected:
1376 string pfx;
1377
1379 string name;
1380
1383
1386
1388 hash<string, PathComponent> paths;
1389
1390public:
1391
1393 constructor(hash<auto> oh, string pfx, SwaggerSchema swagger);
1394
1395
1397protected:
1398 constructor(string full_path, list<auto> l, int offset, hash<auto> oh);
1399public:
1400
1401
1403protected:
1404 add(string full_path, list<auto> l, int offset, hash<auto> oh, SwaggerSchema swagger);
1405public:
1406
1407
1409
1411 PathItemObject match(list<auto> path);
1412
1413
1415
1417 *PathItemObject tryMatch(list<auto> path);
1418
1419
1421
1423 getPathOperationHash(reference<hash<string, list<string>>> h);
1424
1425};
1426
1428class PathsObject : public ObjectBase {
1429
1430public:
1431protected:
1434
1435public:
1436
1438
1446 constructor(hash<auto> oh, SwaggerSchema swagger) ;
1447
1448
1450
1452 PathItemObject match(string path);
1453
1454
1456
1459
1460
1462
1464 hash<string, list<string>> getPathOperationHash();
1465
1466};
1467
1469
1475
1476public:
1478
1483 *string ref;
1484
1486
1495 hash<string, AbstractParameterObject> parameters();
1496
1499
1500protected:
1502
1512 hash<string, OperationObject> operations;
1513
1514public:
1515
1517
1526 constructor(string path, hash<auto> oh, SwaggerSchema swagger) ;
1527
1528
1530
1537 OperationObject getOperation(string method, string path);
1538
1539
1541
1543 softlist getMethods();
1544
1545};
1546
1549
1550public:
1552 string path;
1553
1555 string method;
1556
1558
1561 list tags;
1562
1564 *string summary;
1565
1567 *string desc;
1568
1570
1574 bool deprec = False;
1575
1578
1580
1587
1589
1594 hash<string, bool> consumes;
1595
1597
1602 hash<string, bool> produces;
1603
1605
1613 hash<string, AbstractParameterObject> parameters();
1614
1617
1619 hash<string, AbstractParameterObject> formData;
1620
1623
1625
1629 list<string> schemes;
1630
1632
1644 list<hash<string, list<string>>> security;
1645
1647
1656 constructor(string path, string method, hash<auto> oh, SwaggerSchema swagger) ;
1657
1658
1660 *data getRequestBody(PathItemObject pio, auto body, reference<hash<auto>> headers);
1661
1662
1664
1674 validateRequest(bool serialize, PathItemObject pio, reference<hash<UriQueryInfo>> h, reference<auto> body,
1675 reference<hash> headers, *reference<hash<string, bool>> mime_types) {
1676 // check query parameters
1677 foreach string key in (keys h.params);
1678
1679
1680 // check header parameters
1681 foreach string key in (keys headers);
1682
1683
1684 // check body parameters
1685 {
1686 *AbstractParameterObject body_po = self.body ?? pio.body;
1687 if (body_po) {
1688 body_po.check(serialize, True, path, method, "body", \body);
1689 } else if (formData) {
1690 foreach hash<auto> i in (formData.pairIterator()) {
1691 i.value.check(serialize, True, path, method, "formData." + i.key, \body{i.key});
1692 }
1693 } else if (body) {
1694 error("SCHEMA-VALIDATION-ERROR", "No message body is accepted; body keys passed: %y", keys body);
1695 }
1696 }
1697
1698 // check for missing required parameters
1699 checkMissingParams(h, headers, body, parameters);
1700 checkMissingParams(h, headers, body, pio.parameters, parameters);
1701
1702 if (consumes);
1703
1704 }
1705
1707
1717 parseRequest(PathItemObject pio, reference<hash<UriQueryInfo>> h, reference<auto> body, reference<hash> headers);
1718
1719
1721 validateResponse(string method, string path, PathItemObject pio, int http_code, reference<auto> response_body,
1722 reference<hash<string, bool>> mime_types, bool deserialize = True) {
1723 *ResponseObject res = getResponse(http_code);
1724 if (res.schema);
1725 else if (exists res && exists response_body);
1726
1727
1728 if (produces);
1729
1730 }
1731
1733
1740 hash<RestQoreExampleCodeInfo> getQoreExampleRequest(string method, string path, PathItemObject pio, SwaggerSchema swagger);
1741
1742
1744
1753 hash<RestSchemaValidator::RestExampleRequestInfo> getExampleRequest(string method, string path,
1754 PathItemObject pio, SwaggerSchema swagger, reference rbody) {
1755 hash<RestExampleRequestInfo> rv();
1756
1758 hash<auto> query;
1759
1760 getQoreExampleParams(\query, \rv.hdr, parameters);
1761 getQoreExampleParams(\query, \rv.hdr, pio.parameters, parameters);
1762
1763 rv.request_uri = sprintf("%s %s HTTP/1.1", method.upr(),
1764 make_uri_query(cast<hash<UriQueryInfo>>({"method": path, "params": query})));
1765
1767 *BodyParameter body_po = body ?? pio.body;
1768 if (body_po)
1769 rbody = body_po.getExampleValue();
1770
1771 return rv;
1772 }
1773
1775
1782 hash<RestQoreExampleCodeInfo> getQoreExampleResponse(string method, string path, int code);
1783
1784
1786
1794 hash<RestExampleResponseInfo> getExampleResponse(string method, string path, int code, reference<auto> body);
1795
1796
1797 private getQoreExampleParams(reference<hash<auto>> query, reference<hash<auto>> headers,
1798 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1799 foreach hash<auto> ph in (parameters.pairIterator());
1800
1801 }
1802
1804 private doDefaultParams(reference<hash<UriQueryInfo>> h, reference<hash> headers, reference<auto> body,
1805 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1806 foreach hash<auto> ph in (parameters.pairIterator());
1807
1808 }
1809
1811 private checkMissingParams(hash<UriQueryInfo> h, *hash<auto> headers, auto body,
1812 hash<string, AbstractParameterObject> parameters, *hash<string, AbstractParameterObject> child_params) {
1813 foreach hash<auto> ph in (parameters.pairIterator());
1814
1815 }
1816
1818
1820protected:
1822public:
1823
1824
1826protected:
1827 error(string err, string fmt);
1828public:
1829
1830};
1831
1834
1835public:
1837 *string desc;
1838
1840 string url;
1841
1843
1849 constructor(hash<auto> oh) ;
1850
1851};
1852
1854
1891
1892public:
1894
1901 string name;
1902
1904
1908 string inLoc;
1909
1911 *string desc;
1912
1914
1919 bool required = False;
1920
1921protected:
1922 const OtherParameterMap = ...;
1923
1924
1925public:
1926
1928
1935 constructor(hash<auto> oh) ;
1936
1937
1939 abstract check(bool serialize, bool request, string path, string method, string name, reference value);
1940
1943
1944
1946 static AbstractParameterObject newParameter(string name, hash<auto> oh, SwaggerSchema swagger);
1947};
1948
1951
1952public:
1955
1957
1964 constructor(hash<auto> oh, SwaggerSchema swagger) ;
1965
1966
1968 check(bool serialize, bool request, string path, string method, string name, reference value);
1969
1970
1972 string getQoreExample(reference<hash<RestQoreExampleCodeInfo>> rv);
1973
1974
1975 // returns an example value for a REST API call
1976 auto getExampleValue();
1977
1978};
1979
1982
1983public:
1985
1994 string type;
1995
1997 *string format;
1998
2000
2005 bool allowEmptyValue = False;
2006
2009
2011
2025
2027
2035
2037 const ParameterTypes = ...;
2038
2039
2041
2051 constructor(string name, hash<auto> oh, SwaggerSchema swagger)
2052 ;
2053
2054
2056 check(bool serialize, bool request, string path, string method, string name, reference<auto> value);
2057
2058
2061
2062
2065
2066
2068protected:
2069 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2070public:
2071
2072};
2073
2076
2077public:
2078 // The documentation of responses other than the ones declared for specific HTTP response codes.
2083
2084 // A hash mapping HTTP status codes to @ref ResponseObject "ResponseObjects".
2089 hash<string, ResponseObject> responses;
2090
2092
2102 constructor(string path, string method, hash<auto> oh, SwaggerSchema swagger) ;
2103
2104};
2105
2108
2109public:
2111 string desc;
2112
2114
2121
2123
2126 hash<auto> headers;
2127
2129
2137
2139
2147protected:
2148 constructor(string key, hash<auto> oh, SwaggerSchema swagger) ;
2149public:
2150
2151
2153
2162 static ResponseObject newResponse(string key, hash<auto> oh, SwaggerSchema swagger);
2163};
2164
2166class HeaderObject : public ObjectBase,public SchemaBase {
2167
2168public:
2170 *string desc;
2171
2173
2177 string type;
2178
2180 *string format;
2181
2184
2186
2196
2198
2205
2207
2215 constructor(hash<auto> oh, SwaggerSchema swagger) ;
2216
2217
2219protected:
2220 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2221public:
2222
2223};
2224
2226class TagObject : public ObjectBase {
2227
2228public:
2230 string name;
2231
2233 *string desc;
2234
2237
2239
2245 constructor(hash<auto> oh) ;
2246
2247};
2248
2250class SchemaObject : public ObjectBase,public SchemaBase {
2251
2252public:
2254 string name;
2255
2257
2261 string type;
2262
2264 *string format;
2265
2267 *string title;
2268
2270 *string desc;
2271
2274
2277
2280
2283
2285
2287 bool nullable = False;
2288
2290
2294 hash<string, SchemaObject> properties;
2295
2297
2302
2304
2307 hash<string, bool> required;
2308
2310
2329
2331
2338 bool readOnly = False;
2339
2341
2349 list<SchemaObject> allOf();
2350
2352
2360
2363
2366
2368 const ScalarTypes = ...;
2369
2370
2372 const ReferenceTypes = ...;
2373
2374
2376
2387protected:
2388 constructor(string name, hash<auto> oh, SwaggerSchema swagger, *string hash_str)
2389public:
2390
2391
2393 string getQoreExample(reference<hash<RestQoreExampleCodeInfo>> rv, string name, bool decl);
2394
2395
2396 // returns an example value for a REST API call
2398
2399
2401 check(bool serialize, bool request, string path, string method, string name, reference<auto> value);
2402
2403
2404protected:
2405 checkObjectProperty(string name, string prop);
2406public:
2407
2408
2410 private checkIntern(bool serialize, bool request, string type, *string format, string path, string method,
2411 string name, hash<auto> v, reference<hash<auto>> value) {
2412 if (type != "object" && type != "any")
2413 throwInvalidType(name, "object", type, v);
2414
2415 // check "allOf" schemas, if any
2416 map $1.checkIntern(serialize, request, type, NOTHING, path, method, name, v, \value), allOf;
2417
2418 /*
2419 If additionalProperties is set to true, any number of additionalProperties may be present of any data
2420 type.
2421 If additionalProperties is a schema, additional properties (beyond what are defined in ‘properties’) are
2422 allowed and must match the schema
2423 */
2424 // check properties in this schema definition
2425 if (!additionalProperties && type != 'any');
2426
2427 // check for missing required properties
2428 foreach string prop in (keys required);
2429
2430 //printf("SchemaObject::checkIntern() %y type: %y val: %y self: %N\n", name, type, value, self);
2431 }
2432
2434protected:
2435 static checkValueType(reference<auto> value, string type, *SchemaObject items, *string loc);
2436public:
2437
2438
2440
2451 static SchemaObject newSchemaObject(string name, hash<auto> oh, SwaggerSchema swagger);
2452
2454
2456 static SchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger);
2457};
2458
2461
2462public:
2464
2478
2480
2492protected:
2493 constructor(string name, hash<auto> oh, SwaggerSchema swagger) ;
2494public:
2495
2496
2498
2510 static ParameterItemsSchemaObject newSchemaObject(string name, hash<auto> oh, SwaggerSchema swagger);
2511
2513
2515 static ParameterItemsSchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger);
2516};
2517
2519
2524class XmlObject : public ObjectBase {
2525
2526public:
2528
2535 *string name;
2536
2538 *string ns;
2539
2541 *string prefix;
2542
2544 bool attribute = False;
2545
2547
2551 bool wrapped = False;
2552
2554
2559 constructor(hash<auto> oh) ;
2560
2561};
2562
2564
2570
2571public:
2573 string type;
2574
2576 *string desc;
2577
2579
2582 *string name;
2583
2585
2588 *string inLoc;
2589
2591
2596 *string flow;
2597
2599
2603
2605
2608 *string tokenUrl;
2609
2611
2619
2621
2630 constructor(hash<auto> oh) ;
2631
2632};
2633
2635class ScopesObject : public ObjectBase {
2636
2637public:
2639
2642 hash<string, string> fields;
2643
2645
2650 constructor(hash<auto> oh) ;
2651
2652};
2653};
2654
2655// private namespace for internal definitions
2656namespace Priv {
2657 // a set of string values
2658 const SwaggerListToStringSet = -1;
2659 // a set of any type that can be converted to a string
2660 const SwaggerListToAnySet = -2;
2661 const SwaggerListToHashOfStrings = -3;
2662
2663 const TypeMap = ...;
2664
2665
2667
2677 required_field(string objType, hash<auto> oh, string name, int typeCode, reference<auto> target);
2678
2679
2681
2691 required_field(string objType, hash<auto> oh, string name, hash<string, bool> typeCodes, reference<auto> target);
2692
2693
2695
2706 bool optional_field(string objType, hash<auto> oh, string name, int typeCode, reference<auto> target);
2707
2708
2710
2721 bool optional_field(string objType, hash<auto> oh, string name, hash<string, bool> typeCodes,
2722 reference<auto> target) {
2723 if (!oh.hasKey(name))
2724 return False;
2725 auto val = oh{name};
2726 if (!typeCodes{val.typeCode()})
2727 throw "INVALID-FIELD-TYPE", sprintf("%s Object%s: %y field has invalid type %y", objType,
2728 oh.name ? sprintf(" %y", oh.name) : "", name, val.type());
2729 get_value(objType, name, val.typeCode(), val, \target);
2730 return True;
2731 }
2732
2734 check_type_code(string objType, hash<auto> oh, string name, auto val, int typeCode);
2735
2736
2738 get_value(string objType, string name, int typeCode, auto val, reference<auto> target);
2739
2740
2742 string get_qore_type(string name, string type, *string format, *SchemaObject items);
2743
2744}
Describes a single operation parameter.
Definition: Swagger.qm.dox.h:1890
auto getDefaultValue()
returns the default value of the parameter (default: NOTHING)
constructor(hash< auto > oh)
Constructor.
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:1901
string inLoc
Required. The location of the parameter.
Definition: Swagger.qm.dox.h:1908
static AbstractParameterObject newParameter(string name, hash< auto > oh, SwaggerSchema swagger)
gets a concrete instance of an AbstractParameterObject
*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:1911
AbstractParameterObject specialization for "body" parameters.
Definition: Swagger.qm.dox.h:1950
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:1954
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.
Contact information for the exposed API.
Definition: Swagger.qm.dox.h:1321
constructor(hash< auto > oh)
Constructor.
*string name
The identifying name of the contact person/organization.
Definition: Swagger.qm.dox.h:1325
*string url
The URL pointing to the contact information. MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1328
*string email
The email address of the contact person/organization. MUST be in the format of an email address.
Definition: Swagger.qm.dox.h:1331
Allows referencing an external resource for extended documentation.
Definition: Swagger.qm.dox.h:1833
*string desc
A short description of the target documentation. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1837
constructor(hash< auto > oh)
Constructor.
string url
Required. The URL for the target documentation. Value MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1840
describes a single HTTP header
Definition: Swagger.qm.dox.h:2166
*string desc
A short description of the header.
Definition: Swagger.qm.dox.h:2170
*SchemaObject items
Required if type is "array". Describes the type of items in the array.
Definition: Swagger.qm.dox.h:2183
auto defaultVal
Declares the value of the header that the server will use if none is provided.
Definition: Swagger.qm.dox.h:2204
string type
Required. The type of the object.
Definition: Swagger.qm.dox.h:2177
*string format
The extending format for the previously mentioned type. See Data Type Formats for further details.
Definition: Swagger.qm.dox.h:2180
static checkValueType(reference< auto > value, string type, *SchemaObject items, *string loc)
validates default values
*string collectionFormat
Determines the format of the array if type array is used.
Definition: Swagger.qm.dox.h:2195
constructor(hash< auto > oh, SwaggerSchema swagger)
Constructor.
The object provides metadata about the API. The metadata can be used by the clients if needed,...
Definition: Swagger.qm.dox.h:1288
string version
Required. Provides the version of the application API (not to be confused with the specification vers...
Definition: Swagger.qm.dox.h:1301
constructor(hash< auto > oh)
Constructor.
string title
Required. The title of the application.
Definition: Swagger.qm.dox.h:1292
*LicenseObject license
The license information for the exposed API.
Definition: Swagger.qm.dox.h:1307
*ContactObject contact
The contact information for the exposed API.
Definition: Swagger.qm.dox.h:1304
*string termsOfService
The Terms of Service for the API.
Definition: Swagger.qm.dox.h:1298
*string desc
A short description of the application. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1295
License information for the exposed API.
Definition: Swagger.qm.dox.h:1344
constructor(hash< auto > oh)
Constructor.
string name
Required. The license name used for the API.
Definition: Swagger.qm.dox.h:1348
*string url
A URL to the license used for the API. MUST be in the format of a URL.
Definition: Swagger.qm.dox.h:1351
Base class for the Swagger specification objects, wrapping the vendor extensions.
Definition: Swagger.qm.dox.h:302
initialize(hash< auto > oh)
Initialize.
hash< auto > vendorExtensions
Allows extensions to the Swagger Schema.
Definition: Swagger.qm.dox.h:310
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:1548
list< string > schemes
The transfer protocol for the operation.
Definition: Swagger.qm.dox.h:1629
*string desc
A verbose explanation of the operation behavior. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:1567
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:1811
hash< string, bool > produces
A hash of MIME types (strings) the operation can produce.
Definition: Swagger.qm.dox.h:1602
*ExternalDocumentationObject externalDocs
Additional external documentation for this operation.
Definition: Swagger.qm.dox.h:1577
string path
the URI path for the operation
Definition: Swagger.qm.dox.h:1552
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:1721
*string summary
A short summary of what the operation does.
Definition: Swagger.qm.dox.h:1564
hash< string, AbstractParameterObject > parameters()
A hash of parameters that are applicable for this operation.
hash< RestQoreExampleCodeInfo > getQoreExampleRequest(string method, string path, PathItemObject pio, SwaggerSchema swagger)
returns example Qore code for the given request
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:1804
string method
the HTTP method for the operation
Definition: Swagger.qm.dox.h:1555
AbstractParameterObject body
body parameter; if defined for this operation, formData parameter will be excluded
Definition: Swagger.qm.dox.h:1616
hash< RestQoreExampleCodeInfo > getQoreExampleResponse(string method, string path, int code)
returns example Qore code for the given response
*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:1674
hash< RestExampleResponseInfo > getExampleResponse(string method, string path, int code, reference< auto > body)
returns a hash of example message information for the given request
parseRequest(PathItemObject pio, reference< hash< UriQueryInfo > > h, reference< auto > body, reference< hash > headers)
parses and processes a REST request on the server side
ResponsesObject responses
Required. The list of possible responses as they are returned from executing this operation.
Definition: Swagger.qm.dox.h:1622
error(string err, string fmt)
raises an exception with context information
list tags
A list of tags (strings or TagObjects) for API documentation control.
Definition: Swagger.qm.dox.h:1561
*ResponseObject getResponse(int code)
returns the ResponseObject for hthe given HTTP code or NOTHING if none is configured
*string operationId
Unique string used to identify the operation.
Definition: Swagger.qm.dox.h:1586
hash< string, AbstractParameterObject > formData
formData parameter; if defined for this operation, body parameter will be excluded
Definition: Swagger.qm.dox.h:1619
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:1753
list< hash< string, list< string > > > security
A declaration of which security schemes are applied for this operation.
Definition: Swagger.qm.dox.h:1644
hash< string, bool > consumes
A list of MIME types (strings) the operation can consume.
Definition: Swagger.qm.dox.h:1594
constructor(string path, string method, hash< auto > oh, SwaggerSchema swagger)
Constructor.
AbstractParameterObject specialization for parameters other than "body".
Definition: Swagger.qm.dox.h:1981
constructor(string name, hash< auto > oh, SwaggerSchema swagger)
Constructor.
*string format
The extending format for the previously mentioned type. See Data Type Formats for further details.
Definition: Swagger.qm.dox.h:1997
check(bool serialize, bool request, string path, string method, string name, reference< auto > value)
validates the value against the schema definition
auto defaultVal
Declares the value of the parameter that the server will use if none is provided.
Definition: Swagger.qm.dox.h:2034
auto getDefaultValue()
returns the default value of the parameter (default: NOTHING)
*ParameterItemsSchemaObject items
Required if type is "array". Describes the type of items in the array.
Definition: Swagger.qm.dox.h:2008
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 type
Required. The type of the parameter.
Definition: Swagger.qm.dox.h:1994
*string collectionFormat
Determines the format of the array if type array is used.
Definition: Swagger.qm.dox.h:2024
items schema object for non-body parameters
Definition: Swagger.qm.dox.h:2460
*string collectionFormat
Determines the format of the array if type array is used.
Definition: Swagger.qm.dox.h:2477
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
static ParameterItemsSchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger)
throws an "INVALID-FIELD-TYPE" exception
Holds the relative paths to the individual endpoints.
Definition: Swagger.qm.dox.h:1371
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:1388
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:1379
*PathComponent wildcard
if there is a wildcard to a PathComponent
Definition: Swagger.qm.dox.h:1382
string pfx
path prefix
Definition: Swagger.qm.dox.h:1376
*PathItemObject pio
the PathItemObject associated with this path (if any)
Definition: Swagger.qm.dox.h:1385
Describes the operations available on a single path.
Definition: Swagger.qm.dox.h:1474
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:1483
hash< string, OperationObject > operations
A hash of OperationObjects correspoding to different methods.
Definition: Swagger.qm.dox.h:1512
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:1498
constructor(string path, hash< auto > oh, SwaggerSchema swagger)
Constructor.
This class stores the path tree for URI path matching.
Definition: Swagger.qm.dox.h:1428
*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:1433
hash< string, list< string > > getPathOperationHash()
returns a hash of URI paths as keys with values as lists of supported HTTP methods
Describes a single response from an API Operation.
Definition: Swagger.qm.dox.h:2107
*SchemaObject schema
A definition of the response structure.
Definition: Swagger.qm.dox.h:2120
string desc
Required. A short description of the response. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:2111
hash< auto > headers
A hash of headers that are (can be) sent with the response.
Definition: Swagger.qm.dox.h:2126
hash examples
A hash of example response messages.
Definition: Swagger.qm.dox.h:2136
static ResponseObject newResponse(string key, hash< auto > oh, SwaggerSchema swagger)
returns a new ResponseObject corresponding to the schema definition passed
constructor(string key, hash< auto > oh, SwaggerSchema swagger)
private constructor; use newResponse() instead
contains the possible responses for an operation
Definition: Swagger.qm.dox.h:2075
ResponseObject defaultResp
Definition: Swagger.qm.dox.h:2082
constructor(string path, string method, hash< auto > oh, SwaggerSchema swagger)
Constructor.
hash< string, ResponseObject > responses
Definition: Swagger.qm.dox.h:2089
Base used by OtherParameter, HeaderObject and SchemaObject.
Definition: Swagger.qm.dox.h:335
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:468
*bool exclusiveMin
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3.
Definition: Swagger.qm.dox.h:348
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:363
*float multipleOf
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.1.
Definition: Swagger.qm.dox.h:375
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:395
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:360
*int minLength
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2.
Definition: Swagger.qm.dox.h:354
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:339
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:495
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:458
*int maxLength
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1.
Definition: Swagger.qm.dox.h:351
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:345
*bool uniqueItems
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.4.
Definition: Swagger.qm.dox.h:366
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:342
*string pattern
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.3.
Definition: Swagger.qm.dox.h:357
defines an object in a schema
Definition: Swagger.qm.dox.h:2250
auto additionalProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.4.
Definition: Swagger.qm.dox.h:2301
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:2294
*string format
The extending format for the previously mentioned type. See Data Type Formats for further details.
Definition: Swagger.qm.dox.h:2264
constructor(string name, hash< auto > oh, SwaggerSchema swagger, *string hash_str) public auto getExampleValue()
private constructor; use newSchemaObject() instead
static SchemaObject newSchemaObject(string name, auto error, SwaggerSchema swagger)
throws an "INVALID-FIELD-TYPE" exception
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:2410
check(bool serialize, bool request, string path, string method, string name, reference< auto > value)
validates the value against the schema definition
list< SchemaObject > allOf()
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.3.
*int maxProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.1.
Definition: Swagger.qm.dox.h:2279
string name
the name of this object for documentation and example purposes
Definition: Swagger.qm.dox.h:2254
string type
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.2.
Definition: Swagger.qm.dox.h:2261
*string discriminator
Adds support for polymorphism.
Definition: Swagger.qm.dox.h:2328
*SchemaObject items
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.3.1.
Definition: Swagger.qm.dox.h:2273
*XmlObject xml
This MAY be used only on properties schemas. It has no effect on root schemas.
Definition: Swagger.qm.dox.h:2359
*ExternalDocumentationObject externalDocs
Additional external documentation for this schema.
Definition: Swagger.qm.dox.h:2362
static checkValueType(reference< auto > value, string type, *SchemaObject items, *string loc)
validates default values
*string desc
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.1.
Definition: Swagger.qm.dox.h:2270
auto defaultVal
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2.
Definition: Swagger.qm.dox.h:2276
*string title
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.1.
Definition: Swagger.qm.dox.h:2267
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:2307
auto example
A free-form property to include an example of an instance for this schema.
Definition: Swagger.qm.dox.h:2365
static SchemaObject newSchemaObject(string name, hash< auto > oh, SwaggerSchema swagger)
returns a SchemaObject for the schema definition; resolves references
*int minProperties
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.4.2.
Definition: Swagger.qm.dox.h:2282
Lists the available scopes for an OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2635
constructor(hash< auto > oh)
Constructor.
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:2642
Allows the definition of a security scheme that can be used by the operations.
Definition: Swagger.qm.dox.h:2569
*string flow
The flow used by the OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2596
*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:2602
string type
Required. The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2".
Definition: Swagger.qm.dox.h:2573
*string inLoc
The location of the API key. Valid values are "query" or "header".
Definition: Swagger.qm.dox.h:2588
constructor(hash< auto > oh)
Constructor.
*string name
The name of the header or query parameter to be used.
Definition: Swagger.qm.dox.h:2582
*ScopesObject scopes
The available scopes for the OAuth2 security scheme.
Definition: Swagger.qm.dox.h:2618
*string desc
A short description for security scheme.
Definition: Swagger.qm.dox.h:2576
*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:2608
Used for loading the Swagger definitions.
Definition: Swagger.qm.dox.h:535
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:594
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:1004
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:1262
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:1111
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:1184
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:924
hash< string, bool > produces
A set of MIME types (strings) the APIs can produce.
Definition: Swagger.qm.dox.h:647
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:843
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:1239
hash< string, hash< string, SchemaObject > > so_map
maps name -> SHA1 hash of the config -> schema objects for recursive references
Definition: Swagger.qm.dox.h:722
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:728
*string def_path
the default path to use when retrieving external schema references
Definition: Swagger.qm.dox.h:711
hash< string, softlist< string > > security
A declaration of which security schemes are applied for the API as a whole.
Definition: Swagger.qm.dox.h:685
hash< string, ResponseObject > responses
Response definitions that can be used across operations. This property does not define global respons...
Definition: Swagger.qm.dox.h:665
*ExternalDocumentationObject externalDocs
Additional external documentation.
Definition: Swagger.qm.dox.h:700
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:716
*string basePath
The base path on which the API is served, which is relative to the host.
Definition: Swagger.qm.dox.h:625
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:719
hash< string, SecuritySchemeObject > securityDefinitions
Security scheme definitions that can be used across the specification.
Definition: Swagger.qm.dox.h:671
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:907
SchemaObject processDefinition(string key, auto value)
Processes a schema definition.
string swaggerSpec
Swagger Specification version being used.
Definition: Swagger.qm.dox.h:602
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:1041
InfoObject info
Required. Provides metadata about the API. The metadata can be used by the clients if needed.
Definition: Swagger.qm.dox.h:605
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:708
const SwaggerOptions
SwaggerSchema options.
Definition: Swagger.qm.dox.h:703
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:860
*string host
The host (name or IP) serving the API.
Definition: Swagger.qm.dox.h:617
hash< string, bool > consumes
A set of MIME types (strings) the APIs can consume.
Definition: Swagger.qm.dox.h:640
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:1215
hash< string, bool > schemes
The transfer protocol of the API.
Definition: Swagger.qm.dox.h:633
PathsObject paths
Required. The available paths and operations for the API.
Definition: Swagger.qm.dox.h:608
list< TagObject > tags
A list of tags used by the specification with additional metadata.
Definition: Swagger.qm.dox.h:697
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:2226
*ExternalDocumentationObject externalDocs
Additional external documentation for this tag.
Definition: Swagger.qm.dox.h:2236
*string desc
A short description for the tag. GFM syntax can be used for rich text representation.
Definition: Swagger.qm.dox.h:2233
string name
Required. The name of the tag.
Definition: Swagger.qm.dox.h:2230
constructor(hash< auto > oh)
Constructor.
A metadata object that allows for more fine-tuned XML model definitions.
Definition: Swagger.qm.dox.h:2524
*string name
Replaces the name of the element/attribute used for the described schema property.
Definition: Swagger.qm.dox.h:2535
constructor(hash< auto > oh)
Constructor.
*string prefix
The prefix to be used for the name.
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:2538
const True
string sprintf(string fmt,...)
main namespace for all public Swagger declarations
Definition: Swagger.qm.dox.h:225
const CollectionFormats
allowed collection formats
Definition: Swagger.qm.dox.h:234
const ValidNumberFormats
Valid number type formats.
Definition: Swagger.qm.dox.h:229
const ValidStringFormatsHash
A hash of valid string type formats.
Definition: Swagger.qm.dox.h:246
const ValidNumberFormatsHash
A hash of valid number type formats.
Definition: Swagger.qm.dox.h:244
const ParameterCollectionFormats
valid parameter collection formats
Definition: Swagger.qm.dox.h:238
const SerializationModules
modules available for data serialization and/or deserialization
Definition: Swagger.qm.dox.h:292
const ValidStringFormats
Valid string type formats.
Definition: Swagger.qm.dox.h:231
const ValidIntFormatsHash
A hash of valid integer type formats.
Definition: Swagger.qm.dox.h:242
const MimeDataTypes
supported mime types for de/serializing data
Definition: Swagger.qm.dox.h:257
const MimeContentTypes
MIME types for data serialization.
Definition: Swagger.qm.dox.h:295
const ValidIntFormats
Valid integer type formats.
Definition: Swagger.qm.dox.h:227
const YamlSerialization
Yaml serialization.
Definition: Swagger.qm.dox.h:249
const ValidSchemes
Valid transfer protocol schemes.
Definition: Swagger.qm.dox.h:298