Qore RestSchemaValidator Module Reference  1.0
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 
55 namespace RestSchemaValidator {
58  public struct RestRequestClientInfo {
60  string uri_path;
62  string content;
64  *data body;
65  };
66 
68  public struct RestRequestServerInfo {
70  string path;
74  any body;
77  };
78 
80  public struct RestResponseClientInfo {
82  int code;
84  any body;
89  };
90 
92  public struct RestExampleRequestInfo {
94  string request_uri;
98  string body;
99  };
100 
102  public struct RestExampleResponseInfo {
104  string response_uri;
106  int code;
110  string body;
111  };
112 
114  public struct RestQoreExampleCodeInfo {
116  hash<string, string> hashdecls();
117 
119  string example;
120  };
121 
124 
125 public:
127 
131  string getTargetUrl();
132 
133 
135 
145  hash<RestRequestClientInfo> processRequest(string method, string path, any body, *hash headers, *softlist<string> content_types);
146 
147 
149 
158  hash<RestRequestServerInfo> parseRequest(string method, string path, *data http_body, reference<hash> headers);
159 
160 
162 
177  hash<HttpResponseInfo> processResponse(string method, string path, int code, any response_body, *hash headers, *softlist<string> content_types);
178 
179 
181 
189  hash<RestResponseClientInfo> parseResponse(string method, string path, int code, *data response_body, hash hdr);
190 
191 
193 
198  hash<RestQoreExampleCodeInfo> getQoreExampleRequest(string method, string path);
199 
200 
202 
208  hash<RestExampleRequestInfo> getExampleRequest(string method, string path, *softlist<string> content_types);
209 
210 
212 
218  hash<RestQoreExampleCodeInfo> getQoreExampleResponse(string method, string path, int code);
219 
220 
222 
229  hash<RestExampleResponseInfo> getExampleResponse(string method, string path, int code, *softlist<string> content_types);
230 
231 
233 
235  hash<string, list<string>> getPathOperationHash();
236 
237 
239 
241  string getBasePath();
242 
243 
245 
247  setBasePath(string basePath);
248 
249 
251 
256 private:
257  abstract string getTargetUrlImpl();
258 public:
259 
261 
272 private:
273  abstract hash<RestRequestClientInfo> processRequestImpl(string method, string path, any body, *hash headers, *softlist<string> content_types);
274 public:
275 
277 
287 private:
288  abstract hash<RestRequestServerInfo> parseRequestImpl(string method, string path, *data http_body, reference<hash> headers);
289 public:
290 
292 
308 private:
309  abstract hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, any response_body, *hash headers, *softlist<string> content_types);
310 public:
311 
313 
322 private:
323  abstract hash<RestResponseClientInfo> parseResponseImpl(string method, string path, int code, *data response_body, hash hdr);
324 public:
325 
327 
330 private:
331  abstract hash<string, list<string>> getPathOperationHashImpl();
332 public:
333 
335 
338 private:
339  abstract string getBasePathImpl();
340 public:
341 
343 
346 private:
347  abstract setBasePathImpl(string basePath);
348 public:
349 
351 
357 private:
358  abstract hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
359 public:
360 
362 
369 private:
370  abstract hash<RestExampleRequestInfo> getExampleRequestImpl(string method, string path, *softlist<string> content_types);
371 public:
372 
374 
381 private:
382  abstract hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
383 public:
384 
386 
394 private:
395  abstract hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code, *softlist<string> content_types);
396 public:
397  };
398 
401 
402 public:
403  public :
405  const DataSerializationSupport = {
406  MimeTypeJson: \make_json(),
407  MimeTypeYamlRpc: \make_yaml(),
408  MimeTypeYaml: \make_yaml(),
409  MimeTypeXml: \make_xmlrpc_value(),
410  MimeTypeXmlApp;
411 ,
412  MimeTypeFormUrlEncoded;
413 ,
414  MimeTypeText: string (auto s) { return sprintf("%s", s); },
415  };
416 
417  const DataSerializationSupportList = keys DataSerializationSupport;
418 
419  const DeserializeYaml = (
420  "code": "yaml",
421  "in": \parse_yaml(),
422  );
423  const DeserializeXml = (
424  "code": "xml",
425  "arg": True,
426  "in": any (string xml, reference<string> type) {
427  try {
428  on_success type = "xml";
429  return parse_xmlrpc_value(xml);
430  }
431  catch (hash<ExceptionInfo> ex);
432 
433  },
434  );
435 
437  const DataDeserializationSupport = {
438  MimeTypeFormUrlEncoded: (
439  "code": "url",
440  "in": \mime_parse_form_urlencoded_string(),
441  ),
442  MimeTypeJson: (
443  "code": "json",
444  "in": \parse_json(),
445  ),
446  MimeTypeYamlRpc: DeserializeYaml,
447  MimeTypeYaml: DeserializeYaml,
448  MimeTypeXml: DeserializeXml,
449  MimeTypeXmlApp: DeserializeXml,
450  MimeTypeText: (
451  "code": "text",
452  "in": string (string s) { return s; },
453  ),
454 
455  };
456 
457 public:
458 
460 
465 private:
466  string getTargetUrlImpl();
467 public:
468 
469 
471 
482 private:
483  hash<RestRequestClientInfo> processRequestImpl(string method, string path, any body, *hash headers, *softlist<string> content_types);
484 public:
485 
486 
488 
498 private:
499  hash<RestRequestServerInfo> parseRequestImpl(string method, string path, *data http_body, reference<hash> headers);
500 public:
501 
502 
504 
520 private:
521  hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, any response_body, *hash headers, *softlist<string> content_types);
522 public:
523 
524 
526 
535 private:
536  hash<RestResponseClientInfo> parseResponseImpl(string method, string path, int code, *data response_body, hash hdr);
537 public:
538 
539 
541 
544 private:
545  hash<string, list<string>> getPathOperationHashImpl();
546 public:
547 
548 
550 
553 private:
554  string getBasePathImpl();
555 public:
556 
557 
559 
561  setBasePathImpl(string basePath);
562 
563 
565 
571 private:
572  hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
573 public:
574 
575 
577 
584 private:
585  hash<RestExampleRequestInfo> getExampleRequestImpl(string method, string path, *softlist<string> content_types);
586 public:
587 
588 
590 
597 private:
598  hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
599 public:
600 
601 
603 
611 private:
612  hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code, *softlist<string> content_types);
613 public:
614 
615  };
616 };
string response_uri
the HTTP response URI
Definition: RestSchemaValidator.qm.dox.h:104
hash info
miscellaneous free-form info about the parsed request
Definition: RestSchemaValidator.qm.dox.h:76
string body
the HTTP request body
Definition: RestSchemaValidator.qm.dox.h:98
string sprintf(string fmt,...)
main namespace for all public RestSchemaValidator declarations
Definition: RestSchemaValidator.qm.dox.h:56
a hash giving example info for example HTTP request messages
Definition: RestSchemaValidator.qm.dox.h:92
abstract REST schema validation classes
Definition: RestSchemaValidator.qm.dox.h:123
any body
the deserialized message body
Definition: RestSchemaValidator.qm.dox.h:84
hash hdr
the HTTP response header hash
Definition: RestSchemaValidator.qm.dox.h:108
const True
a hash of information about a response from the server
Definition: RestSchemaValidator.qm.dox.h:80
string example
a string giving the example code generation
Definition: RestSchemaValidator.qm.dox.h:119
a hash of information about a client-side request
Definition: RestSchemaValidator.qm.dox.h:58
hash hdr
the HTTP headers received
Definition: RestSchemaValidator.qm.dox.h:86
any body
the deserialized message body data
Definition: RestSchemaValidator.qm.dox.h:74
string content
the Content-Type for the message
Definition: RestSchemaValidator.qm.dox.h:62
a hash giving example information for building a request or response in Qore
Definition: RestSchemaValidator.qm.dox.h:114
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:106
null REST validator; no schema is used but default serialization and deserialization is performed ...
Definition: RestSchemaValidator.qm.dox.h:400
hash info
miscellaneous free-form info about the parsed response
Definition: RestSchemaValidator.qm.dox.h:88
a hash of information about a server-side request
Definition: RestSchemaValidator.qm.dox.h:68
a hash giving example info for example HTTP response messages
Definition: RestSchemaValidator.qm.dox.h:102
string type(auto arg)
string request_uri
the HTTP request URI
Definition: RestSchemaValidator.qm.dox.h:94
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:82
string body
the HTTP response body
Definition: RestSchemaValidator.qm.dox.h:110
string string(softstring str, *string enc)
hash hdr
the HTTP request header hash
Definition: RestSchemaValidator.qm.dox.h:96
string path
the URI path without query arguments
Definition: RestSchemaValidator.qm.dox.h:70
*hash query
any query arguments
Definition: RestSchemaValidator.qm.dox.h:72
hash hash(object obj)
string uri_path
the URI path for the request
Definition: RestSchemaValidator.qm.dox.h:60
*data body
the serialized message body hash
Definition: RestSchemaValidator.qm.dox.h:64