RestSchemaValidator.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* RestSchemaValidator.qm Copyright (C) 2017 - 2018 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// make sure we have the required qore version
// requires the HttpServerUtil module
// need mime definitions
namespace RestSchemaValidator {
public struct RestRequestClientInfo {
string uri_path;
string content;
*data body;
};
public struct RestRequestServerInfo {
string path;
*hash query;
auto body;
hash info;
};
public struct RestResponseClientInfo {
int code;
auto body;
hash hdr;
hash info;
};
public struct RestExampleRequestInfo {
string request_uri;
hash hdr;
string body;
};
public struct RestExampleResponseInfo {
string response_uri;
int code;
hash hdr;
string body;
};
public struct RestQoreExampleCodeInfo {
hash<string, string> hashdecls();
string example;
};
class AbstractRestSchemaValidator {
public:
string getTargetUrl();
hash<RestRequestClientInfo> processRequest(string method, string path, auto body, *hash headers, *softlist<string> content_types);
hash<RestRequestServerInfo> parseRequest(string method, string path, *data http_body, reference<hash> headers);
hash<HttpResponseInfo> processResponse(string method, string path, int code, auto response_body, *hash headers, *softlist<string> content_types);
hash<RestResponseClientInfo> parseResponse(string method, string path, int code, *data response_body, hash hdr);
hash<RestQoreExampleCodeInfo> getQoreExampleRequest(string method, string path);
hash<RestExampleRequestInfo> getExampleRequest(string method, string path, *softlist<string> content_types);
hash<RestQoreExampleCodeInfo> getQoreExampleResponse(string method, string path, int code);
hash<RestExampleResponseInfo> getExampleResponse(string method, string path, int code, *softlist<string> content_types);
hash<string, list<string>> getPathOperationHash();
string getBasePath();
setBasePath(string basePath);
private:
abstract string getTargetUrlImpl();
public:
private:
abstract hash<RestRequestClientInfo> processRequestImpl(string method, string path, auto body, *hash headers, *softlist<string> content_types);
public:
private:
abstract hash<RestRequestServerInfo> parseRequestImpl(string method, string path, *data http_body, reference<hash> headers);
public:
private:
abstract hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, any response_body, *hash headers, *softlist<string> content_types);
public:
private:
abstract hash<RestResponseClientInfo> parseResponseImpl(string method, string path, int code, *data response_body, hash hdr);
public:
private:
abstract hash<string, list<string>> getPathOperationHashImpl();
public:
private:
abstract string getBasePathImpl();
public:
private:
abstract setBasePathImpl(string basePath);
public:
private:
abstract hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
public:
private:
abstract hash<RestExampleRequestInfo> getExampleRequestImpl(string method, string path, *softlist<string> content_types);
public:
private:
abstract hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
public:
private:
abstract hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code, *softlist<string> content_types);
public:
};
class NullRestSchemaValidator : public AbstractRestSchemaValidator {
public:
public :
const DataSerializationSupport = {
MimeTypeJson: \make_json(),
MimeTypeYamlRpc: \make_yaml(),
MimeTypeYaml: \make_yaml(),
MimeTypeXml: \make_xmlrpc_value(),
MimeTypeXmlApp;
,
MimeTypeFormUrlEncoded;
,
MimeTypeText;
,
MimeTypeOctetStream;
,
};
const DataSerializationSupportList = keys DataSerializationSupport;
const DeserializeYaml = (
"code": "yaml",
"in": \parse_yaml(),
);
const DeserializeXml = (
"code": "xml",
"arg": True,
"in": auto (string xml, reference<string> type) {
try {
on_success type = "xml";
return parse_xmlrpc_value(xml);
}
catch (hash<ExceptionInfo> ex);
},
);
const DataDeserializationSupport = {
MimeTypeFormUrlEncoded: (
"code": "url",
"in": \mime_parse_form_urlencoded_string(),
),
MimeTypeJson: (
"code": "json",
"in": \parse_json(),
),
MimeTypeYamlRpc: DeserializeYaml,
MimeTypeYaml: DeserializeYaml,
MimeTypeXml: DeserializeXml,
MimeTypeXmlApp: DeserializeXml,
MimeTypeText: (
"code": "text",
"in": data (data s) { return s; },
),
MimeTypeOctetStream: {
"code": "bin",
"in": binary (data s) {
return s.typeCode() == NT_BINARY ? s : binary(s);
},
},
};
public:
private:
string getTargetUrlImpl();
public:
private:
hash<RestRequestClientInfo> processRequestImpl(string method, string path, auto body, *hash headers, *softlist<string> content_types);
public:
private:
hash<RestRequestServerInfo> parseRequestImpl(string method, string path, *data http_body, reference<hash> headers);
public:
private:
hash<HttpResponseInfo> processResponseImpl(string method, string path, int code, auto response_body, *hash headers, *softlist<string> content_types);
public:
private:
hash<RestResponseClientInfo> parseResponseImpl(string method, string path, int code, *data response_body, hash hdr);
public:
private:
hash<string, list<string>> getPathOperationHashImpl();
public:
private:
string getBasePathImpl();
public:
setBasePathImpl(string basePath);
private:
hash<RestQoreExampleCodeInfo> getQoreExampleRequestImpl(string method, string path);
public:
private:
hash<RestExampleRequestInfo> getExampleRequestImpl(string method, string path, *softlist<string> content_types);
public:
private:
hash<RestQoreExampleCodeInfo> getQoreExampleResponseImpl(string method, string path, int code);
public:
private:
hash<RestExampleResponseInfo> getExampleResponseImpl(string method, string path, int code, *softlist<string> content_types);
public:
};
};
RestSchemaValidator::AbstractRestSchemaValidator::getPathOperationHashImpl
abstract hash< string, list< string > > getPathOperationHashImpl()
returns a hash of URI paths as keys with values as lists of supported HTTP methods ...
RestSchemaValidator::RestExampleResponseInfo::response_uri
string response_uri
the HTTP response URI
Definition: RestSchemaValidator.qm.dox.h:112
RestSchemaValidator::RestRequestServerInfo::info
hash info
miscellaneous free-form info about the parsed request
Definition: RestSchemaValidator.qm.dox.h:84
RestSchemaValidator::NullRestSchemaValidator::getExampleResponseImpl
hash< RestExampleResponseInfo > getExampleResponseImpl(string method, string path, int code, *softlist< string > content_types)
returns a hash of example message information for the given request
RestSchemaValidator::NullRestSchemaValidator::DataSerializationSupport
const DataSerializationSupport
Data serialization support mapping codes to MIME types and de/serialization functions.
Definition: RestSchemaValidator.qm.dox.h:417
RestSchemaValidator::RestExampleRequestInfo::body
string body
the HTTP request body
Definition: RestSchemaValidator.qm.dox.h:106
RestSchemaValidator
main namespace for all public RestSchemaValidator declarations
Definition: RestSchemaValidator.qm.dox.h:64
RestSchemaValidator::RestExampleRequestInfo
a hash giving example info for example HTTP request messages
Definition: RestSchemaValidator.qm.dox.h:100
RestSchemaValidator::AbstractRestSchemaValidator::getQoreExampleRequestImpl
abstract hash< RestQoreExampleCodeInfo > getQoreExampleRequestImpl(string method, string path)
returns a hash of example Qore code for the given request
RestSchemaValidator::NullRestSchemaValidator::parseRequestImpl
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) ...
RestSchemaValidator::AbstractRestSchemaValidator
abstract REST schema validation classes
Definition: RestSchemaValidator.qm.dox.h:131
RestSchemaValidator::NullRestSchemaValidator::getPathOperationHashImpl
hash< string, list< string > > getPathOperationHashImpl()
returns a hash of URI paths as keys with values as lists of supported HTTP methods ...
RestSchemaValidator::NullRestSchemaValidator::getExampleRequestImpl
hash< RestExampleRequestInfo > getExampleRequestImpl(string method, string path, *softlist< string > content_types)
returns a hash of example message information for the given request
RestSchemaValidator::AbstractRestSchemaValidator::getTargetUrlImpl
abstract string getTargetUrlImpl()
returns the target URL for the schema
RestSchemaValidator::NullRestSchemaValidator::setBasePathImpl
setBasePathImpl(string basePath)
overrides the basePath value
RestSchemaValidator::RestExampleResponseInfo::hdr
hash hdr
the HTTP response header hash
Definition: RestSchemaValidator.qm.dox.h:116
True
const True
RestSchemaValidator::RestResponseClientInfo
a hash of information about a response from the server
Definition: RestSchemaValidator.qm.dox.h:88
RestSchemaValidator::NullRestSchemaValidator::getBasePathImpl
string getBasePathImpl()
returns the base path prefix for all requests in this schema
RestSchemaValidator::AbstractRestSchemaValidator::getQoreExampleResponse
hash< RestQoreExampleCodeInfo > getQoreExampleResponse(string method, string path, int code)
returns example Qore code for the given response
binary
binary binary()
RestSchemaValidator::RestQoreExampleCodeInfo::example
string example
a string giving the example code generation
Definition: RestSchemaValidator.qm.dox.h:127
RestSchemaValidator::AbstractRestSchemaValidator::parseRequest
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) ...
RestSchemaValidator::AbstractRestSchemaValidator::getExampleRequestImpl
abstract hash< RestExampleRequestInfo > getExampleRequestImpl(string method, string path, *softlist< string > content_types)
returns a hash of example message information for the given request
RestSchemaValidator::RestRequestClientInfo
a hash of information about a client-side request
Definition: RestSchemaValidator.qm.dox.h:66
RestSchemaValidator::RestResponseClientInfo::hdr
hash hdr
the HTTP headers received
Definition: RestSchemaValidator.qm.dox.h:94
RestSchemaValidator::AbstractRestSchemaValidator::getTargetUrl
string getTargetUrl()
returns the target URL for the schema
RestSchemaValidator::NullRestSchemaValidator::processResponseImpl
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 ...
RestSchemaValidator::AbstractRestSchemaValidator::getExampleResponse
hash< RestExampleResponseInfo > getExampleResponse(string method, string path, int code, *softlist< string > content_types)
returns a hash of example message information for the given request
RestSchemaValidator::AbstractRestSchemaValidator::setBasePathImpl
abstract setBasePathImpl(string basePath)
overrides the basePath value
RestSchemaValidator::AbstractRestSchemaValidator::getExampleResponseImpl
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
RestSchemaValidator::RestRequestServerInfo::body
auto body
the deserialized message body data
Definition: RestSchemaValidator.qm.dox.h:82
RestSchemaValidator::AbstractRestSchemaValidator::getPathOperationHash
hash< string, list< string > > getPathOperationHash()
returns a hash of URI paths as keys with values as lists of supported HTTP methods ...
RestSchemaValidator::AbstractRestSchemaValidator::parseResponse
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 ...
RestSchemaValidator::AbstractRestSchemaValidator::processRequest
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-...
RestSchemaValidator::NullRestSchemaValidator::processRequestImpl
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-...
RestSchemaValidator::NullRestSchemaValidator::getQoreExampleResponseImpl
hash< RestQoreExampleCodeInfo > getQoreExampleResponseImpl(string method, string path, int code)
returns example Qore code for the given response
RestSchemaValidator::AbstractRestSchemaValidator::getBasePath
string getBasePath()
returns the base path prefix for all requests in this schema
RestSchemaValidator::RestRequestClientInfo::content
string content
the Content-Type for the message
Definition: RestSchemaValidator.qm.dox.h:70
RestSchemaValidator::AbstractRestSchemaValidator::parseResponseImpl
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 ...
RestSchemaValidator::RestQoreExampleCodeInfo
a hash giving example information for building a request or response in Qore
Definition: RestSchemaValidator.qm.dox.h:122
RestSchemaValidator::RestExampleResponseInfo::code
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:114
RestSchemaValidator::NullRestSchemaValidator::getTargetUrlImpl
string getTargetUrlImpl()
returns the target URL for the schema
RestSchemaValidator::NullRestSchemaValidator::DataDeserializationSupport
const DataDeserializationSupport
Data deserialization support MIME types to codes and de/serialization functions.
Definition: RestSchemaValidator.qm.dox.h:452
RestSchemaValidator::NullRestSchemaValidator
null REST validator; no schema is used but default serialization and deserialization is performed ...
Definition: RestSchemaValidator.qm.dox.h:412
RestSchemaValidator::RestResponseClientInfo::info
hash info
miscellaneous free-form info about the parsed response
Definition: RestSchemaValidator.qm.dox.h:96
RestSchemaValidator::RestRequestServerInfo
a hash of information about a server-side request
Definition: RestSchemaValidator.qm.dox.h:76
RestSchemaValidator::RestExampleResponseInfo
a hash giving example info for example HTTP response messages
Definition: RestSchemaValidator.qm.dox.h:110
NT_BINARY
const NT_BINARY
RestSchemaValidator::AbstractRestSchemaValidator::processResponse
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 ...
type
string type(auto arg)
RestSchemaValidator::RestExampleRequestInfo::request_uri
string request_uri
the HTTP request URI
Definition: RestSchemaValidator.qm.dox.h:102
RestSchemaValidator::RestResponseClientInfo::code
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:90
RestSchemaValidator::AbstractRestSchemaValidator::getQoreExampleResponseImpl
abstract hash< RestQoreExampleCodeInfo > getQoreExampleResponseImpl(string method, string path, int code)
returns example Qore code for the given response
RestSchemaValidator::RestExampleResponseInfo::body
string body
the HTTP response body
Definition: RestSchemaValidator.qm.dox.h:118
RestSchemaValidator::NullRestSchemaValidator::getQoreExampleRequestImpl
hash< RestQoreExampleCodeInfo > getQoreExampleRequestImpl(string method, string path)
returns a hash of example Qore code for the given request
RestSchemaValidator::AbstractRestSchemaValidator::getQoreExampleRequest
hash< RestQoreExampleCodeInfo > getQoreExampleRequest(string method, string path)
returns a hash of example Qore code for the given request
RestSchemaValidator::AbstractRestSchemaValidator::setBasePath
setBasePath(string basePath)
overrides the basePath value
RestSchemaValidator::RestExampleRequestInfo::hdr
hash hdr
the HTTP request header hash
Definition: RestSchemaValidator.qm.dox.h:104
RestSchemaValidator::AbstractRestSchemaValidator::processResponseImpl
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 ...
RestSchemaValidator::RestResponseClientInfo::body
auto body
the deserialized message body
Definition: RestSchemaValidator.qm.dox.h:92
RestSchemaValidator::RestRequestServerInfo::path
string path
the URI path without query arguments
Definition: RestSchemaValidator.qm.dox.h:78
RestSchemaValidator::NullRestSchemaValidator::parseResponseImpl
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 ...
RestSchemaValidator::RestRequestServerInfo::query
*hash query
any query arguments
Definition: RestSchemaValidator.qm.dox.h:80
RestSchemaValidator::AbstractRestSchemaValidator::getExampleRequest
hash< RestExampleRequestInfo > getExampleRequest(string method, string path, *softlist< string > content_types)
returns a hash of example message information for the given request
hash
hash hash(object obj)
RestSchemaValidator::AbstractRestSchemaValidator::getBasePathImpl
abstract string getBasePathImpl()
returns the base path prefix for all requests in this schema
RestSchemaValidator::RestQoreExampleCodeInfo::hashdecls
hash< string, string > hashdecls()
a hash giving example struct declarations for hash objects in the message; keys are struct names; str...
RestSchemaValidator::RestRequestClientInfo::uri_path
string uri_path
the URI path for the request
Definition: RestSchemaValidator.qm.dox.h:68
RestSchemaValidator::AbstractRestSchemaValidator::parseRequestImpl
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) ...
RestSchemaValidator::AbstractRestSchemaValidator::processRequestImpl
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-...
RestSchemaValidator::RestRequestClientInfo::body
*data body
the serialized message body hash
Definition: RestSchemaValidator.qm.dox.h:72