RestSchemaValidator.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* RestSchemaValidator.qm Copyright (C) 2017 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: string (auto s) { return sprintf("%s", s); },
};
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": string (string s) { return 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::RestExampleResponseInfo::response_uri
string response_uri
the HTTP response URI
Definition: RestSchemaValidator.qm.dox.h:109
RestSchemaValidator::RestRequestServerInfo::info
hash info
miscellaneous free-form info about the parsed request
Definition: RestSchemaValidator.qm.dox.h:81
RestSchemaValidator::RestExampleRequestInfo::body
string body
the HTTP request body
Definition: RestSchemaValidator.qm.dox.h:103
sprintf
string sprintf(string fmt,...)
RestSchemaValidator
main namespace for all public RestSchemaValidator declarations
Definition: RestSchemaValidator.qm.dox.h:61
RestSchemaValidator::RestExampleRequestInfo
a hash giving example info for example HTTP request messages
Definition: RestSchemaValidator.qm.dox.h:97
RestSchemaValidator::AbstractRestSchemaValidator
abstract REST schema validation classes
Definition: RestSchemaValidator.qm.dox.h:128
RestSchemaValidator::RestExampleResponseInfo::hdr
hash hdr
the HTTP response header hash
Definition: RestSchemaValidator.qm.dox.h:113
True
const True
RestSchemaValidator::RestResponseClientInfo
a hash of information about a response from the server
Definition: RestSchemaValidator.qm.dox.h:85
RestSchemaValidator::RestQoreExampleCodeInfo::example
string example
a string giving the example code generation
Definition: RestSchemaValidator.qm.dox.h:124
RestSchemaValidator::RestRequestClientInfo
a hash of information about a client-side request
Definition: RestSchemaValidator.qm.dox.h:63
RestSchemaValidator::RestResponseClientInfo::hdr
hash hdr
the HTTP headers received
Definition: RestSchemaValidator.qm.dox.h:91
RestSchemaValidator::RestRequestServerInfo::body
auto body
the deserialized message body data
Definition: RestSchemaValidator.qm.dox.h:79
RestSchemaValidator::RestRequestClientInfo::content
string content
the Content-Type for the message
Definition: RestSchemaValidator.qm.dox.h:67
RestSchemaValidator::RestQoreExampleCodeInfo
a hash giving example information for building a request or response in Qore
Definition: RestSchemaValidator.qm.dox.h:119
RestSchemaValidator::RestExampleResponseInfo::code
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:111
RestSchemaValidator::NullRestSchemaValidator
null REST validator; no schema is used but default serialization and deserialization is performed ...
Definition: RestSchemaValidator.qm.dox.h:409
RestSchemaValidator::RestResponseClientInfo::info
hash info
miscellaneous free-form info about the parsed response
Definition: RestSchemaValidator.qm.dox.h:93
RestSchemaValidator::RestRequestServerInfo
a hash of information about a server-side request
Definition: RestSchemaValidator.qm.dox.h:73
RestSchemaValidator::RestExampleResponseInfo
a hash giving example info for example HTTP response messages
Definition: RestSchemaValidator.qm.dox.h:107
type
string type(auto arg)
RestSchemaValidator::RestExampleRequestInfo::request_uri
string request_uri
the HTTP request URI
Definition: RestSchemaValidator.qm.dox.h:99
RestSchemaValidator::RestResponseClientInfo::code
int code
the HTTP status code
Definition: RestSchemaValidator.qm.dox.h:87
RestSchemaValidator::RestExampleResponseInfo::body
string body
the HTTP response body
Definition: RestSchemaValidator.qm.dox.h:115
string
string string(softstring str, *string enc)
RestSchemaValidator::RestExampleRequestInfo::hdr
hash hdr
the HTTP request header hash
Definition: RestSchemaValidator.qm.dox.h:101
RestSchemaValidator::RestResponseClientInfo::body
auto body
the deserialized message body
Definition: RestSchemaValidator.qm.dox.h:89
RestSchemaValidator::RestRequestServerInfo::path
string path
the URI path without query arguments
Definition: RestSchemaValidator.qm.dox.h:75
RestSchemaValidator::RestRequestServerInfo::query
*hash query
any query arguments
Definition: RestSchemaValidator.qm.dox.h:77
hash
hash hash(object obj)
RestSchemaValidator::RestRequestClientInfo::uri_path
string uri_path
the URI path for the request
Definition: RestSchemaValidator.qm.dox.h:65
RestSchemaValidator::RestRequestClientInfo::body
*data body
the serialized message body hash
Definition: RestSchemaValidator.qm.dox.h:69