comparison OrthancFramework/Sources/RestApi/RestApiCallDocumentation.cpp @ 4413:22a1352a0823

cont openapi
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 28 Dec 2020 13:08:00 +0100
parents 5784a9eaf502
children d928dfcacb4b
comparison
equal deleted inserted replaced
4412:68b96234fbd6 4413:22a1352a0823
208 LOG(WARNING) << "HTTP client is not available to generated the documentation"; 208 LOG(WARNING) << "HTTP client is not available to generated the documentation";
209 #endif 209 #endif
210 } 210 }
211 211
212 212
213 static const char* TypeToString(RestApiCallDocumentation::Type type) 213 static void TypeToSchema(Json::Value& target,
214 RestApiCallDocumentation::Type type)
214 { 215 {
215 switch (type) 216 switch (type)
216 { 217 {
217 case RestApiCallDocumentation::Type_Unknown: 218 case RestApiCallDocumentation::Type_Unknown:
218 throw OrthancException(ErrorCode_ParameterOutOfRange); 219 throw OrthancException(ErrorCode_ParameterOutOfRange);
219 220
220 case RestApiCallDocumentation::Type_String: 221 case RestApiCallDocumentation::Type_String:
221 case RestApiCallDocumentation::Type_Text: 222 case RestApiCallDocumentation::Type_Text:
222 return "string"; 223 target["type"] = "string";
224 return;
223 225
224 case RestApiCallDocumentation::Type_Number: 226 case RestApiCallDocumentation::Type_Number:
225 return "number"; 227 target["type"] = "number";
228 return;
226 229
227 case RestApiCallDocumentation::Type_Boolean: 230 case RestApiCallDocumentation::Type_Boolean:
228 return "boolean"; 231 target["type"] = "boolean";
232 return;
229 233
230 case RestApiCallDocumentation::Type_JsonObject: 234 case RestApiCallDocumentation::Type_JsonObject:
231 return "object"; 235 target["type"] = "object";
236 return;
232 237
233 case RestApiCallDocumentation::Type_JsonListOfStrings: 238 case RestApiCallDocumentation::Type_JsonListOfStrings:
239 target["type"] = "array";
240 target["items"]["type"] = "string";
241 return;
242
234 case RestApiCallDocumentation::Type_JsonListOfObjects: 243 case RestApiCallDocumentation::Type_JsonListOfObjects:
235 return "array"; 244 target["type"] = "array";
245 target["items"]["type"] = "object";
246 return;
236 247
237 default: 248 default:
238 throw OrthancException(ErrorCode_ParameterOutOfRange); 249 throw OrthancException(ErrorCode_ParameterOutOfRange);
239 } 250 }
240 } 251 }
288 { 299 {
289 for (Parameters::const_iterator field = requestFields_.begin(); 300 for (Parameters::const_iterator field = requestFields_.begin();
290 field != requestFields_.end(); ++field) 301 field != requestFields_.end(); ++field)
291 { 302 {
292 Json::Value p = Json::objectValue; 303 Json::Value p = Json::objectValue;
293 p["type"] = TypeToString(field->second.GetType()); 304 TypeToSchema(p, field->second.GetType());
294 p["description"] = field->second.GetDescription(); 305 p["description"] = field->second.GetDescription();
295 schema["properties"][field->first] = p; 306 schema["properties"][field->first] = p;
296 } 307 }
297 } 308 }
298 } 309 }
310 { 321 {
311 for (Parameters::const_iterator field = answerFields_.begin(); 322 for (Parameters::const_iterator field = answerFields_.begin();
312 field != answerFields_.end(); ++field) 323 field != answerFields_.end(); ++field)
313 { 324 {
314 Json::Value p = Json::objectValue; 325 Json::Value p = Json::objectValue;
315 p["type"] = TypeToString(field->second.GetType()); 326 TypeToSchema(p, field->second.GetType());
316 p["description"] = field->second.GetDescription(); 327 p["description"] = field->second.GetDescription();
317 schema["properties"][field->first] = p; 328 schema["properties"][field->first] = p;
318 } 329 }
319 } 330 }
320 } 331 }
356 { 367 {
357 Json::Value p = Json::objectValue; 368 Json::Value p = Json::objectValue;
358 p["name"] = it->first; 369 p["name"] = it->first;
359 p["in"] = "query"; 370 p["in"] = "query";
360 p["required"] = it->second.IsRequired(); 371 p["required"] = it->second.IsRequired();
361 p["schema"]["type"] = TypeToString(it->second.GetType()); 372 TypeToSchema(p["schema"], it->second.GetType());
362 p["description"] = it->second.GetDescription(); 373 p["description"] = it->second.GetDescription();
363 parameters.append(p); 374 parameters.append(p);
364 } 375 }
365 376
366 for (Parameters::const_iterator it = httpHeaders_.begin(); 377 for (Parameters::const_iterator it = httpHeaders_.begin();
368 { 379 {
369 Json::Value p = Json::objectValue; 380 Json::Value p = Json::objectValue;
370 p["name"] = it->first; 381 p["name"] = it->first;
371 p["in"] = "header"; 382 p["in"] = "header";
372 p["required"] = it->second.IsRequired(); 383 p["required"] = it->second.IsRequired();
373 p["schema"]["type"] = TypeToString(it->second.GetType()); 384 TypeToSchema(p["schema"], it->second.GetType());
374 p["description"] = it->second.GetDescription(); 385 p["description"] = it->second.GetDescription();
375 parameters.append(p); 386 parameters.append(p);
376 } 387 }
377 388
378 for (Parameters::const_iterator it = uriArguments_.begin(); 389 for (Parameters::const_iterator it = uriArguments_.begin();
385 396
386 Json::Value p = Json::objectValue; 397 Json::Value p = Json::objectValue;
387 p["name"] = it->first; 398 p["name"] = it->first;
388 p["in"] = "path"; 399 p["in"] = "path";
389 p["required"] = it->second.IsRequired(); 400 p["required"] = it->second.IsRequired();
390 p["schema"]["type"] = TypeToString(it->second.GetType()); 401 TypeToSchema(p["schema"], it->second.GetType());
391 p["description"] = it->second.GetDescription(); 402 p["description"] = it->second.GetDescription();
392 parameters.append(p); 403 parameters.append(p);
393 } 404 }
394 405
395 for (std::set<std::string>::const_iterator it = expectedUriArguments.begin(); 406 for (std::set<std::string>::const_iterator it = expectedUriArguments.begin();