Qore RestSchemaValidator Module Reference  1.0.1
RestSchemaValidator.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* RestSchemaValidator.qm Copyright (C) 2017 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 // requires the HttpServerUtil module
29 
30 // need mime definitions
31 
32 
33 
34 
35 
60 namespace RestSchemaValidator {
63  public struct RestRequestClientInfo {
65  string uri_path;
67  string content;
69  *data body;
70  };
71 
73  public struct RestRequestServerInfo {
75  string path;
79  auto body;
82  };
83 
85  public struct RestResponseClientInfo {
87  int code;
89  auto body;
94  };
95 
97  public struct RestExampleRequestInfo {
99  string request_uri;
103  string body;
104  };
105 
107  public struct RestExampleResponseInfo {
109  string response_uri;
111  int code;
115  string body;
116  };
117 
119  public struct RestQoreExampleCodeInfo {
121  hash<string, string> hashdecls();
122 
124  string example;
125  };
126 
129 
130 public:
132 
136  string getTargetUrl();
137 
138 
140 
150  hash<RestRequestClientInfo> processRequest(string method, string path, auto body, *hash headers, *softlist<string> content_types);
151 
152 
154 
165  hash<RestRequestServerInfo> parseRequest(string method, string path, *data http_body, reference<hash> headers);
166 
167 
169 
184  hash<HttpResponseInfo> processResponse(string method, string path, int code, auto response_body, *hash headers, *softlist<string> content_types);
185 
186 
188 
196  hash<RestResponseClientInfo> parseResponse(string method, string path, int code, *data response_body, hash hdr);
197 
198 
200 
205  hash<RestQoreExampleCodeInfo> getQoreExampleRequest(string method, string path);
206 
207 
209 
215  hash<RestExampleRequestInfo> getExampleRequest(string method, string path, *softlist<string> content_types);
216 
217 
219 
225  hash<RestQoreExampleCodeInfo> getQoreExampleResponse(string method, string path, int code);
226 
227 
229 
236  hash<RestExampleResponseInfo> getExampleResponse(string method, string path, int code, *softlist<string> content_types);
237 
238 
240 
242  hash<string, list<string>> getPathOperationHash();
243 
244 
246 
248  string getBasePath();
249 
250 
252 
254  setBasePath(string basePath);
255 
256 
258 
263 private:
264  abstract string getTargetUrlImpl();
265 public:
266 
268 
279 private:
280  abstract hash<RestRequestClientInfo> processRequestImpl(string method, string path, auto body, *hash headers, *softlist<string> content_types);
281 public:
282 
284 
296 private:
297  abstract hash<RestRequestServerInfo> parseRequestImpl(string method, string path, *data http_body, reference<hash> headers);
298 public:
299 
301 
317 private:
318  abstract hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, any response_body, *hash headers, *softlist<string> content_types);
319 public:
320 
322 
331 private:
332  abstract hash<RestResponseClientInfo> parseResponseImpl(string method, string path, int code, *data response_body, hash hdr);
333 public:
334 
336 
339 private:
340  abstract hash<string, list<string>> getPathOperationHashImpl();
341 public:
342 
344 
347 private:
348  abstract string getBasePathImpl();
349 public:
350 
352 
355 private:
356  abstract setBasePathImpl(string basePath);
357 public:
358 
360 
366 private:
367  abstract hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
368 public:
369 
371 
378 private:
379  abstract hash<RestExampleRequestInfo> getExampleRequestImpl(string method, string path, *softlist<string> content_types);
380 public:
381 
383 
390 private:
391  abstract hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
392 public:
393 
395 
403 private:
404  abstract hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code, *softlist<string> content_types);
405 public:
406  };
407 
410 
411 public:
412  public :
414  const DataSerializationSupport = {
415  MimeTypeJson: \make_json(),
416  MimeTypeYamlRpc: \make_yaml(),
417  MimeTypeYaml: \make_yaml(),
418  MimeTypeXml: \make_xmlrpc_value(),
419  MimeTypeXmlApp;
420 ,
421  MimeTypeFormUrlEncoded;
422 ,
423  MimeTypeText: string (auto s) { return sprintf("%s", s); },
424  };
425 
426  const DataSerializationSupportList = keys DataSerializationSupport;
427 
428  const DeserializeYaml = (
429  "code": "yaml",
430  "in": \parse_yaml(),
431  );
432  const DeserializeXml = (
433  "code": "xml",
434  "arg": True,
435  "in": auto (string xml, reference<string> type) {
436  try {
437  on_success type = "xml";
438  return parse_xmlrpc_value(xml);
439  }
440  catch (hash<ExceptionInfo> ex);
441 
442  },
443  );
444 
446  const DataDeserializationSupport = {
447  MimeTypeFormUrlEncoded: (
448  "code": "url",
449  "in": \mime_parse_form_urlencoded_string(),
450  ),
451  MimeTypeJson: (
452  "code": "json",
453  "in": \parse_json(),
454  ),
455  MimeTypeYamlRpc: DeserializeYaml,
456  MimeTypeYaml: DeserializeYaml,
457  MimeTypeXml: DeserializeXml,
458  MimeTypeXmlApp: DeserializeXml,
459  MimeTypeText: (
460  "code": "text",
461  "in": string (string s) { return s; },
462  ),
463 
464  };
465 
466 public:
467 
469 
474 private:
475  string getTargetUrlImpl();
476 public:
477 
478 
480 
491 private:
492  hash<RestRequestClientInfo> processRequestImpl(string method, string path, auto body, *hash headers, *softlist<string> content_types);
493 public:
494 
495 
497 
509 private:
510  hash<RestRequestServerInfo> parseRequestImpl(string method, string path, *data http_body, reference<hash> headers);
511 public:
512 
513 
515 
531 private:
532  hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, auto response_body, *hash headers, *softlist<string> content_types);
533 public:
534 
535 
537 
546 private:
547  hash<RestResponseClientInfo> parseResponseImpl(string method, string path, int code, *data response_body, hash hdr);
548 public:
549 
550 
552 
555 private:
556  hash<string, list<string>> getPathOperationHashImpl();
557 public:
558 
559 
561 
564 private:
565  string getBasePathImpl();
566 public:
567 
568 
570 
572  setBasePathImpl(string basePath);
573 
574 
576 
582 private:
583  hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
584 public:
585 
586 
588 
595 private:
596  hash<RestExampleRequestInfo> getExampleRequestImpl(string method, string path, *softlist<string> content_types);
597 public:
598 
599 
601 
608 private:
609  hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
610 public:
611 
612 
614 
622 private:
623  hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code, *softlist<string> content_types);
624 public:
625 
626  };
627 };
string response_uri
the HTTP response URI
Definition: RestSchemaValidator.qm.dox.h:109
hash info
miscellaneous free-form info about the parsed request
Definition: RestSchemaValidator.qm.dox.h:81
string body
the HTTP request body
Definition: RestSchemaValidator.qm.dox.h:103
string sprintf(string fmt,...)
main namespace for all public RestSchemaValidator declarations
Definition: RestSchemaValidator.qm.dox.h:61
a hash giving example info for example HTTP request messages
Definition: RestSchemaValidator.qm.dox.h:97
abstract REST schema validation classes
Definition: RestSchemaValidator.qm.dox.h:128
hash hdr
the HTTP response header hash
Definition: RestSchemaValidator.qm.dox.h:113
const True
a hash of information about a response from the server
Definition: RestSchemaValidator.qm.dox.h:85
string example
a string giving the example code generation
Definition: RestSchemaValidator.qm.dox.h:124
a hash of information about a client-side request
Definition: RestSchemaValidator.qm.dox.h:63
hash hdr
the HTTP headers received
Definition: RestSchemaValidator.qm.dox.h:91
auto body
the deserialized message body data
Definition: RestSchemaValidator.qm.dox.h:79
string content
the Content-Type for the message
Definition: RestSchemaValidator.qm.dox.h:67
a hash giving example information for building a request or response in Qore
Definition: RestSchemaValidator.qm.dox.h:119
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:111
null REST validator; no schema is used but default serialization and deserialization is performed ...
Definition: RestSchemaValidator.qm.dox.h:409
hash info
miscellaneous free-form info about the parsed response
Definition: RestSchemaValidator.qm.dox.h:93
a hash of information about a server-side request
Definition: RestSchemaValidator.qm.dox.h:73
a hash giving example info for example HTTP response messages
Definition: RestSchemaValidator.qm.dox.h:107
string type(auto arg)
string request_uri
the HTTP request URI
Definition: RestSchemaValidator.qm.dox.h:99
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:87
string body
the HTTP response body
Definition: RestSchemaValidator.qm.dox.h:115
string string(softstring str, *string enc)
hash hdr
the HTTP request header hash
Definition: RestSchemaValidator.qm.dox.h:101
auto body
the deserialized message body
Definition: RestSchemaValidator.qm.dox.h:89
string path
the URI path without query arguments
Definition: RestSchemaValidator.qm.dox.h:75
*hash query
any query arguments
Definition: RestSchemaValidator.qm.dox.h:77
hash hash(object obj)
string uri_path
the URI path for the request
Definition: RestSchemaValidator.qm.dox.h:65
*data body
the serialized message body hash
Definition: RestSchemaValidator.qm.dox.h:69