Qore RestSchemaValidator Module Reference 2.2
Loading...
Searching...
No Matches
RestSchemaValidator.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* RestSchemaValidator.qm Copyright (C) 2017 - 2023 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25
26// make sure we have the required qore version
27
28// requires the HttpServerUtil module
29
30// need mime definitions
31
32// supports using the DataProvider module to describe input and output records
33
34// supports logging with the Logger module
35
36
37
38
39
113 public hashdecl RestRequestClientInfo {
115 string uri_path;
117 string content;
119
121 *list<string> response_content;
123 *data body;
124 };
125
127 public hashdecl RestRequestServerInfo {
129 string path;
131 *hash<auto> query;
133 *hash<auto> path_args;
135 auto body;
137 hash<auto> info;
138 };
139
141 public hashdecl RestResponseClientInfo {
143 int code;
145 auto body;
147 hash<auto> hdr;
149 hash<auto> info;
150 };
151
153 public hashdecl RestExampleRequestInfo {
157 hash<auto> hdr;
159 string body;
160 };
161
163 public hashdecl RestExampleResponseInfo {
167 int code;
169 hash<auto> hdr;
171 string body;
172 };
173
175 public hashdecl RestQoreExampleCodeInfo {
177 hash<string, string> hashdecls();
178
180 string example;
181 };
182
184class AbstractRestSchemaValidator : public LoggerWrapper {
185
186public:
189
190
193
194
196
200 string getHash();
201
202
204
208 string getTargetUrl();
209
210
212
222 hash<RestRequestClientInfo> processRequest(string method, string path, auto body, *hash<auto> headers, *softlist<string> content_types);
223
224
226
241 hash<RestRequestServerInfo> parseRequest(string method, string path, *data http_body, reference<hash<auto>> headers);
242
243
245
267 hash<HttpResponseInfo> processResponse(string method, string path, int code, auto response_body, *hash<auto> headers, *softlist<string> content_types);
268
269
271
279 hash<RestResponseClientInfo> parseResponse(string method, string path, int code, *data response_body, hash<auto> hdr);
280
281
283
288 hash<RestQoreExampleCodeInfo> getQoreExampleRequest(string method, string path);
289
290
292
298 hash<RestExampleRequestInfo> getExampleRequest(string method, string path, *softlist<string> content_types);
299
300
302
308 hash<RestQoreExampleCodeInfo> getQoreExampleResponse(string method, string path, int code);
309
310
312
319 hash<RestExampleResponseInfo> getExampleResponse(string method, string path, int code, *softlist<string> content_types);
320
321
323
325 hash<string, list<string>> getPathOperationHash();
326
327
329
331 string getBasePath();
332
333
335
337 setBasePath(string basePath);
338
339
341
350 DataProvider::AbstractDataProvider getDataProvider(HTTPClient rest);
351
352
354
357
358
360
364 setTimeZoneLocale(*TimeZone tz);
365
366
368
372 *TimeZone getTimeZoneLocale();
373
374
376
385protected:
386 DataProvider::AbstractDataProvider getDataProviderImpl(HTTPClient rest);
387public:
388
389
391
395protected:
396 abstract string getHashImpl();
397public:
398
400
404protected:
405 abstract string getTargetUrlImpl();
406public:
407
409
419protected:
420 abstract hash<RestRequestClientInfo> processRequestImpl(string method, string path, auto body, *hash<auto> headers, *softlist<string> content_types);
421public:
422
424
435protected:
436 abstract hash<RestRequestServerInfo> parseRequestImpl(string method, string path, *data http_body, reference<hash> headers);
437public:
438
440
455protected:
456 abstract hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, auto response_body, *hash<auto> headers, *softlist<string> content_types);
457public:
458
460
468protected:
469 abstract hash<RestResponseClientInfo> parseResponseImpl(string method, string path, int code, *data response_body, hash<auto> hdr);
470public:
471
473
475protected:
476 abstract hash<string, list<string>> getPathOperationHashImpl();
477public:
478
480
482protected:
483 abstract string getBasePathImpl();
484public:
485
487
489protected:
490 abstract setBasePathImpl(string basePath);
491public:
492
494
499protected:
500 abstract hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
501public:
502
504
510protected:
511 abstract hash<RestExampleRequestInfo> getExampleRequestImpl(string method, string path, *softlist<string> content_types);
512public:
513
515
521protected:
522 abstract hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
523public:
524
526
533protected:
534 abstract hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code, *softlist<string> content_types);
535public:
536
538
542protected:
543 abstract setTimeZoneLocaleImpl(*TimeZone tz);
544public:
545
547
551protected:
552 abstract *TimeZone getTimeZoneLocaleImpl();
553public:
554 };
555
558
559public:
562%ifndef NoJson
563 MimeTypeJson: \make_json(),
564%endif
565%ifndef NoYaml
566 MimeTypeYamlRpc: \make_yaml(),
567 MimeTypeYaml: \make_yaml(),
568%endif
569%ifndef NoXml
570 MimeTypeXml: \make_xmlrpc_value(),
571 MimeTypeXmlApp: string sub (auto v) {
572 switch (v.typeCode()) {
573 case NT_LIST: return make_xml(("list": ("element": v)));
574 case NT_HASH: return v.size() == 1 && v.firstValue().lsize() == 1 ? make_xml(v) : make_xml(("value": v));
575 }
576 return make_xml(("value": v));
577 },
578%endif
579 MimeTypeFormUrlEncoded: string sub (auto v) {
580 if (v.typeCode() == NT_HASH)
581 return mime_get_form_urlencoded_string(v);
582 throw "FORMURLENCODING-ERROR", sprintf("form URL encoding can only encode hashes; type %y requested", v.type());
583 },
584 MimeTypeText: data sub (auto s) {
585 switch (s.typeCode()) {
586 case NT_STRING:
587 case NT_BINARY:
588 return s;
589 default:
590 // issue #3547: send as a YAML-serialized string if possible to catch unserializable data
591%ifndef NoYaml
592 return make_yaml(s);
593%else
594 throw "TEXT-SERIALIZATION-ERROR", sprintf("cannot serialize type %y without YAML support", s.type());
595%endif
596 }
597 },
598 MimeTypeOctetStream: binary sub (auto s) {
599 switch (s.typeCode()) {
600 case NT_STRING:
601 return binary(s);
602 case NT_BINARY:
603 return s;
604 default:
605 # issue #3547: send as a YAML-serialized string if possible to catch unserializable data
606%ifndef NoYaml
607 return binary(make_yaml(s));
608%else
609 throw "BINARY-SERIALIZATION-ERROR", sprintf("cannot serialize type %y without YAML support", s.type());
610%endif
611 }
612 },
613 };
614
615 const DataSerializationSupportList = keys DataSerializationSupport;
616
617 const DeserializeYaml = ...;
618
619 const DeserializeXml = ...;
620
621
624 MimeTypeFormUrlEncoded: (
625 "code": "url",
626 "in": \mime_parse_form_urlencoded_string(),
627 ),
628%ifndef NoJson
629 MimeTypeJson: (
630 "code": "json",
631 "in": \parse_json(),
632 ),
633%endif
634%ifndef NoYaml
635 MimeTypeYamlRpc: DeserializeYaml,
636 MimeTypeYaml: DeserializeYaml,
637%endif
638%ifndef NoXml
639 MimeTypeXml: DeserializeXml,
640 MimeTypeXmlApp: DeserializeXml,
641%endif
642 MimeTypeText: (
643 "code": "text",
644 "in": data sub (data s) { return s; },
645 ),
646
647 MimeTypeOctetStream: {
648 "code": "bin",
649 "in": binary sub (data s) {
650 return s.typeCode() == NT_BINARY ? s : binary(s);
651 },
652 },
653 };
654
656
658 const NullSchemaHashStr = "<null rest schema>";
659
661
664
665
667
671protected:
672 string getHashImpl();
673public:
674
675
677
681protected:
683public:
684
685
687
697protected:
698 hash<RestRequestClientInfo> processRequestImpl(string method, string path, auto body, *hash<auto> headers, *softlist<string> content_types);
699public:
700
701
703
714protected:
715 hash<RestRequestServerInfo> parseRequestImpl(string method, string path, *data http_body, reference<hash> headers);
716public:
717
718
720
743protected:
744 hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, auto response_body, *hash<auto> headers, *softlist<string> content_types);
745public:
746
747
749
757protected:
758 hash<RestResponseClientInfo> parseResponseImpl(string method, string path, int code, *data response_body, hash<auto> hdr);
759public:
760
761
763
772private:
773 bool checkResponseContentTypeHeader(reference<hash<HttpResponseInfo>> resp, auto body, *hash<auto> headers, *softlist<string> content_types);
774public:
775
776
778
780protected:
781 hash<string, list<string>> getPathOperationHashImpl();
782public:
783
784
786
788protected:
790public:
791
792
794
796protected:
797 setBasePathImpl(string basePath);
798public:
799
800
802
807protected:
808 hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
809public:
810
811
813
819protected:
820 hash<RestExampleRequestInfo> getExampleRequestImpl(string method, string path, *softlist<string> content_types);
821public:
822
823
825
831protected:
832 hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
833public:
834
835
837
844protected:
845 hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code, *softlist<string> content_types);
846public:
847
848
850
854protected:
856public:
857
858
860
864protected:
866public:
867
868 };
869};
abstract REST schema validation classes
Definition: RestSchemaValidator.qm.dox.h:184
bool managesUriPath()
returns True if the provider manages the URI path
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< 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-...
abstract hash< RestExampleRequestInfo > getExampleRequestImpl(string method, string path, *softlist< string > content_types)
returns a hash of example message information for the given request
hash< RestRequestClientInfo > processRequest(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-...
abstract hash< 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
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
hash< RestExampleRequestInfo > getExampleRequest(string method, string path, *softlist< string > content_types)
returns a hash of example message information for the given request
*TimeZone getTimeZoneLocale()
Returns the time zone locale used for serialization / deserialization.
DataProvider::AbstractDataProvider getDataProviderImpl(HTTPClient rest)
returns a data provider object for this connection, if supported by any REST schema validator object
string getTargetUrl()
returns the target URL for the schema
abstract string getHashImpl()
returns a unique hash for the schema that can be used to compare schemas
hash< RestQoreExampleCodeInfo > getQoreExampleRequest(string method, string path)
returns a hash of example Qore code for the given request
abstract setBasePathImpl(string basePath)
overrides the basePath value
hash< RestQoreExampleCodeInfo > getQoreExampleResponse(string method, string path, int code)
returns example Qore code for the given response
abstract setTimeZoneLocaleImpl(*TimeZone tz)
Allows the time zone locale to be set for serialization / deserialization.
abstract string getTargetUrlImpl()
returns the target URL for the schema
constructor(Logger::LoggerInterface logger)
Creates the object with the given logger.
abstract *TimeZone getTimeZoneLocaleImpl()
Returns the time zone locale used for serialization / deserialization.
constructor()
Creates the object without a logger.
abstract hash< string, list< string > > getPathOperationHashImpl()
returns a hash of URI paths as keys with values as lists of supported HTTP methods
hash< RestRequestServerInfo > parseRequest(string method, string path, *data http_body, reference< hash< auto > > headers)
processes and parses a client request and returns the deserialized message body (if any)
abstract string getBasePathImpl()
returns the base path prefix for all requests in this schema
hash< HttpResponseInfo > processResponse(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.
setTimeZoneLocale(*TimeZone tz)
Allows the time zone locale to be set for serialization / deserialization.
string getHash()
returns a unique hash for the schema that can be used to compare schemas
DataProvider::AbstractDataProvider getDataProvider(HTTPClient rest)
returns a data provider object for this connection, if supported by any REST schema validator object
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< auto > hdr)
parses and validates the response from the server and returns a hash of the processed info
abstract 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
abstract hash< RestQoreExampleCodeInfo > getQoreExampleRequestImpl(string method, string path)
returns a hash of example Qore code for the given request
abstract 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 ...
hash< RestExampleResponseInfo > getExampleResponse(string method, string path, int code, *softlist< string > content_types)
returns a hash of example message information for the given request
setBasePath(string basePath)
overrides the basePath value
null REST validator; no schema is used but default serialization and deserialization is performed
Definition: RestSchemaValidator.qm.dox.h:557
setBasePathImpl(string basePath)
overrides the basePath value
string getHashImpl()
returns a unique hash for the schema that can be used to compare schemas
const DataDeserializationSupport
Data deserialization support MIME types to codes and de/serialization functions.
Definition: RestSchemaValidator.qm.dox.h:623
hash< RestExampleRequestInfo > getExampleRequestImpl(string method, string path, *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:561
*TimeZone getTimeZoneLocaleImpl()
Returns the time zone locale used for serialization / deserialization.
hash< 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-...
const NullSchemaHashStr
a unique hash for the null schema
Definition: RestSchemaValidator.qm.dox.h:658
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 ...
setTimeZoneLocaleImpl(*TimeZone tz)
Allows the time zone locale to be set for serialization / deserialization.
string getTargetUrlImpl()
returns the target URL for the schema
bool managesUriPath()
returns True if the provider manages the URI path
hash< RestQoreExampleCodeInfo > getQoreExampleResponseImpl(string method, string path, int code)
returns example Qore code for the given response
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)
hash< RestExampleResponseInfo > getExampleResponseImpl(string method, string path, int code, *softlist< string > content_types)
returns a hash of example message information for the given request
string getBasePathImpl()
returns the base path prefix for all requests in this schema
hash< string, list< string > > getPathOperationHashImpl()
returns a hash of URI paths as keys with values as lists of supported HTTP methods
hash< 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
bool checkResponseContentTypeHeader(reference< hash< HttpResponseInfo > > resp, auto body, *hash< auto > headers, *softlist< string > content_types)
Check if the headers contain a content-type header which is accepted and if so, modify the response h...
main namespace for all public RestSchemaValidator declarations
Definition: RestSchemaValidator.qm.dox.h:111
a hash giving example info for example HTTP request messages
Definition: RestSchemaValidator.qm.dox.h:153
string body
the HTTP request body
Definition: RestSchemaValidator.qm.dox.h:159
hash< auto > hdr
the HTTP request header hash
Definition: RestSchemaValidator.qm.dox.h:157
string request_uri
the HTTP request URI
Definition: RestSchemaValidator.qm.dox.h:155
a hash giving example info for example HTTP response messages
Definition: RestSchemaValidator.qm.dox.h:163
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:167
string response_uri
the HTTP response URI
Definition: RestSchemaValidator.qm.dox.h:165
string body
the HTTP response body
Definition: RestSchemaValidator.qm.dox.h:171
hash< auto > hdr
the HTTP response header hash
Definition: RestSchemaValidator.qm.dox.h:169
a hash giving example information for building a request or response in Qore
Definition: RestSchemaValidator.qm.dox.h:175
string example
a string giving the example code generation
Definition: RestSchemaValidator.qm.dox.h:180
hash< string, string > hashdecls()
a hash giving example hashdecl declarations for hash objects in the message; keys are hashdecl names; str...
a hash of information about a client-side request
Definition: RestSchemaValidator.qm.dox.h:113
*list< string > response_content
Content-Type for the response message if available.
Definition: RestSchemaValidator.qm.dox.h:121
*data body
the serialized message body hash
Definition: RestSchemaValidator.qm.dox.h:123
string content
the Content-Type for the message
Definition: RestSchemaValidator.qm.dox.h:117
string uri_path
the URI path for the request
Definition: RestSchemaValidator.qm.dox.h:115
a hash of information about a server-side request
Definition: RestSchemaValidator.qm.dox.h:127
*hash< auto > path_args
any path arguments
Definition: RestSchemaValidator.qm.dox.h:133
hash< auto > info
miscellaneous free-form info about the parsed request
Definition: RestSchemaValidator.qm.dox.h:137
string path
the URI path without query arguments
Definition: RestSchemaValidator.qm.dox.h:129
*hash< auto > query
any query arguments
Definition: RestSchemaValidator.qm.dox.h:131
auto body
the deserialized message body data
Definition: RestSchemaValidator.qm.dox.h:135
a hash of information about a response from the server
Definition: RestSchemaValidator.qm.dox.h:141
hash< auto > hdr
the HTTP headers received
Definition: RestSchemaValidator.qm.dox.h:147
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:143
hash< auto > info
miscellaneous free-form info about the parsed response
Definition: RestSchemaValidator.qm.dox.h:149
auto body
the deserialized message body
Definition: RestSchemaValidator.qm.dox.h:145