comparison OrthancFramework/Sources/RestApi/RestApiCallDocumentation.cpp @ 4415:b50410d0e98c

cont openapi
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 28 Dec 2020 15:32:01 +0100
parents d928dfcacb4b
children a4518adede59
comparison
equal deleted inserted replaced
4414:d928dfcacb4b 4415:b50410d0e98c
177 177
178 178
179 void RestApiCallDocumentation::SetHttpGetSample(const std::string& url, 179 void RestApiCallDocumentation::SetHttpGetSample(const std::string& url,
180 bool isJson) 180 bool isJson)
181 { 181 {
182 //return; // TODO -REMOVE
183
182 #if ORTHANC_ENABLE_CURL == 1 184 #if ORTHANC_ENABLE_CURL == 1
183 HttpClient client; 185 HttpClient client;
184 client.SetUrl(url); 186 client.SetUrl(url);
185 client.SetHttpsVerifyPeers(false); 187 client.SetHttpsVerifyPeers(false);
186 188
206 } 208 }
207 #else 209 #else
208 LOG(WARNING) << "HTTP client is not available to generated the documentation"; 210 LOG(WARNING) << "HTTP client is not available to generated the documentation";
209 #endif 211 #endif
210 } 212 }
213
214
215 static void Truncate(Json::Value& value,
216 size_t size)
217 {
218 if (value.type() == Json::arrayValue)
219 {
220 if (value.size() > size)
221 {
222 value.resize(size);
223 value.append("...");
224 }
225
226 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++)
227 {
228 Truncate(value[i], size);
229 }
230 }
231 else if (value.type() == Json::objectValue)
232 {
233 std::vector<std::string> members = value.getMemberNames();
234 if (members.size() > size)
235 {
236 members.resize(size);
237
238 Json::Value v = Json::objectValue;
239 for (size_t i = 0; i < members.size(); i++)
240 {
241 v[members[i]] = value[members[i]];
242 }
243
244 // We use the "{" symbol, as it the last in the 7bit ASCII
245 // table, which places "..." at the end of the object in OpenAPI
246 v["{...}"] = "...";
247
248 value = v;
249 }
250
251 for (size_t i = 0; i < members.size(); i++)
252 {
253 Truncate(value[members[i]], size);
254 }
255 }
256 }
257
258
259 void RestApiCallDocumentation::SetTruncatedJsonHttpGetSample(const std::string& url,
260 size_t size)
261 {
262 SetHttpGetSample(url, true);
263 Truncate(sampleJson_, size);
264 }
265
211 266
212 267
213 static void TypeToSchema(Json::Value& target, 268 static void TypeToSchema(Json::Value& target,
214 RestApiCallDocumentation::Type type) 269 RestApiCallDocumentation::Type type)
215 { 270 {