Class OASValidator#

Class Documentation#

class OASValidator#

Class that provides API for HTTP requests validation against OAS validation.

The OASValidator class offers various methods for validating REST requests against a defined OAS (OpenAPI Specification) file.

Public Functions

explicit OASValidator(const std::string &oas_specs)#

Constructor that takes the path to the OAS specification file.

Note

The OAS specification can be provided as a file path or as a JSON string.

Parameters

oas_specs – File path to the OAS specification in JSON format or JSON string containing the OAS specification.

ValidationError ValidateRoute(const std::string &method, const std::string &http_path, std::string &error_msg)#

Validates the HTTP method and route against the OpenAPI specification.

This function performs the following validation sequence:

  1. HTTP method

  2. Route

Note

The error_msg argument will be populated with a JSON string in case of a validation error.

Parameters
  • method – The HTTP method as a std::string (e.g., “GET”, “POST”).

  • http_path – The HTTP path as a std::string (e.g., “/api/v1/resource”).

  • error_msg – Reference to a std::string where the error message will be stored in case of a validation error.

Returns

ValidationError enum indicating the result of the validation. Possible values include:

ValidationError ValidateBody(const std::string &method, const std::string &http_path, const std::string &json_body, std::string &error_msg)#

Validates the JSON body of the HTTP request against the OpenAPI specification.

This function performs the following validation sequence:

  1. HTTP method

  2. Route

  3. Body schema

Note

The error_msg argument will be populated with a JSON string in case of a validation error.

Parameters
  • method – The HTTP method as a std::string (e.g., “POST”, “PUT”).

  • http_path – The HTTP path as a std::string (e.g., “/api/v1/resource”).

  • json_body – The JSON body of the HTTP request as a std::string.

  • error_msg – Reference to a std::string where the error message will be stored in case of a validation error.

Returns

ValidationError enum indicating the result of the validation. Possible values include:

ValidationError ValidatePathParam(const std::string &method, const std::string &http_path, std::string &error_msg)#

Validates the path parameters of the HTTP request against the OpenAPI specification.

This function performs the following validation sequence:

  1. HTTP method

  2. Route

  3. Path parameters (in the sequence provided in the OpenAPI spec)

Note

The error_msg argument will be populated with a JSON string in case of a validation error.

Parameters
  • method – The HTTP method as a std::string (e.g., “GET”, “DELETE”).

  • http_path – The HTTP path with parameters as a std::string (e.g., “/api/v1/resource/{id}”).

  • error_msg – Reference to a std::string where the error message will be stored in case of a validation error.

Returns

ValidationError enum indicating the result of the validation. Possible values include:

ValidationError ValidateQueryParam(const std::string &method, const std::string &http_path, std::string &error_msg)#

Validates the query parameters of the HTTP request against the OpenAPI specification.

This function performs the following validation sequence:

  1. HTTP method

  2. Route

  3. Query parameters (in the sequence provided in the OpenAPI spec)

Note

The error_msg argument will be populated with a JSON string in case of a validation error.

Parameters
  • method – The HTTP method as a std::string (e.g., “GET”, “DELETE”).

  • http_path – The HTTP path including query parameters as a std::string (e.g., “/api/v1/resource?name=value”).

  • error_msg – Reference to a std::string where the error message will be stored in case of a validation error.

Returns

ValidationError enum indicating the result of the validation. Possible values include:

ValidationError ValidateHeaders(const std::string &method, const std::string &http_path, const std::unordered_map<std::string, std::string> &headers, std::string &error_msg)#

Validates the HTTP headers of the request against the OpenAPI specification.

This function performs the following validation sequence:

  1. HTTP method

  2. Route

  3. Header parameters

Note

The error_msg argument will be populated with a JSON string in case of a validation error.

Parameters
  • method – The HTTP method as a std::string (e.g., “GET”, “POST”).

  • http_path – The HTTP path as a std::string (e.g., “/api/v1/resource”).

  • headers – The HTTP headers as an std::unordered_map from std::string to std::string.

  • error_msg – Reference to a std::string where the error message will be stored in case of a validation error.

