comparison OrthancFramework/Sources/RestApi/RestApiCallDocumentation.cpp @ 4622:9086aeb9d9d2 db-changes

RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 16 Apr 2021 10:48:57 +0200
parents d9473bd5ed43
children 7053502fbf97
comparison
equal deleted inserted replaced
4621:82dbe45c947a 4622:9086aeb9d9d2
174 return *this; 174 return *this;
175 } 175 }
176 } 176 }
177 177
178 178
179 RestApiCallDocumentation& RestApiCallDocumentation::SetAnswerHeader(const std::string& name,
180 const std::string& description)
181 {
182 if (answerHeaders_.find(name) != answerHeaders_.end())
183 {
184 throw OrthancException(ErrorCode_ParameterOutOfRange, "Answer HTTP header \"" + name + "\" is already documented");
185 }
186 else
187 {
188 answerHeaders_[name] = Parameter(Type_String, description, false);
189 return *this;
190 }
191 }
192
193
179 void RestApiCallDocumentation::SetHttpGetSample(const std::string& url, 194 void RestApiCallDocumentation::SetHttpGetSample(const std::string& url,
180 bool isJson) 195 bool isJson)
181 { 196 {
182 #if ORTHANC_ENABLE_CURL == 1 197 #if ORTHANC_ENABLE_CURL == 1
183 HttpClient client; 198 HttpClient client;
428 if (hasSampleText_) 443 if (hasSampleText_)
429 { 444 {
430 target["responses"]["200"]["content"][EnumerationToString(MimeType_PlainText)]["example"] = sampleText_; 445 target["responses"]["200"]["content"][EnumerationToString(MimeType_PlainText)]["example"] = sampleText_;
431 } 446 }
432 447
448 if (!answerHeaders_.empty())
449 {
450 Json::Value answerHeaders = Json::objectValue;
451
452 for (Parameters::const_iterator it = answerHeaders_.begin(); it != answerHeaders_.end(); ++it)
453 {
454 Json::Value h = Json::objectValue;
455 h["description"] = it->second.GetDescription();
456 answerHeaders[it->first] = h;
457 }
458
459 target["responses"]["200"]["headers"] = answerHeaders;
460 }
461
433 Json::Value parameters = Json::arrayValue; 462 Json::Value parameters = Json::arrayValue;
434 463
435 for (Parameters::const_iterator it = getArguments_.begin(); 464 for (Parameters::const_iterator it = getArguments_.begin();
436 it != getArguments_.end(); ++it) 465 it != getArguments_.end(); ++it)
437 { 466 {