You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/08/30 08:14:23 UTC

[GitHub] [nifi-minifi-cpp] adamdebreceni opened a new pull request, #1413: MINIFICPP-1917 - Generate flow config JSON schema

adamdebreceni opened a new pull request, #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413

   Documentation incoming, usage: `${MINIFIEXE} schema ./config-schema.json`
   ---
   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the LICENSE file?
   - [ ] If applicable, have you updated the NOTICE file?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] lordgamez commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
lordgamez commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1031609914


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,436 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "\\n");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) { // NOLINT(bugprone-branch-clone)
+      // special value types
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "(?i)^"
+      << "(" << makeCommon(secs) << ")"
+      << " (" << makeCommon(mins) << ")"
+      << " (" << makeCommon(hours) << ")"
+      << " (" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")"
+      << " (" << makeCommon(months) << ")"
+      << " (" << makeCommon(weekdays) << "|" << weekdays << "?L|" << weekdays << "#" << "[1-5]" << ")"
+      << "( (" << makeCommon(years) << "))?"
+      << "$";
+
+  }
+
+  return prettifyJson(R"(
+{
+  "$schema": "http://json-schema.org/draft-07/schema",

Review Comment:
   With the addition of https://github.com/apache/nifi-minifi-cpp/pull/1451 should we add `Input Ports` and `Output Ports` as well to the schema?



##########
minifi_main/JsonSchema.h:
##########
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+
+namespace org::apache::nifi::minifi::docs {
+
+std::string generateJsonSchema();

Review Comment:
   Would it be possible to add a test to check the json schema, with an attached json file that contains all the possible elements, to check if our generated schema is valid? It could be appended later if new elements are introduced and to update the test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1042158041


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,436 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "\\n");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) { // NOLINT(bugprone-branch-clone)
+      // special value types
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "(?i)^"
+      << "(" << makeCommon(secs) << ")"
+      << " (" << makeCommon(mins) << ")"
+      << " (" << makeCommon(hours) << ")"
+      << " (" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")"
+      << " (" << makeCommon(months) << ")"
+      << " (" << makeCommon(weekdays) << "|" << weekdays << "?L|" << weekdays << "#" << "[1-5]" << ")"
+      << "( (" << makeCommon(years) << "))?"
+      << "$";
+
+  }
+
+  return prettifyJson(R"(
+{
+  "$schema": "http://json-schema.org/draft-07/schema",

Review Comment:
   yes, good idea, added in [f939b06](https://github.com/apache/nifi-minifi-cpp/pull/1413/commits/f939b06657939ba54c325fbf462c4a04bc8286da)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] lordgamez commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
lordgamez commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1043359935


##########
minifi_main/JsonSchema.h:
##########
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+
+namespace org::apache::nifi::minifi::docs {
+
+std::string generateJsonSchema();

Review Comment:
   The first result I found was https://github.com/pboettch/json-schema-validator which depends on nlohmann json library, maybe this could be used to test the generated schema.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1048177387


##########
minifi_main/JsonSchema.h:
##########
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+
+namespace org::apache::nifi::minifi::docs {
+
+std::string generateJsonSchema();

Review Comment:
   integrated the proposed validator, and added tests to verify that it reports errors on invalid configs



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] fgerlits commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
fgerlits commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1004097276


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "^"
+      << "(" << makeCommon(secs) << ")" << " "
+      << "(" << makeCommon(mins) << ")" << " "
+      << "(" << makeCommon(hours) << ")" << " "
+      << "(" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")" << " "
+      << "(" << makeCommon(months) << ")" << " "
+      << "(" << makeCommon(weekdays) << "|L|" << weekdays << "#" << "[1-5]" << ")"
+      << "( " << makeCommon(years) << ")?"
+      << "$";
+
+  }
+
+  return prettifyJson(R"(
+{
+  "$schema": "http://json-schema.org/draft-07/schema",
+  "$defs": {)" + std::move(all_rels).str() + R"(
+    "datasize": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(B|K|M|G|T|P|KB|MB|GB|TB|PT)\\s*$"

Review Comment:
   yeah, there is a bit of a contradiction between petabytes and MINIfi...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1003058840


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "^"
+      << "(" << makeCommon(secs) << ")" << " "
+      << "(" << makeCommon(mins) << ")" << " "
+      << "(" << makeCommon(hours) << ")" << " "
+      << "(" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")" << " "
+      << "(" << makeCommon(months) << ")" << " "
+      << "(" << makeCommon(weekdays) << "|L|" << weekdays << "#" << "[1-5]" << ")"
+      << "( " << makeCommon(years) << ")?"
+      << "$";
+
+  }
+
+  return prettifyJson(R"(
+{
+  "$schema": "http://json-schema.org/draft-07/schema",
+  "$defs": {)" + std::move(all_rels).str() + R"(
+    "datasize": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(B|K|M|G|T|P|KB|MB|GB|TB|PT)\\s*$"
+    },
+    "uuid": {
+      "type": "string",
+      "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
+      "default": "00000000-0000-0000-0000-000000000000"
+    },
+    "cron_pattern": {
+      "type": "string",
+      "pattern": ")" + std::move(cron_pattern).str() + R"("
+    },
+    "remote_port": {
+      "type": "object",
+      "properties": {
+        "required": ["name", "id", "Properties"],
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "max concurrent tasks": {"type": "integer"},
+        )" + std::move(remote_port_props).str() +  R"(
+      }
+    },
+    "time": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(ns|nano|nanos|nanoseconds|nanosecond|us|micro|micros|microseconds|microsecond|msec|ms|millisecond|milliseconds|msecs|millis|milli|sec|s|second|seconds|secs|min|m|mins|minute|minutes|h|hr|hour|hrs|hours|d|day|days)\\s*$"
+    },
+    "controller_service": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "class"],
+      "properties": {
+        "name": {"type": "string"},
+        "class": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"}
+      }
+    }, )" + controller_services + R"(]},
+    "processor": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "class", "scheduling strategy"],
+      "additionalProperties": false,
+      "properties": {
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "class": {"type": "string"},
+        "max concurrent tasks": {"type": "integer", "default": 1},
+        "penalization period": {"$ref": "#/$defs/time"},
+        "yield period": {"$ref": "#/$defs/time"},
+        "run duration nanos": {"$ref": "#/$defs/time"},
+        "Properties": {},
+        "scheduling strategy": {"enum": ["EVENT_DRIVEN", "TIMER_DRIVEN", "CRON_DRIVEN"]},
+        "scheduling period": {},
+        "auto-terminated relationships list": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "uniqueItems": true
+        }
+      }}, {
+        "if": {"properties": {"scheduling strategy": {"const": "EVENT_DRIVEN"}}},
+        "then": {"properties": {"scheduling period": false}}
+      }, {
+        "if": {"properties": {"scheduling strategy": {"const": "TIMER_DRIVEN"}}},
+        "then": {"required": ["scheduling period"], "properties": {"scheduling period": {"$ref": "#/$defs/time"}}}
+      }, {
+        "if": {"properties": {"scheduling strategy": {"const": "CRON_DRIVEN"}}},
+        "then": {"required": ["scheduling period"], "properties": {"scheduling period": {"$ref": "#/$defs/cron_pattern"}}}
+      }, )" + processors + R"(]
+    },
+    "remote_process_group": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "Input Ports"],
+      "properties": {
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "url": {"type": "string"},
+        "yield period": {"$ref": "#/$defs/time"},
+        "timeout": {"$ref": "#/$defs/time"},
+        "local network interface": {"type": "string"},
+        "transport protocol": {"enum": ["HTTP", "RAW"]},
+        "Input Ports": {
+          "type": "array",
+          "items": {"$ref": "#/$defs/remote_port"}
+        },
+        "Output Ports": {
+          "type": "array",
+          "items": {"$ref": "#/$defs/remote_port"}
+        }
+      }
+    }, {
+      "if": {"properties": {"transport protocol": {"const": "HTTP"}}},
+      "then": {"properties": {
+        "proxy host": {"type": "string"},
+        "proxy user": {"type": "string"},
+        "proxy password": {"type": "string"},
+        "proxy port": {"type": "integer"}
+      }}
+    }]},
+    "connection": {
+      "type": "object",
+      "additionalProperties": false,
+      "required": ["name", "id", "source name", "source id", "source relationship names", "destination name", "destination id"],

Review Comment:
   indeed, they are only used as fallbacks in case of missing ids



##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "^"
+      << "(" << makeCommon(secs) << ")" << " "
+      << "(" << makeCommon(mins) << ")" << " "
+      << "(" << makeCommon(hours) << ")" << " "
+      << "(" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")" << " "
+      << "(" << makeCommon(months) << ")" << " "
+      << "(" << makeCommon(weekdays) << "|L|" << weekdays << "#" << "[1-5]" << ")"
+      << "( " << makeCommon(years) << ")?"
+      << "$";
+
+  }
+
+  return prettifyJson(R"(
+{
+  "$schema": "http://json-schema.org/draft-07/schema",
+  "$defs": {)" + std::move(all_rels).str() + R"(
+    "datasize": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(B|K|M|G|T|P|KB|MB|GB|TB|PT)\\s*$"
+    },
+    "uuid": {
+      "type": "string",
+      "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
+      "default": "00000000-0000-0000-0000-000000000000"
+    },
+    "cron_pattern": {
+      "type": "string",
+      "pattern": ")" + std::move(cron_pattern).str() + R"("
+    },
+    "remote_port": {
+      "type": "object",
+      "properties": {
+        "required": ["name", "id", "Properties"],
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "max concurrent tasks": {"type": "integer"},
+        )" + std::move(remote_port_props).str() +  R"(
+      }
+    },
+    "time": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(ns|nano|nanos|nanoseconds|nanosecond|us|micro|micros|microseconds|microsecond|msec|ms|millisecond|milliseconds|msecs|millis|milli|sec|s|second|seconds|secs|min|m|mins|minute|minutes|h|hr|hour|hrs|hours|d|day|days)\\s*$"
+    },
+    "controller_service": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "class"],
+      "properties": {
+        "name": {"type": "string"},
+        "class": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"}
+      }
+    }, )" + controller_services + R"(]},
+    "processor": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "class", "scheduling strategy"],
+      "additionalProperties": false,
+      "properties": {
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "class": {"type": "string"},
+        "max concurrent tasks": {"type": "integer", "default": 1},
+        "penalization period": {"$ref": "#/$defs/time"},
+        "yield period": {"$ref": "#/$defs/time"},
+        "run duration nanos": {"$ref": "#/$defs/time"},
+        "Properties": {},
+        "scheduling strategy": {"enum": ["EVENT_DRIVEN", "TIMER_DRIVEN", "CRON_DRIVEN"]},
+        "scheduling period": {},
+        "auto-terminated relationships list": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "uniqueItems": true
+        }
+      }}, {
+        "if": {"properties": {"scheduling strategy": {"const": "EVENT_DRIVEN"}}},
+        "then": {"properties": {"scheduling period": false}}
+      }, {
+        "if": {"properties": {"scheduling strategy": {"const": "TIMER_DRIVEN"}}},
+        "then": {"required": ["scheduling period"], "properties": {"scheduling period": {"$ref": "#/$defs/time"}}}
+      }, {
+        "if": {"properties": {"scheduling strategy": {"const": "CRON_DRIVEN"}}},
+        "then": {"required": ["scheduling period"], "properties": {"scheduling period": {"$ref": "#/$defs/cron_pattern"}}}
+      }, )" + processors + R"(]
+    },
+    "remote_process_group": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "Input Ports"],
+      "properties": {
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "url": {"type": "string"},
+        "yield period": {"$ref": "#/$defs/time"},
+        "timeout": {"$ref": "#/$defs/time"},
+        "local network interface": {"type": "string"},
+        "transport protocol": {"enum": ["HTTP", "RAW"]},
+        "Input Ports": {
+          "type": "array",
+          "items": {"$ref": "#/$defs/remote_port"}
+        },
+        "Output Ports": {
+          "type": "array",
+          "items": {"$ref": "#/$defs/remote_port"}
+        }
+      }
+    }, {
+      "if": {"properties": {"transport protocol": {"const": "HTTP"}}},
+      "then": {"properties": {
+        "proxy host": {"type": "string"},
+        "proxy user": {"type": "string"},
+        "proxy password": {"type": "string"},
+        "proxy port": {"type": "integer"}
+      }}
+    }]},
+    "connection": {
+      "type": "object",
+      "additionalProperties": false,
+      "required": ["name", "id", "source name", "source id", "source relationship names", "destination name", "destination id"],

Review Comment:
   removed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] lordgamez closed pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
