diff OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp @ 4415:b50410d0e98c

cont openapi
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 28 Dec 2020 15:32:01 +0100
parents d928dfcacb4b
children 0b27841950d5
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Mon Dec 28 14:46:51 2020 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestResources.cpp	Mon Dec 28 15:32:01 2020 +0100
@@ -67,6 +67,32 @@
 
 namespace Orthanc
 {
+  static std::string GetDocumentationSampleResource(ResourceType type)
+  {
+    switch (type)
+    {
+      case Orthanc::ResourceType_Instance:
+        return "https://demo.orthanc-server.com/instances/d94d9a03-3003b047-a4affc69-322313b2-680530a2";
+        break;
+        
+      case Orthanc::ResourceType_Series:
+        return "https://demo.orthanc-server.com/series/37836232-d13a2350-fa1dedc5-962b31aa-010f8e52";
+        break;
+        
+      case Orthanc::ResourceType_Study:
+        return "https://demo.orthanc-server.com/studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988";
+        break;
+        
+      case Orthanc::ResourceType_Patient:
+        return "https://demo.orthanc-server.com/patients/46e6332c-677825b6-202fcf7c-f787bc5f-7b07c382";
+        break;
+        
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
+  
+
   static void AnswerDicomAsJson(RestApiCall& call,
                                 const Json::Value& dicom,
                                 DicomToJsonFormat mode)
@@ -214,32 +240,6 @@
 
 
 
-  static std::string GetDocumentationSampleResource(ResourceType type)
-  {
-    switch (type)
-    {
-      case Orthanc::ResourceType_Instance:
-        return "https://demo.orthanc-server.com/instances/d94d9a03-3003b047-a4affc69-322313b2-680530a2";
-        break;
-        
-      case Orthanc::ResourceType_Series:
-        return "https://demo.orthanc-server.com/series/37836232-d13a2350-fa1dedc5-962b31aa-010f8e52";
-        break;
-        
-      case Orthanc::ResourceType_Study:
-        return "https://demo.orthanc-server.com/studies/27f7126f-4f66fb14-03f4081b-f9341db2-53925988";
-        break;
-        
-      case Orthanc::ResourceType_Patient:
-        return "https://demo.orthanc-server.com/patients/46e6332c-677825b6-202fcf7c-f787bc5f-7b07c382";
-        break;
-        
-      default:
-        throw OrthancException(ErrorCode_ParameterOutOfRange);
-    }
-  }
-  
-
   template <enum ResourceType resourceType>
   static void GetSingleResource(RestApiGetCall& call)
   {
@@ -436,7 +436,7 @@
           .SetDescription("Get the DICOM tags in human-readable format")
           .SetUriArgument("id", "Orthanc identifier of the DICOM instance of interest")
           .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value")
-          .SetHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/simplified-tags", true);
+          .SetTruncatedJsonHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/simplified-tags", 10);
         return;
       }
       else
@@ -487,7 +487,7 @@
         .SetHttpGetArgument("short", RestApiCallDocumentation::Type_String,
                             "If present, report the DICOM tags indexed in hexadecimal format", false)
         .AddAnswerType(MimeType_Json, "JSON object containing the DICOM tags and their associated value")
-        .SetHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/tags", true);      
+        .SetTruncatedJsonHttpGetSample("https://demo.orthanc-server.com/instances/7c92ce8e-bbf67ed2-ffa3b8c1-a3b35d94-7ff3ae26/tags", 10);
       return;
     }
 
@@ -2377,6 +2377,21 @@
             enum ResourceType end>
   static void GetChildResources(RestApiGetCall& call)
   {
+    if (call.IsDocumentation())
+    {
+      const std::string children = GetResourceTypeText(end, true /* plural */, false /* lower case */);
+      const std::string resource = GetResourceTypeText(start, false /* plural */, false /* lower case */);
+      call.GetDocumentation()
+        .SetTag(GetResourceTypeText(start, true /* plural */, true /* upper case */))
+        .SetSummary("Get child " + children)
+        .SetDescription("Get detailed information about the child " + children + " of the DICOM " +
+                        resource + " of interest whose Orthanc identifier is provided in the URL")
+        .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest")
+        .AddAnswerType(MimeType_Json, "JSON array containing information about the child DICOM " + children)
+        .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + children, 5);
+      return;
+    }
+
     ServerIndex& index = OrthancRestApi::GetIndex(call);
 
     std::list<std::string> a, b, c;
@@ -2463,6 +2478,21 @@
   {
     assert(start > end);
 
+    if (call.IsDocumentation())
+    {
+      const std::string parent = GetResourceTypeText(end, false /* plural */, false /* lower case */);
+      const std::string resource = GetResourceTypeText(start, false /* plural */, false /* lower case */);
+      call.GetDocumentation()
+        .SetTag(GetResourceTypeText(start, true /* plural */, true /* upper case */))
+        .SetSummary("Get parent " + parent)
+        .SetDescription("Get detailed information about the parent " + parent + " of the DICOM " +
+                        resource + " of interest whose Orthanc identifier is provided in the URL")
+        .SetUriArgument("id", "Orthanc identifier of the " + resource + " of interest")
+        .AddAnswerType(MimeType_Json, "Information about the parent DICOM " + parent)
+        .SetTruncatedJsonHttpGetSample(GetDocumentationSampleResource(start) + "/" + parent, 10);
+      return;
+    }
+
     ServerIndex& index = OrthancRestApi::GetIndex(call);
     
     std::string current = call.GetUriComponent("id", "");