Returns

ValidationError enum indicating the result of the validation. Possible return values include:

ValidationError ValidateRequest(const std::string &method, const std::string &http_path, std::string &error_msg)#

Validates the entire HTTP request against the OpenAPI specification.

This function performs a comprehensive validation of the entire HTTP request based on the following sequence:

  1. HTTP method

  2. Route

  3. Path parameters (if specified in specs)

  4. Query parameters (if specified in specs)

Note

The error_msg argument will be populated with a JSON string in case of a validation error.

Parameters
  • method – The HTTP method as a std::string (e.g., “POST”, “PUT”).

  • http_path – The HTTP path as a std::string (e.g., “/api/v1/resource”).

  • error_msg – Reference to a std::string where the error message will be stored in case of a validation error.

Returns

ValidationError enum indicating the result of the validation. Possible return values include:

ValidationError ValidateRequest(const std::string &method, const std::string &http_path, const std::string &json_body, std::string &error_msg)#

Validates the entire HTTP request including JSON body against the OpenAPI specification.

This overloaded function performs a comprehensive validation of the entire HTTP request, including the JSON body, based on the following sequence:

  1. HTTP method

  2. Route

  3. Body schema

  4. Path parameters (if specified in specs)

  5. Query parameters (if specified in specs)

Note

The error_msg argument will be populated with a JSON string in case of a validation error.

Parameters
  • method – The HTTP method as a std::string (e.g., “POST”, “PUT”).

  • http_path – The HTTP path as a std::string (e.g., “/api/v1/resource”).

  • json_body – The JSON body of the HTTP request as a std::string.

  • error_msg – Reference to a std::string where the error message will be stored in case of a validation error.

Returns

ValidationError enum indicating the result of the validation. Possible return values include:

ValidationError ValidateRequest(const std::string &method, const std::string &http_path, const std::unordered_map<std::string, std::string> &headers, std::string &error_msg)#

Validates the entire HTTP request, including headers, against the OpenAPI specification.

This overloaded function performs a comprehensive validation of the entire HTTP request, including HTTP headers, based on the following sequence:

  1. HTTP method

  2. Route

  3. Path parameters (if specified in specs)

  4. Query parameters (if specified in specs)

  5. Header parameters

Note

The error_msg argument will be populated with a JSON string in case of a validation error.

Parameters
  • method – The HTTP method as a std::string (e.g., “GET”, “DELETE”).

  • http_path – The HTTP path as a std::string (e.g., “/api/v1/resource”).

  • headers – The HTTP headers as an std::unordered_map of std::string to std::string.

  • error_msg – Reference to a std::string where the error message will be stored in case of a validation error.

Returns

ValidationError enum indicating the result of the validation. Possible return values include:

ValidationError ValidateRequest(const std::string &method, const std::string &http_path, const std::string &json_body, const std::unordered_map<std::string, std::string> &headers, std::string &error_msg)#

Validates the entire HTTP request, including JSON body and headers, against the OpenAPI specification.

This overloaded function performs a comprehensive validation of the entire HTTP request, including the JSON body and HTTP headers, based on the following sequence:

  1. HTTP method

  2. Route

  3. Body schema

  4. Path parameters (if specified in specs)

  5. Query parameters (if specified in specs)

  6. Header parameters

Note

The error_msg argument will be populated with a JSON string in case of a validation error.

Parameters
  • method – The HTTP method as a std::string (e.g., “POST”, “PUT”).

  • http_path – The HTTP path as a std::string (e.g., “/api/v1/resource”).

  • json_body – The JSON body of the HTTP request as a std::string.

  • headers – The HTTP headers as an std::unordered_map of std::string to std::string.

  • error_msg – Reference to a std::string where the error message will be stored in case of a validation error.

Returns

ValidationError enum indicating the result of the validation. Possible return values include:

~OASValidator()#