diff 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
line wrap: on
line diff
--- a/OrthancFramework/Sources/RestApi/RestApiCallDocumentation.cpp	Mon Dec 28 14:46:51 2020 +0100
+++ b/OrthancFramework/Sources/RestApi/RestApiCallDocumentation.cpp	Mon Dec 28 15:32:01 2020 +0100
@@ -179,6 +179,8 @@
   void RestApiCallDocumentation::SetHttpGetSample(const std::string& url,
                                                   bool isJson)
   {
+    //return;  // TODO -REMOVE
+    
 #if ORTHANC_ENABLE_CURL == 1
     HttpClient client;
     client.SetUrl(url);
@@ -210,6 +212,59 @@
   }
 
 
+  static void Truncate(Json::Value& value,
+                       size_t size)
+  {
+    if (value.type() == Json::arrayValue)
+    {
+      if (value.size() > size)
+      {
+        value.resize(size);
+        value.append("...");
+      }
+
+      for (Json::Value::ArrayIndex i = 0; i < value.size(); i++)
+      {
+        Truncate(value[i], size);
+      }
+    }
+    else if (value.type() == Json::objectValue)
+    {
+      std::vector<std::string> members = value.getMemberNames();
+      if (members.size() > size)
+      {
+        members.resize(size);
+
+        Json::Value v = Json::objectValue;
+        for (size_t i = 0; i < members.size(); i++)
+        {
+          v[members[i]] = value[members[i]];
+        }
+
+        // We use the "{" symbol, as it the last in the 7bit ASCII
+        // table, which places "..." at the end of the object in OpenAPI
+        v["{...}"] = "...";
+        
+        value = v;
+      }
+
+      for (size_t i = 0; i < members.size(); i++)
+      {
+        Truncate(value[members[i]], size);
+      }
+    }
+  }
+
+  
+  void RestApiCallDocumentation::SetTruncatedJsonHttpGetSample(const std::string& url,
+                                                               size_t size)
+  {
+    SetHttpGetSample(url, true);
+    Truncate(sampleJson_, size);
+  }
+
+
+
   static void TypeToSchema(Json::Value& target,
                            RestApiCallDocumentation::Type type)
   {