Skip to content

Commit

Permalink
Schema support for std::unordered_set (microsoft#6634)
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou authored Nov 13, 2024
1 parent ff1ec38 commit 2eb532a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

- Added a `ccf::any_cert_auth_policy` (C++), or `any_cert` (JS/TS), implementing TLS client certificate authentication, but without checking for the presence of the certificate in the governance user or member tables. This enables applications wanting to do so to perform user management in application space, using application tables (#6608).
- Added OpenAPI support for `std::unordered_set`.

## [6.0.0-dev5]

Expand Down
8 changes: 6 additions & 2 deletions include/ccf/ds/json_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <fmt/format.h>
#include <nlohmann/json.hpp>
#include <set>
#include <unordered_set>

namespace ccf::ds
{
Expand Down Expand Up @@ -113,7 +114,9 @@ namespace ccf::ds
return fmt::format("{}_array", schema_name<typename T::value_type>());
}
}
else if constexpr (ccf::nonstd::is_specialization<T, std::set>::value)
else if constexpr (
ccf::nonstd::is_specialization<T, std::set>::value ||
ccf::nonstd::is_specialization<T, std::unordered_set>::value)
{
return fmt::format("{}_set", schema_name<typename T::value_type>());
}
Expand Down Expand Up @@ -204,7 +207,8 @@ namespace ccf::ds
}
else if constexpr (
ccf::nonstd::is_specialization<T, std::vector>::value ||
ccf::nonstd::is_specialization<T, std::set>::value)
ccf::nonstd::is_specialization<T, std::set>::value ||
ccf::nonstd::is_specialization<T, std::unordered_set>::value)
{
if constexpr (std::is_same<T, std::vector<uint8_t>>::value)
{
Expand Down
4 changes: 3 additions & 1 deletion include/ccf/ds/openapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <regex>
#include <set>
#include <string_view>
#include <unordered_set>

namespace ccf::ds
{
Expand Down Expand Up @@ -281,7 +282,8 @@ namespace ccf::ds
}
else if constexpr (
ccf::nonstd::is_specialization<T, std::vector>::value ||
ccf::nonstd::is_specialization<T, std::set>::value)
ccf::nonstd::is_specialization<T, std::set>::value ||
ccf::nonstd::is_specialization<T, std::unordered_set>::value)
{
if constexpr (std::is_same<T, std::vector<uint8_t>>::value)
{
Expand Down
2 changes: 2 additions & 0 deletions src/ds/test/openapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ TEST_CASE("Complex custom types")
doc, "/app/complex", HTTP_POST);
openapi::add_response_schema<std::map<Baz, std::vector<Buzz>>>(
doc, "/app/complex", HTTP_POST, HTTP_STATUS_OK);
openapi::add_response_schema<std::unordered_set<Baz>>(
doc, "/app/complex", HTTP_POST, HTTP_STATUS_OK);

required_doc_elements(doc);
}
Expand Down

0 comments on commit 2eb532a

Please sign in to comment.