Fawkes API Fawkes Development Version
PluginOpResponse.cpp
1
2/****************************************************************************
3 * PluginOpResponse
4 * (auto-generated, do not modify directly)
5 *
6 * Fawkes Plugin REST API.
7 * List, load, and unload plugins.
8 *
9 * API Contact: Tim Niemueller <niemueller@kbsg.rwth-aachen.de>
10 * API Version: v1beta1
11 * API License: Apache 2.0
12 ****************************************************************************/
13
14#include "PluginOpResponse.h"
15
16#include <rapidjson/document.h>
17#include <rapidjson/prettywriter.h>
18#include <rapidjson/stringbuffer.h>
19#include <rapidjson/writer.h>
20
21#include <sstream>
22
24{
25}
26
27PluginOpResponse::PluginOpResponse(const std::string &json)
28{
29 from_json(json);
30}
31
32PluginOpResponse::PluginOpResponse(const rapidjson::Value &v)
33{
35}
36
38{
39}
40
41std::string
42PluginOpResponse::to_json(bool pretty) const
43{
44 rapidjson::Document d;
45
46 to_json_value(d, d);
47
48 rapidjson::StringBuffer buffer;
49 if (pretty) {
50 rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
51 d.Accept(writer);
52 } else {
53 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
54 d.Accept(writer);
55 }
56
57 return buffer.GetString();
58}
59
60void
61PluginOpResponse::to_json_value(rapidjson::Document &d, rapidjson::Value &v) const
62{
63 rapidjson::Document::AllocatorType &allocator = d.GetAllocator();
64 v.SetObject();
65 // Avoid unused variable warnings
66 (void)allocator;
67
68 if (kind_) {
69 rapidjson::Value v_kind;
70 v_kind.SetString(*kind_, allocator);
71 v.AddMember("kind", v_kind, allocator);
72 }
73 if (apiVersion_) {
74 rapidjson::Value v_apiVersion;
75 v_apiVersion.SetString(*apiVersion_, allocator);
76 v.AddMember("apiVersion", v_apiVersion, allocator);
77 }
78 if (name_) {
79 rapidjson::Value v_name;
80 v_name.SetString(*name_, allocator);
81 v.AddMember("name", v_name, allocator);
82 }
83 if (state_) {
84 rapidjson::Value v_state;
85 v_state.SetString(*state_, allocator);
86 v.AddMember("state", v_state, allocator);
87 }
88 if (message_) {
89 rapidjson::Value v_message;
90 v_message.SetString(*message_, allocator);
91 v.AddMember("message", v_message, allocator);
92 }
93}
94
95void
96PluginOpResponse::from_json(const std::string &json)
97{
98 rapidjson::Document d;
99 d.Parse(json);
100
102}
103
104void
105PluginOpResponse::from_json_value(const rapidjson::Value &d)
106{
107 if (d.HasMember("kind") && d["kind"].IsString()) {
108 kind_ = d["kind"].GetString();
109 }
110 if (d.HasMember("apiVersion") && d["apiVersion"].IsString()) {
111 apiVersion_ = d["apiVersion"].GetString();
112 }
113 if (d.HasMember("name") && d["name"].IsString()) {
114 name_ = d["name"].GetString();
115 }
116 if (d.HasMember("state") && d["state"].IsString()) {
117 state_ = d["state"].GetString();
118 }
119 if (d.HasMember("message") && d["message"].IsString()) {
120 message_ = d["message"].GetString();
121 }
122}
123
124void
125PluginOpResponse::validate(bool subcall) const
126{
127 std::vector<std::string> missing;
128 if (!kind_)
129 missing.push_back("kind");
130 if (!apiVersion_)
131 missing.push_back("apiVersion");
132 if (!name_)
133 missing.push_back("name");
134 if (!state_)
135 missing.push_back("state");
136
137 if (!missing.empty()) {
138 if (subcall) {
139 throw missing;
140 } else {
141 std::ostringstream s;
142 s << "PluginOpResponse is missing field" << ((missing.size() > 0) ? "s" : "") << ": ";
143 for (std::vector<std::string>::size_type i = 0; i < missing.size(); ++i) {
144 s << missing[i];
145 if (i < (missing.size() - 1)) {
146 s << ", ";
147 }
148 }
149 throw std::runtime_error(s.str());
150 }
151 }
152}
virtual void validate(bool subcall=false) const
Validate if all required fields have been set.
virtual void from_json(const std::string &json)
Retrieve data from JSON string.
virtual std::string to_json(bool pretty=false) const
Render object to JSON.
PluginOpResponse()
Constructor.
virtual void to_json_value(rapidjson::Document &d, rapidjson::Value &v) const
Render object to JSON.
virtual ~PluginOpResponse()
Destructor.
virtual void from_json_value(const rapidjson::Value &v)
Retrieve data from JSON string.