lordgamez closed pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1005733706


##########
minifi_main/MiNiFiMain.cpp:
##########
@@ -269,6 +279,21 @@ int main(int argc, char **argv) {
       exit(0);
     }
 
+    if (argc >= 2 && std::string("schema") == argv[1]) {
+      if (argc != 3) {
+        std::cerr << "Malformed schema command, expected '<minifiexe> schema <output-file>'" << std::endl;
+        std::exit(1);
+      }
+
+      std::cerr << "Writing json schema to " << argv[2] << std::endl;

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] fgerlits commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
fgerlits commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1001899203


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");

Review Comment:
   which strings can contain newlines?  would it be better to replace the newline with a space?



##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "^"
+      << "(" << makeCommon(secs) << ")" << " "
+      << "(" << makeCommon(mins) << ")" << " "
+      << "(" << makeCommon(hours) << ")" << " "
+      << "(" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")" << " "
+      << "(" << makeCommon(months) << ")" << " "
+      << "(" << makeCommon(weekdays) << "|L|" << weekdays << "#" << "[1-5]" << ")"
+      << "( " << makeCommon(years) << ")?"
+      << "$";
+
+  }
+
+  return prettifyJson(R"(
+{
+  "$schema": "http://json-schema.org/draft-07/schema",
+  "$defs": {)" + std::move(all_rels).str() + R"(
+    "datasize": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(B|K|M|G|T|P|KB|MB|GB|TB|PT)\\s*$"

Review Comment:
   typo: PT -> PB



##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "^"
+      << "(" << makeCommon(secs) << ")" << " "
+      << "(" << makeCommon(mins) << ")" << " "
+      << "(" << makeCommon(hours) << ")" << " "
+      << "(" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")" << " "
+      << "(" << makeCommon(months) << ")" << " "
+      << "(" << makeCommon(weekdays) << "|L|" << weekdays << "#" << "[1-5]" << ")"

Review Comment:
   is a space missing from the end here?



##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "^"
+      << "(" << makeCommon(secs) << ")" << " "
+      << "(" << makeCommon(mins) << ")" << " "
+      << "(" << makeCommon(hours) << ")" << " "
+      << "(" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")" << " "
+      << "(" << makeCommon(months) << ")" << " "
+      << "(" << makeCommon(weekdays) << "|L|" << weekdays << "#" << "[1-5]" << ")"
+      << "( " << makeCommon(years) << ")?"
+      << "$";
+
+  }
+
+  return prettifyJson(R"(
+{
+  "$schema": "http://json-schema.org/draft-07/schema",
+  "$defs": {)" + std::move(all_rels).str() + R"(
+    "datasize": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(B|K|M|G|T|P|KB|MB|GB|TB|PT)\\s*$"
+    },
+    "uuid": {
+      "type": "string",
+      "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
+      "default": "00000000-0000-0000-0000-000000000000"
+    },
+    "cron_pattern": {
+      "type": "string",
+      "pattern": ")" + std::move(cron_pattern).str() + R"("
+    },
+    "remote_port": {
+      "type": "object",
+      "properties": {
+        "required": ["name", "id", "Properties"],
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "max concurrent tasks": {"type": "integer"},
+        )" + std::move(remote_port_props).str() +  R"(
+      }
+    },
+    "time": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(ns|nano|nanos|nanoseconds|nanosecond|us|micro|micros|microseconds|microsecond|msec|ms|millisecond|milliseconds|msecs|millis|milli|sec|s|second|seconds|secs|min|m|mins|minute|minutes|h|hr|hour|hrs|hours|d|day|days)\\s*$"
+    },
+    "controller_service": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "class"],
+      "properties": {
+        "name": {"type": "string"},
+        "class": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"}
+      }
+    }, )" + controller_services + R"(]},
+    "processor": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "class", "scheduling strategy"],
+      "additionalProperties": false,
+      "properties": {
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "class": {"type": "string"},
+        "max concurrent tasks": {"type": "integer", "default": 1},
+        "penalization period": {"$ref": "#/$defs/time"},
+        "yield period": {"$ref": "#/$defs/time"},
+        "run duration nanos": {"$ref": "#/$defs/time"},
+        "Properties": {},
+        "scheduling strategy": {"enum": ["EVENT_DRIVEN", "TIMER_DRIVEN", "CRON_DRIVEN"]},
+        "scheduling period": {},
+        "auto-terminated relationships list": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "uniqueItems": true
+        }
+      }}, {
+        "if": {"properties": {"scheduling strategy": {"const": "EVENT_DRIVEN"}}},
+        "then": {"properties": {"scheduling period": false}}
+      }, {
+        "if": {"properties": {"scheduling strategy": {"const": "TIMER_DRIVEN"}}},
+        "then": {"required": ["scheduling period"], "properties": {"scheduling period": {"$ref": "#/$defs/time"}}}
+      }, {
+        "if": {"properties": {"scheduling strategy": {"const": "CRON_DRIVEN"}}},
+        "then": {"required": ["scheduling period"], "properties": {"scheduling period": {"$ref": "#/$defs/cron_pattern"}}}
+      }, )" + processors + R"(]
+    },
+    "remote_process_group": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "Input Ports"],
+      "properties": {
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "url": {"type": "string"},
+        "yield period": {"$ref": "#/$defs/time"},
+        "timeout": {"$ref": "#/$defs/time"},
+        "local network interface": {"type": "string"},
+        "transport protocol": {"enum": ["HTTP", "RAW"]},
+        "Input Ports": {
+          "type": "array",
+          "items": {"$ref": "#/$defs/remote_port"}
+        },
+        "Output Ports": {
+          "type": "array",
+          "items": {"$ref": "#/$defs/remote_port"}
+        }
+      }
+    }, {
+      "if": {"properties": {"transport protocol": {"const": "HTTP"}}},
+      "then": {"properties": {
+        "proxy host": {"type": "string"},
+        "proxy user": {"type": "string"},
+        "proxy password": {"type": "string"},
+        "proxy port": {"type": "integer"}
+      }}
+    }]},
+    "connection": {
+      "type": "object",
+      "additionalProperties": false,
+      "required": ["name", "id", "source name", "source id", "source relationship names", "destination name", "destination id"],

Review Comment:
   `source name` and `destination name` are not really required



##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";

Review Comment:
   clang-tidy doesn't like it that this branch does the same as line 73; this is silly, but we have to obey our robot overlords



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1003060183


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";

Review Comment:
   added a big old `NOLINT`, they do the same thing but for different reasons



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1042191877


##########
minifi_main/JsonSchema.h:
##########
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+
+namespace org::apache::nifi::minifi::docs {
+
+std::string generateJsonSchema();

Review Comment:
   I am not sure how we would check the validity, currently we depend on the editor's capabilities to inform the user of any invalid json



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1003063173


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");

Review Comment:
   descriptions could contain newlines, not clear why I went for removal and not an escaped newline, changed it for an escaped newline



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] martinzink commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
martinzink commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1005698054


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,436 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "\\n");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      // special value types
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";  // NOLINT(bugprone-branch-clone)
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "^"
+      << "(" << makeCommon(secs) << ")"
+      << "( " << makeCommon(mins) << ")"
+      << "( " << makeCommon(hours) << ")"
+      << "( " << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")"
+      << "( " << makeCommon(months) << ")"
+      << "( " << makeCommon(weekdays) << "|L|" << weekdays << "#" << "[1-5]" << ")"
+      << "( " << makeCommon(years) << ")?"
+      << "$";

