-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.cpp
65 lines (54 loc) · 2.42 KB
/
example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Copyright (c) 2024 Muhammad Nawaz
* Licensed under the MIT License. See LICENSE file for more information.
*/
// [ END OF LICENSE c6bd0f49d040fca8d8a9cb05868e66aa63f0e2e0 ]
#include <oas_validator.hpp>
#include <iostream>
#include <vector>
int main()
{
OASValidator OasValidator(SPEC_PATH);
std::string err_msg;
if (ValidationError::NONE != OasValidator.ValidateRoute("GETT", "/test/dummy", err_msg)) {
std::cout << err_msg << std::endl;
}
if (ValidationError::NONE != OasValidator.ValidateRoute("GET", "/test/dummy", err_msg)) {
std::cout << err_msg << std::endl;
}
if (ValidationError::NONE != OasValidator.ValidateRoute("GET", "/test/invalid", err_msg)) {
std::cout << err_msg << std::endl;
}
if (ValidationError::NONE != OasValidator.ValidatePathParam("GET", "/test/integer_simple_true/1001", err_msg)) {
std::cout << err_msg << std::endl;
}
if (ValidationError::NONE !=
OasValidator.ValidatePathParam("GET", "/test/integer_simple_true/not_an_integer", err_msg)) {
std::cout << err_msg << std::endl;
}
if (ValidationError::NONE !=
OasValidator.ValidateQueryParam("GET", "/test/query_integer_form_true?param=not_an_integer", err_msg)) {
std::cout << err_msg << std::endl;
}
std::unordered_map<std::string, std::string> headers;
headers["intHeader"] = "not_an_integer";
if (ValidationError::NONE != OasValidator.ValidateHeaders("GET", "/test/header_single1", headers, err_msg)) {
std::cout << err_msg << std::endl;
}
if (ValidationError::NONE !=
OasValidator.ValidateRequest(
"POST",
"/test/all/123/abc/str1,str2/"
"field1,0,field2,string?param4=string1¶m4=string2¶m5=field1,0,field2,string¶m6=field1,0,field2,"
"string&"
"param7=field1,0,field2,string¶m8=field1,0,field2,string¶m9=field1,0,field2,string¶m10=false",
"{\"field1\":123,\"field2\":\"abc\",\"field3\":[\"abc\",\"def\"],\"field4\":{\"subfield1\":123,"
"\"subfield2\":"
"\"abc\"},\"field5\":{\"subfield1\":123},\"field6\":true,\"field7\":[123,456],\"field8\":[123,456],"
"\"field9\":"
"\"abc\",\"field10\":\"option1\",\"field11\":{\"field\":123},\"field12\":[{\"name\":\"abc\"},{\"name\":"
"\"def\"}]}",
headers, err_msg)) {
std::cout << err_msg << std::endl;
}
}