Qore RestSchemaValidator Module Reference  1.0.2
RestSchemaValidator.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* RestSchemaValidator.qm Copyright (C) 2017 - 2018 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 
63 namespace RestSchemaValidator {
66  public struct RestRequestClientInfo {
68  string uri_path;
70  string content;
72  *data body;
73  };
74 
76  public struct RestRequestServerInfo {
78  string path;
82  auto body;
85  };
86 
88  public struct RestResponseClientInfo {
90  int code;
92  auto body;
97  };
98 
100  public struct RestExampleRequestInfo {
102  string request_uri;
106  string body;
107  };
108 
110  public struct RestExampleResponseInfo {
112  string response_uri;
114  int code;
118  string body;
119  };
120 
122  public struct RestQoreExampleCodeInfo {
124  hash<string, string> hashdecls();
125 
127  string example;
128  };
129 
132 
133 public:
135 
139  string getTargetUrl();
140 
141 
143 
153  hash<RestRequestClientInfo> processRequest(string method, string path, auto body, *hash headers, *softlist<string> content_types);
154 
155 
157 
168  hash<RestRequestServerInfo> parseRequest(string method, string path, *data http_body, reference<hash> headers);
169 
170 
172 
187  hash<HttpResponseInfo> processResponse(string method, string path, int code, auto response_body, *hash headers, *softlist<string> content_types);
188 
189 
191 
199  hash<RestResponseClientInfo> parseResponse(string method, string path, int code, *data response_body, hash hdr);
200 
201 
203 
208  hash<RestQoreExampleCodeInfo> getQoreExampleRequest(string method, string path);
209 
210 
212 
218  hash<RestExampleRequestInfo> getExampleRequest(string method, string path, *softlist<string> content_types);
219 
220 
222 
228  hash<RestQoreExampleCodeInfo> getQoreExampleResponse(string method, string path, int code);
229 
230 
232 
239  hash<RestExampleResponseInfo> getExampleResponse(string method, string path, int code, *softlist<string> content_types);
240 
241 
243 
245  hash<string, list<string>> getPathOperationHash();
246 
247 
249 
251  string getBasePath();
252 
253 
255 
257  setBasePath(string basePath);
258 
259 
261 
266 private:
267  abstract string getTargetUrlImpl();
268 public:
269 
271 
282 private:
283  abstract hash<RestRequestClientInfo> processRequestImpl(string method, string path, auto body, *hash headers, *softlist<string> content_types);
284 public:
285 
287 
299 private:
300  abstract hash<RestRequestServerInfo> parseRequestImpl(string method, string path, *data http_body, reference<hash> headers);
301 public:
302 
304 
320 private:
321  abstract hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, any response_body, *hash headers, *softlist<string> content_types);
322 public:
323 
325 
334 private:
335  abstract hash<RestResponseClientInfo> parseResponseImpl(string method, string path, int code, *data response_body, hash hdr);
336 public:
337 
339 
342 private:
343  abstract hash<string, list<string>> getPathOperationHashImpl();
344 public:
345 
347 
350 private:
351  abstract string getBasePathImpl();
352 public:
353 
355 
358 private:
359  abstract setBasePathImpl(string basePath);
360 public:
361 
363 
369 private:
370  abstract hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
371 public:
372 
374 
381 private:
382  abstract hash<RestExampleRequestInfo> getExampleRequestImpl(string method, string path, *softlist<string> content_types);
383 public:
384 
386 
393 private:
394  abstract hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
395 public:
396 
398 
406 private:
407  abstract hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code, *softlist<string> content_types);
408 public:
409  };
410 
413 
414 public:
415  public :
418  MimeTypeJson: \make_json(),
419  MimeTypeYamlRpc: \make_yaml(),
420  MimeTypeYaml: \make_yaml(),
421  MimeTypeXml: \make_xmlrpc_value(),
422  MimeTypeXmlApp;
423 ,
424  MimeTypeFormUrlEncoded;
425 ,
426  MimeTypeText;
427 ,
428  MimeTypeOctetStream;
429 ,
430  };
431 
432  const DataSerializationSupportList = keys DataSerializationSupport;
433 
434  const DeserializeYaml = (
435  "code": "yaml",
436  "in": \parse_yaml(),
437  );
438  const DeserializeXml = (
439  "code": "xml",
440  "arg": True,
441  "in": auto (string xml, reference<string> type) {
442  try {
443  on_success type = "xml";
444  return parse_xmlrpc_value(xml);
445  }
446  catch (hash<ExceptionInfo> ex);
447 
448  },
449  );
450 
453  MimeTypeFormUrlEncoded: (
454  "code": "url",
455  "in": \mime_parse_form_urlencoded_string(),
456  ),
457  MimeTypeJson: (
458  "code": "json",
459  "in": \parse_json(),
460  ),
461  MimeTypeYamlRpc: DeserializeYaml,
462  MimeTypeYaml: DeserializeYaml,
463  MimeTypeXml: DeserializeXml,
464  MimeTypeXmlApp: DeserializeXml,
465  MimeTypeText: (
466  "code": "text",
467  "in": data (data s) { return s; },
468  ),
469 
470  MimeTypeOctetStream: {
471  "code": "bin",
472  "in": binary (data s) {
473  return s.typeCode() == NT_BINARY ? s : binary(s);
474  },
475  },
476  };
477 
478 public:
479 
481 
486 private:
487  string getTargetUrlImpl();
488 public:
489 
490 
492 
503 private:
504  hash<RestRequestClientInfo> processRequestImpl(string method, string path, auto body, *hash headers, *softlist<string> content_types);
505 public:
506 
507 
509 
521 private:
522  hash<RestRequestServerInfo> parseRequestImpl(string method, string path, *data http_body, reference<hash> headers);
523 public:
524 
525 
527 
543 private:
544  hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, auto response_body, *hash headers, *softlist<string> content_types);
545 public:
546 
547 
549 
558 private:
559  hash<RestResponseClientInfo> parseResponseImpl(string method, string path, int code, *data response_body, hash hdr);
560 public:
561 
562 
564 
567 private:
568  hash<string, list<string>> getPathOperationHashImpl();
569 public:
570 
571 
573 
576 private:
577  string getBasePathImpl();
578 public:
579 
580 
582 
584  setBasePathImpl(string basePath);
585 
586 
588 
594 private:
595  hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
596 public:
597 
598 
600 
607 private:
608  hash<RestExampleRequestInfo> getExampleRequestImpl(string method, string path, *softlist<string> content_types);
609 public:
610 
611 
613 
620 private:
621  hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
622 public:
623 
624 
626 
634 private:
635  hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code, *softlist<string> content_types);
636 public:
637 
638  };
639 };
abstract hash< string, list< string > > getPathOperationHashImpl()
returns a hash of URI paths as keys with values as lists of supported HTTP methods ...
string response_uri
the HTTP response URI
Definition: RestSchemaValidator.qm.dox.h:112
hash info
miscellaneous free-form info about the parsed request
Definition: RestSchemaValidator.qm.dox.h:84
hash< RestExampleResponseInfo > getExampleResponseImpl(string method, string path, int code, *softlist< string > content_types)
returns a hash of example message information for the given request
const DataSerializationSupport
Data serialization support mapping codes to MIME types and de/serialization functions.
Definition: RestSchemaValidator.qm.dox.h:417
string body
the HTTP request body
Definition: RestSchemaValidator.qm.dox.h:106
main namespace for all public RestSchemaValidator declarations
Definition: RestSchemaValidator.qm.dox.h:64
a hash giving example info for example HTTP request messages
Definition: RestSchemaValidator.qm.dox.h:100
abstract hash< RestQoreExampleCodeInfo > getQoreExampleRequestImpl(string method, string path)
returns a hash of example Qore code for the given request
hash< 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) ...
abstract REST schema validation classes
Definition: RestSchemaValidator.qm.dox.h:131
hash< string, list< string > > getPathOperationHashImpl()
returns a hash of URI paths as keys with values as lists of supported HTTP methods ...
hash< RestExampleRequestInfo > getExampleRequestImpl(string method, string path, *softlist< string > content_types)
returns a hash of example message information for the given request
abstract string getTargetUrlImpl()
returns the target URL for the schema
setBasePathImpl(string basePath)
overrides the basePath value
hash hdr
the HTTP response header hash
Definition: RestSchemaValidator.qm.dox.h:116
const True
a hash of information about a response from the server
Definition: RestSchemaValidator.qm.dox.h:88
string getBasePathImpl()
returns the base path prefix for all requests in this schema
hash< RestQoreExampleCodeInfo > getQoreExampleResponse(string method, string path, int code)
returns example Qore code for the given response
binary binary()
string example
a string giving the example code generation
Definition: RestSchemaValidator.qm.dox.h:127
hash< RestRequestServerInfo > parseRequest(string method, string path, *data http_body, reference< hash > headers)
processes and parses a client request and returns the deserialized message body (if any) ...
abstract hash< RestExampleRequestInfo > getExampleRequestImpl(string method, string path, *softlist< string > content_types)
returns a hash of example message information for the given request
a hash of information about a client-side request
Definition: RestSchemaValidator.qm.dox.h:66
hash hdr
the HTTP headers received
Definition: RestSchemaValidator.qm.dox.h:94
string getTargetUrl()
returns the target URL for the schema
hash< HttpResponseInfo > processResponseImpl(string method, string path, int code, auto response_body, *hash headers, *softlist< string > content_types)
processes a REST response with a serialized message body, validates any response data against schema ...
hash< RestExampleResponseInfo > getExampleResponse(string method, string path, int code, *softlist< string > content_types)
returns a hash of example message information for the given request
abstract setBasePathImpl(string basePath)
overrides the basePath value
abstract hash< RestExampleResponseInfo > getExampleResponseImpl(string method, string path, int code, *softlist< string > content_types)
returns a hash of example message information for the given request
auto body
the deserialized message body data
Definition: RestSchemaValidator.qm.dox.h:82
hash< string, list< string > > getPathOperationHash()
returns a hash of URI paths as keys with values as lists of supported HTTP methods ...
hash< RestResponseClientInfo > parseResponse(string method, string path, int code, *data response_body, hash hdr)
parses and validates the response from the server and returns a hash of the processed info ...
hash< RestRequestClientInfo > processRequest(string method, string path, auto body, *hash headers, *softlist< string > content_types)
processes a client-side REST request and returns a hash that can be used to make the outgoing client-...
hash< RestRequestClientInfo > processRequestImpl(string method, string path, auto body, *hash headers, *softlist< string > content_types)
processes a client-side REST request and returns a hash that can be used to make the outgoing client-...
hash< RestQoreExampleCodeInfo > getQoreExampleResponseImpl(string method, string path, int code)
returns example Qore code for the given response
string getBasePath()
returns the base path prefix for all requests in this schema
string content
the Content-Type for the message
Definition: RestSchemaValidator.qm.dox.h:70
abstract hash< RestResponseClientInfo > parseResponseImpl(string method, string path, int code, *data response_body, hash hdr)
parses and validates the response from the server and returns a hash of the processed info ...
a hash giving example information for building a request or response in Qore
Definition: RestSchemaValidator.qm.dox.h:122
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:114
string getTargetUrlImpl()
returns the target URL for the schema
const DataDeserializationSupport
Data deserialization support MIME types to codes and de/serialization functions.
Definition: RestSchemaValidator.qm.dox.h:452
null REST validator; no schema is used but default serialization and deserialization is performed ...
Definition: RestSchemaValidator.qm.dox.h:412
hash info
miscellaneous free-form info about the parsed response
Definition: RestSchemaValidator.qm.dox.h:96
a hash of information about a server-side request
Definition: RestSchemaValidator.qm.dox.h:76
a hash giving example info for example HTTP response messages
Definition: RestSchemaValidator.qm.dox.h:110
const NT_BINARY
hash< HttpResponseInfo > processResponse(string method, string path, int code, auto response_body, *hash headers, *softlist< string > content_types)
processes a REST response with a serialized message body, validates any response data against schema ...
string type(auto arg)
string request_uri
the HTTP request URI
Definition: RestSchemaValidator.qm.dox.h:102
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:90
abstract hash< RestQoreExampleCodeInfo > getQoreExampleResponseImpl(string method, string path, int code)
returns example Qore code for the given response
string body
the HTTP response body
Definition: RestSchemaValidator.qm.dox.h:118
hash< RestQoreExampleCodeInfo > getQoreExampleRequestImpl(string method, string path)
returns a hash of example Qore code for the given request
hash< RestQoreExampleCodeInfo > getQoreExampleRequest(string method, string path)
returns a hash of example Qore code for the given request
setBasePath(string basePath)
overrides the basePath value
hash hdr
the HTTP request header hash
Definition: RestSchemaValidator.qm.dox.h:104
abstract hash< HttpResponseInfo > processResponseImpl(string method, string path, int code, any response_body, *hash headers, *softlist< string > content_types)
processes a REST response with a serialized message body, validates any response data against schema ...
auto body
the deserialized message body
Definition: RestSchemaValidator.qm.dox.h:92
string path
the URI path without query arguments
Definition: RestSchemaValidator.qm.dox.h:78
hash< RestResponseClientInfo > parseResponseImpl(string method, string path, int code, *data response_body, hash hdr)
parses and validates the response from the server and returns a hash of the processed info ...
*hash query
any query arguments
Definition: RestSchemaValidator.qm.dox.h:80
hash< RestExampleRequestInfo > getExampleRequest(string method, string path, *softlist< string > content_types)
returns a hash of example message information for the given request
hash hash(object obj)
abstract string getBasePathImpl()
returns the base path prefix for all requests in this schema
hash< string, string > hashdecls()
a hash giving example struct declarations for hash objects in the message; keys are struct names; str...
string uri_path
the URI path for the request
Definition: RestSchemaValidator.qm.dox.h:68
abstract hash< 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) ...
abstract hash< RestRequestClientInfo > processRequestImpl(string method, string path, auto body, *hash headers, *softlist< string > content_types)
processes a client-side REST request and returns a hash that can be used to make the outgoing client-...
*data body
the serialized message body hash
Definition: RestSchemaValidator.qm.dox.h:72