Review Comment:
   ```suggestion
       cron_pattern << "(?i)^"
         << "(" << makeCommon(secs) << ")"
         << " (" << makeCommon(mins) << ")"
         << " (" << makeCommon(hours) << ")"
         << " (" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")"
         << " (" << makeCommon(months) << ")"
         << " (" << makeCommon(weekdays) << "|" << weekdays << "?L|" << weekdays << "#" << "[1-5]" << ")"
         << "( (" << makeCommon(years) << "))?"
         << "$";
   ```
   based on our debugging session I think this should be the regex



##########
minifi_main/MiNiFiMain.cpp:
##########
@@ -269,6 +279,21 @@ int main(int argc, char **argv) {
       exit(0);
     }
 
+    if (argc >= 2 && std::string("schema") == argv[1]) {
+      if (argc != 3) {
+        std::cerr << "Malformed schema command, expected '<minifiexe> schema <output-file>'" << std::endl;
+        std::exit(1);
+      }
+
+      std::cerr << "Writing json schema to " << argv[2] << std::endl;

Review Comment:
   I think this could go on std::cout instead of cerr (same applies to line 265)



##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,436 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "\\n");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      // special value types
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";  // NOLINT(bugprone-branch-clone)
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "^"
+      << "(" << makeCommon(secs) << ")"
+      << "( " << makeCommon(mins) << ")"
+      << "( " << makeCommon(hours) << ")"
+      << "( " << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")"
+      << "( " << makeCommon(months) << ")"
+      << "( " << makeCommon(weekdays) << "|L|" << weekdays << "#" << "[1-5]" << ")"
+      << "( " << makeCommon(years) << ")?"
+      << "$";
+
+  }
+
+  return prettifyJson(R"(
+{
+  "$schema": "http://json-schema.org/draft-07/schema",
+  "$defs": {)" + std::move(all_rels).str() + R"(
+    "datasize": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(B|K|M|G|T|P|KB|MB|GB|TB|PB)\\s*$"
+    },
+    "uuid": {
+      "type": "string",
+      "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
+      "default": "00000000-0000-0000-0000-000000000000"
+    },
+    "cron_pattern": {
+      "type": "string",
+      "pattern": ")" + std::move(cron_pattern).str() + R"("
+    },
+    "remote_port": {
+      "type": "object",
+      "properties": {
+        "required": ["name", "id", "Properties"],
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "max concurrent tasks": {"type": "integer"},
+        )" + std::move(remote_port_props).str() +  R"(
+      }
+    },
+    "time": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(ns|nano|nanos|nanoseconds|nanosecond|us|micro|micros|microseconds|microsecond|msec|ms|millisecond|milliseconds|msecs|millis|milli|sec|s|second|seconds|secs|min|m|mins|minute|minutes|h|hr|hour|hrs|hours|d|day|days)\\s*$"
+    },
+    "controller_service": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "class"],
+      "properties": {
+        "name": {"type": "string"},
+        "class": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"}
+      }
+    }, )" + controller_services + R"(]},
+    "processor": {"allOf": [{
+      "type": "object",
+      "required": ["name", "id", "class", "scheduling strategy"],
+      "additionalProperties": false,
+      "properties": {
+        "name": {"type": "string"},
+        "id": {"$ref": "#/$defs/uuid"},
+        "class": {"type": "string"},
+        "max concurrent tasks": {"type": "integer", "default": 1},
+        "penalization period": {"$ref": "#/$defs/time"},
+        "yield period": {"$ref": "#/$defs/time"},
+        "run duration nanos": {"$ref": "#/$defs/time"},
+        "Properties": {},
+        "scheduling strategy": {"enum": ["EVENT_DRIVEN", "TIMER_DRIVEN", "CRON_DRIVEN"]},
+        "scheduling period": {},
+        "auto-terminated relationships list": {
+          "type": "array",
+          "items": {
+            "type": "string"
+          },
+          "uniqueItems": true
+        }
+      }}, {
+        "if": {"properties": {"scheduling strategy": {"const": "EVENT_DRIVEN"}}},
+        "then": {"properties": {"scheduling period": false}}
+      }, {
+        "if": {"properties": {"scheduling strategy": {"const": "TIMER_DRIVEN"}}},
+        "then": {"required": ["scheduling period"], "properties": {"scheduling period": {"$ref": "#/$defs/time"}}}
+      }, {
+        "if": {"properties": {"scheduling strategy": {"const": "CRON_DRIVEN"}}},
+        "then": {"required": ["scheduling period"], "properties": {"scheduling period": {"$ref": "#/$defs/cron_pattern"}}}
+      }, )" + processors + R"(]

Review Comment:
   ```suggestion
         })" + (!processors.empty() ? ", " : "") + processors + R"(]
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1003062203


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "^"
+      << "(" << makeCommon(secs) << ")" << " "
+      << "(" << makeCommon(mins) << ")" << " "
+      << "(" << makeCommon(hours) << ")" << " "
+      << "(" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")" << " "
+      << "(" << makeCommon(months) << ")" << " "
+      << "(" << makeCommon(weekdays) << "|L|" << weekdays << "#" << "[1-5]" << ")"
+      << "( " << makeCommon(years) << ")?"
+      << "$";
+
+  }
+
+  return prettifyJson(R"(
+{
+  "$schema": "http://json-schema.org/draft-07/schema",
+  "$defs": {)" + std::move(all_rels).str() + R"(
+    "datasize": {
+      "type": "string",
+      "pattern": "^\\s*[0-9]+\\s*(B|K|M|G|T|P|KB|MB|GB|TB|PT)\\s*$"

Review Comment:
   nice catch, hopefully not something users would encounter 😃 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1003061489


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,435 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }
+  out << "}";  // property.getName()
+}
+
+template<typename PropertyContainer>
+void writeProperties(const PropertyContainer& props, bool supports_dynamic, std::ostream& out) {
+  out << R"("Properties": {)"
+        << R"("type": "object",)"
+        << R"("additionalProperties": )" << (supports_dynamic? "true" : "false") << ","
+        << R"("required": [)"
+        << (props
+            | ranges::views::filter([] (auto& prop) {return prop.getRequired() && prop.getDefaultValue().empty();})
+            | ranges::views::transform([] (auto& prop) {return '"' + escape(prop.getName()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+
+  out << R"(, "properties": {)";
+  for (size_t prop_idx = 0; prop_idx < props.size(); ++prop_idx) {
+    const auto& property = props[prop_idx];
+    if (prop_idx != 0) out << ",";
+    writePropertySchema(property, out);
+  }
+  out << "}";  // "properties"
+  out << "}";  // "Properties"
+}
+
+static std::string buildSchema(const std::unordered_map<std::string, std::string>& relationships, const std::string& processors, const std::string& controller_services) {
+  std::stringstream all_rels;
+  for (const auto& [name, rels] : relationships) {
+    all_rels << "\"relationships-" << escape(name) << "\": " << rels << ", ";
+  }
+
+  std::stringstream remote_port_props;
+  writeProperties(minifi::RemoteProcessorGroupPort::properties(), minifi::RemoteProcessorGroupPort::SupportsDynamicProperties, remote_port_props);
+
+  std::string process_group_properties = R"(
+    "Processors": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/processor"}
+    },
+    "Connections": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/connection"}
+    },
+    "Controller Services": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/controller_service"}
+    },
+    "Remote Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/remote_process_group"}
+    },
+    "Process Groups": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/simple_process_group"}
+    },
+    "Funnels": {
+      "type": "array",
+      "items": {"$ref": "#/$defs/funnel"}
+    }
+  )";
+
+  std::stringstream cron_pattern;
+  {
+    const char* all = "\\\\*";
+    const char* any = "\\\\?";
+    const char* increment = "(-?[0-9]+)";
+    const char* secs = "([0-5]?[0-9])";
+    const char* mins = "([0-5]?[0-9])";
+    const char* hours = "(1?[0-9]|2[0-3])";
+    const char* days = "([1-2]?[0-9]|3[0-1])";
+    const char* months = "([0-9]|1[0-2]|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";
+    const char* weekdays = "([0-7]|sun|mon|tue|wed|thu|fri|sat)";
+    const char* years = "([0-9]+)";
+
+    auto makeCommon = [&] (const char* pattern) {
+      std::stringstream common;
+      common << all << "|" << any
+        << "|" << pattern << "(," << pattern << ")*"
+        << "|" << pattern << "-" << pattern
+        << "|" << "(" << all << "|" << pattern << ")" << "/" << increment;
+      return std::move(common).str();
+    };
+
+    cron_pattern << "^"
+      << "(" << makeCommon(secs) << ")" << " "
+      << "(" << makeCommon(mins) << ")" << " "
+      << "(" << makeCommon(hours) << ")" << " "
+      << "(" << makeCommon(days) << "|LW|L|L-" << days << "|" << days << "W" << ")" << " "
+      << "(" << makeCommon(months) << ")" << " "
+      << "(" << makeCommon(weekdays) << "|L|" << weekdays << "#" << "[1-5]" << ")"

Review Comment:
   it was hidden after the next line's opening parenthesis (that is an optional block), moved all the spaces to the beginning, hopefully it is easier to read now



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] martinzink commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
martinzink commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1005719939


##########
minifi_main/JsonSchema.cpp:
##########
@@ -0,0 +1,436 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "JsonSchema.h"
+
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "agent/agent_version.h"
+#include "agent/build_description.h"
+#include "rapidjson/document.h"
+#include "rapidjson/prettywriter.h"
+#include "RemoteProcessorGroupPort.h"
+#include "utils/gsl.h"
+
+#include "range/v3/view/filter.hpp"
+#include "range/v3/view/transform.hpp"
+#include "range/v3/view/join.hpp"
+#include "range/v3/range/conversion.hpp"
+
+namespace org::apache::nifi::minifi::docs {
+
+static std::string escape(std::string str) {
+  utils::StringUtils::replaceAll(str, "\"", "\\\"");
+  utils::StringUtils::replaceAll(str, "\n", "\\n");
+  return str;
+}
+
+static std::string prettifyJson(const std::string& str) {
+  rapidjson::Document doc;
+  rapidjson::ParseResult res = doc.Parse(str.c_str(), str.length());
+  gsl_Assert(res);
+
+  rapidjson::StringBuffer buffer;
+
+  rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
+  doc.Accept(writer);
+
+  return std::string{buffer.GetString(), buffer.GetSize()};
+}
+
+void writePropertySchema(const core::Property& prop, std::ostream& out) {
+  out << "\"" << escape(prop.getName()) << "\" : {";
+  out << R"("description": ")" << escape(prop.getDescription()) << "\"";
+  if (const auto& values = prop.getAllowedValues(); !values.empty()) {
+    out << R"(, "enum": [)"
+        << (values
+            | ranges::views::transform([] (auto& val) {return '"' + escape(val.to_string()) + '"';})
+            | ranges::views::join(std::string{','})
+            | ranges::to<std::string>())
+        << "]";
+  }
+  if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
+    const auto& type = def_value.getTypeInfo();
+    // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
+    if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
+        || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) {
+      // special value types
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
+    } else if (type == state::response::Value::INT_TYPE
+        || type == state::response::Value::INT64_TYPE
+        || type == state::response::Value::UINT32_TYPE
+        || type == state::response::Value::UINT64_TYPE) {
+      out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
+    } else if (type == state::response::Value::DOUBLE_TYPE) {
+      out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
+    } else if (type == state::response::Value::BOOL_TYPE) {
+      out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
+    } else {
+      out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";  // NOLINT(bugprone-branch-clone)
+    }
+  } else {
+    // no default value, no type information, fallback to string
+    out << R"(, "type": "string")";
+  }

Review Comment:
   for the clang tidy error
   ```suggestion
     if (const auto& def_value = prop.getDefaultValue(); !def_value.empty()) {
       const auto& type = def_value.getTypeInfo();
       // order is important as both DataSizeValue and TimePeriodValue's type_id is uint64_t
       if (std::dynamic_pointer_cast<core::DataSizeValue>(def_value.getValue())
           || std::dynamic_pointer_cast<core::TimePeriodValue>(def_value.getValue())) { // NOLINT(bugprone-branch-clone)
         // special value types
         out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
       } else if (type == state::response::Value::INT_TYPE
           || type == state::response::Value::INT64_TYPE
           || type == state::response::Value::UINT32_TYPE
           || type == state::response::Value::UINT64_TYPE) {
         out << R"(, "type": "integer", "default": )" << static_cast<int64_t>(def_value);
       } else if (type == state::response::Value::DOUBLE_TYPE) {
         out << R"(, "type": "number", "default": )" << static_cast<double>(def_value);
       } else if (type == state::response::Value::BOOL_TYPE) {
         out << R"(, "type": "boolean", "default": )" << (static_cast<bool>(def_value) ? "true" : "false");
       } else {
         out << R"(, "type": "string", "default": ")" << escape(def_value.to_string()) << "\"";
       }
     } else {
       // no default value, no type information, fallback to string
       out << R"(, "type": "string")";
     }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi-minifi-cpp] lordgamez commented on a diff in pull request #1413: MINIFICPP-1917 - Generate flow config JSON schema

Posted by GitBox <gi...@apache.org>.
lordgamez commented on code in PR #1413:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1413#discussion_r1050559125


##########
minifi_main/JsonSchema.h:
##########
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+
+namespace org::apache::nifi::minifi::docs {
+
+std::string generateJsonSchema();

Review Comment:
   Great addition, thank you!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org