comparison OrthancFramework/Sources/RestApi/RestApi.cpp @ 5394:002ba12a8bee

fix openapi & cheatsheet visitors to include trailing 'path' in /instances/{id}/content/{path} url
author Alain Mazy <am@osimis.io>
date Tue, 03 Oct 2023 11:55:43 +0200
parents c5c00bee291a
children 48b8dae6dc77
comparison
equal deleted inserted replaced
5393:c5c00bee291a 5394:002ba12a8bee
136 size_t successPathsCount_; 136 size_t successPathsCount_;
137 size_t totalPathsCount_; 137 size_t totalPathsCount_;
138 138
139 protected: 139 protected:
140 virtual bool HandleCall(RestApiCall& call, 140 virtual bool HandleCall(RestApiCall& call,
141 const std::string& path,
141 const std::set<std::string>& uriArgumentsNames) = 0; 142 const std::set<std::string>& uriArgumentsNames) = 0;
142 143
143 public: 144 public:
144 explicit DocumentationVisitor(RestApi& restApi) : 145 explicit DocumentationVisitor(RestApi& restApi) :
145 restApi_(restApi), 146 restApi_(restApi),
192 bool ok = false; 193 bool ok = false;
193 194
194 try 195 try
195 { 196 {
196 ok = (resource.Handle(call) && 197 ok = (resource.Handle(call) &&
197 HandleCall(call, uriArgumentsNames)); 198 HandleCall(call, path, uriArgumentsNames));
198 } 199 }
199 catch (OrthancException& e) 200 catch (OrthancException& e)
200 { 201 {
201 LOG(ERROR) << "Exception while documenting GET " << path << ": " << e.What(); 202 LOG(ERROR) << "Exception while documenting GET " << path << ": " << e.What();
202 } 203 }
230 bool ok = false; 231 bool ok = false;
231 232
232 try 233 try
233 { 234 {
234 ok = (resource.Handle(call) && 235 ok = (resource.Handle(call) &&
235 HandleCall(call, uriArgumentsNames)); 236 HandleCall(call, path, uriArgumentsNames));
236 } 237 }
237 catch (OrthancException& e) 238 catch (OrthancException& e)
238 { 239 {
239 LOG(ERROR) << "Exception while documenting POST " << path << ": " << e.What(); 240 LOG(ERROR) << "Exception while documenting POST " << path << ": " << e.What();
240 } 241 }
267 bool ok = false; 268 bool ok = false;
268 269
269 try 270 try
270 { 271 {
271 ok = (resource.Handle(call) && 272 ok = (resource.Handle(call) &&
272 HandleCall(call, uriArgumentsNames)); 273 HandleCall(call, path, uriArgumentsNames));
273 } 274 }
274 catch (OrthancException& e) 275 catch (OrthancException& e)
275 { 276 {
276 LOG(ERROR) << "Exception while documenting DELETE " << path << ": " << e.What(); 277 LOG(ERROR) << "Exception while documenting DELETE " << path << ": " << e.What();
277 } 278 }
305 bool ok = false; 306 bool ok = false;
306 307
307 try 308 try
308 { 309 {
309 ok = (resource.Handle(call) && 310 ok = (resource.Handle(call) &&
310 HandleCall(call, uriArgumentsNames)); 311 HandleCall(call, path, uriArgumentsNames));
311 } 312 }
312 catch (OrthancException& e) 313 catch (OrthancException& e)
313 { 314 {
314 LOG(ERROR) << "Exception while documenting PUT " << path << ": " << e.What(); 315 LOG(ERROR) << "Exception while documenting PUT " << path << ": " << e.What();
315 } 316 }
364 private: 365 private:
365 Json::Value paths_; 366 Json::Value paths_;
366 367
367 protected: 368 protected:
368 virtual bool HandleCall(RestApiCall& call, 369 virtual bool HandleCall(RestApiCall& call,
370 const std::string& path,
369 const std::set<std::string>& uriArgumentsNames) ORTHANC_OVERRIDE 371 const std::set<std::string>& uriArgumentsNames) ORTHANC_OVERRIDE
370 { 372 {
371 const std::string path = Toolbox::FlattenUri(call.GetFullUri());
372
373 Json::Value v; 373 Json::Value v;
374 if (call.GetDocumentation().FormatOpenApi(v, uriArgumentsNames, path)) 374 if (call.GetDocumentation().FormatOpenApi(v, uriArgumentsNames, path))
375 { 375 {
376 std::string method; 376 std::string method;
377 377
682 682
683 Paths paths_; 683 Paths paths_;
684 684
685 protected: 685 protected:
686 virtual bool HandleCall(RestApiCall& call, 686 virtual bool HandleCall(RestApiCall& call,
687 const std::string& _path,
687 const std::set<std::string>& uriArgumentsNames) ORTHANC_OVERRIDE 688 const std::set<std::string>& uriArgumentsNames) ORTHANC_OVERRIDE
688 { 689 {
689 Path& path = paths_[ Toolbox::FlattenUri(call.GetFullUri()) ]; 690 Path& path = paths_[ _path ];
690 691
691 path.AddMethod(call.GetMethod(), call.GetDocumentation().GetTag(), call.GetDocumentation().IsDeprecated()); 692 path.AddMethod(call.GetMethod(), call.GetDocumentation().GetTag(), call.GetDocumentation().IsDeprecated());
692 693
693 if (call.GetDocumentation().HasSummary()) 694 if (call.GetDocumentation().HasSummary())
694 { 695 {