Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clang-fmt
Browse files Browse the repository at this point in the history
cwaldren-ld committed Sep 3, 2024
1 parent 35b5035 commit c6fa406
Showing 11 changed files with 210 additions and 255 deletions.
153 changes: 61 additions & 92 deletions contract-tests/data-model/include/data_model/data_model.hpp
Original file line number Diff line number Diff line change
@@ -5,41 +5,30 @@
#include <unordered_map>
#include "nlohmann/json.hpp"

Check failure on line 6 in contract-tests/data-model/include/data_model/data_model.hpp

GitHub Actions / cpp-linter

/contract-tests/data-model/include/data_model/data_model.hpp:6:10 [clang-diagnostic-error]

'nlohmann/json.hpp' file not found

namespace nlohmann
{
template <typename T>
struct adl_serializer<std::optional<T>>
{
static void to_json(json& j, std::optional<T> const& opt)
{
if (opt == std::nullopt)
{
j = nullptr;
}
else
{
j = *opt; // this will call adl_serializer<T>::to_json which will
// find the free function to_json in T's namespace!
}
namespace nlohmann {
template <typename T>
struct adl_serializer<std::optional<T>> {
static void to_json(json& j, std::optional<T> const& opt) {
if (opt == std::nullopt) {
j = nullptr;
} else {
j = *opt; // this will call adl_serializer<T>::to_json which will
// find the free function to_json in T's namespace!
}

static void from_json(json const& j, std::optional<T>& opt)
{
if (j.is_null())
{
opt = std::nullopt;
}
else
{
opt = j.get<T>(); // same as above, but with
// adl_serializer<T>::from_json
}
}

static void from_json(json const& j, std::optional<T>& opt) {
if (j.is_null()) {
opt = std::nullopt;
} else {
opt = j.get<T>(); // same as above, but with
// adl_serializer<T>::from_json
}
};
} // namespace nlohmann
}
};
} // namespace nlohmann

struct ConfigTLSParams
{
struct ConfigTLSParams {
std::optional<bool> skipVerifyPeer;
std::optional<std::string> customCAFile;
};
@@ -48,30 +37,29 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigTLSParams,
skipVerifyPeer,
customCAFile);

struct ConfigStreamingParams
{
struct ConfigStreamingParams {
std::optional<std::string> baseUri;
std::optional<uint32_t> initialRetryDelayMs;
std::optional<std::string> filter;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigStreamingParams,
baseUri,
initialRetryDelayMs, filter);
initialRetryDelayMs,
filter);

struct ConfigPollingParams
{
struct ConfigPollingParams {
std::optional<std::string> baseUri;
std::optional<uint32_t> pollIntervalMs;
std::optional<std::string> filter;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigPollingParams,
baseUri,
pollIntervalMs, filter);
pollIntervalMs,
filter);

struct ConfigEventParams
{
struct ConfigEventParams {

Check warning on line 62 in contract-tests/data-model/include/data_model/data_model.hpp

GitHub Actions / cpp-linter

/contract-tests/data-model/include/data_model/data_model.hpp:62:8 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: globalPrivateAttributes
std::optional<std::string> baseUri;
std::optional<uint32_t> capacity;
std::optional<bool> enableDiagnostics;
@@ -88,8 +76,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigEventParams,
globalPrivateAttributes,
flushIntervalMs);

struct ConfigServiceEndpointsParams
{
struct ConfigServiceEndpointsParams {
std::optional<std::string> streaming;
std::optional<std::string> polling;
std::optional<std::string> events;
@@ -100,8 +87,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigServiceEndpointsParams,
polling,
events);

struct ConfigClientSideParams
{
struct ConfigClientSideParams {

Check warning on line 90 in contract-tests/data-model/include/data_model/data_model.hpp

GitHub Actions / cpp-linter

/contract-tests/data-model/include/data_model/data_model.hpp:90:8 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: initialContext
nlohmann::json initialContext;
std::optional<bool> evaluationReasons;
std::optional<bool> useReport;
@@ -112,8 +98,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigClientSideParams,
evaluationReasons,
useReport);

struct ConfigTags
{
struct ConfigTags {
std::optional<std::string> applicationId;
std::optional<std::string> applicationVersion;
};
@@ -122,8 +107,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigTags,
applicationId,
applicationVersion);

struct ConfigParams
{
struct ConfigParams {
std::string credential;
std::optional<uint32_t> startWaitTimeMs;
std::optional<bool> initCanFail;
@@ -148,8 +132,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigParams,
tags,
tls);

struct ContextSingleParams
{
struct ContextSingleParams {

Check warning on line 135 in contract-tests/data-model/include/data_model/data_model.hpp

GitHub Actions / cpp-linter

/contract-tests/data-model/include/data_model/data_model.hpp:135:8 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: custom
std::optional<std::string> kind;
std::string key;
std::optional<std::string> name;
@@ -161,8 +144,7 @@ struct ContextSingleParams
// These are defined manually because of the 'private' field, which is a
// reserved keyword in C++.
inline void to_json(nlohmann::json& nlohmann_json_j,
ContextSingleParams const& nlohmann_json_t)
{
ContextSingleParams const& nlohmann_json_t) {
nlohmann_json_j["kind"] = nlohmann_json_t.kind;
nlohmann_json_j["key"] = nlohmann_json_t.key;
nlohmann_json_j["name"] = nlohmann_json_t.name;
@@ -172,8 +154,7 @@ inline void to_json(nlohmann::json& nlohmann_json_j,
}

inline void from_json(nlohmann::json const& nlohmann_json_j,
ContextSingleParams& nlohmann_json_t)
{
ContextSingleParams& nlohmann_json_t) {
ContextSingleParams nlohmann_json_default_obj;
nlohmann_json_t.kind =
nlohmann_json_j.value("kind", nlohmann_json_default_obj.kind);
@@ -189,8 +170,7 @@ inline void from_json(nlohmann::json const& nlohmann_json_j,
nlohmann_json_j.value("custom", nlohmann_json_default_obj.custom);
}

struct ContextBuildParams
{
struct ContextBuildParams {
std::optional<ContextSingleParams> single;
std::optional<std::vector<ContextSingleParams>> multi;
};
@@ -199,23 +179,20 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ContextBuildParams,
single,
multi);

struct ContextConvertParams
{
struct ContextConvertParams {
std::string input;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ContextConvertParams, input);

struct ContextResponse
{
struct ContextResponse {
std::optional<std::string> output;
std::optional<std::string> error;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ContextResponse, output, error);

struct CreateInstanceParams
{
struct CreateInstanceParams {
ConfigParams configuration;
std::string tag;
};
@@ -228,14 +205,13 @@ enum class ValueType { Bool = 1, Int, Double, String, Any, Unspecified };

NLOHMANN_JSON_SERIALIZE_ENUM(ValueType,
{{ValueType::Bool, "bool"},
{ValueType::Int, "int"},
{ValueType::Double, "double"},
{ValueType::String, "string"},
{ValueType::Any, "any"},
{ValueType::Unspecified, ""}})

struct EvaluateFlagParams
{
{ValueType::Int, "int"},
{ValueType::Double, "double"},
{ValueType::String, "string"},
{ValueType::Any, "any"},
{ValueType::Unspecified, ""}})

struct EvaluateFlagParams {
std::string flagKey;
std::optional<nlohmann::json> context;
ValueType valueType;
@@ -251,8 +227,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(EvaluateFlagParams,
defaultValue,
detail);

struct EvaluateFlagResponse
{
struct EvaluateFlagResponse {

Check warning on line 230 in contract-tests/data-model/include/data_model/data_model.hpp

GitHub Actions / cpp-linter

/contract-tests/data-model/include/data_model/data_model.hpp:230:8 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: value, reason
nlohmann::json value;
std::optional<uint32_t> variationIndex;
std::optional<nlohmann::json> reason;
@@ -263,8 +238,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(EvaluateFlagResponse,
variationIndex,
reason);

struct EvaluateAllFlagParams
{
struct EvaluateAllFlagParams {

Check warning on line 241 in contract-tests/data-model/include/data_model/data_model.hpp

GitHub Actions / cpp-linter

/contract-tests/data-model/include/data_model/data_model.hpp:241:8 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: context
std::optional<nlohmann::json> context;
std::optional<bool> withReasons;
std::optional<bool> clientSideOnly;
@@ -277,16 +251,14 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(EvaluateAllFlagParams,
clientSideOnly,
detailsOnlyForTrackedFlags);

struct EvaluateAllFlagsResponse
{
struct EvaluateAllFlagsResponse {

Check warning on line 254 in contract-tests/data-model/include/data_model/data_model.hpp

GitHub Actions / cpp-linter

/contract-tests/data-model/include/data_model/data_model.hpp:254:8 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: state
nlohmann::json state;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(EvaluateAllFlagsResponse,
state);

struct CustomEventParams
{
struct CustomEventParams {
std::string eventKey;
std::optional<nlohmann::json> context;
std::optional<nlohmann::json> data;
@@ -301,15 +273,13 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(CustomEventParams,
omitNullData,
metricValue);

struct IdentifyEventParams
{
struct IdentifyEventParams {

Check warning on line 276 in contract-tests/data-model/include/data_model/data_model.hpp

GitHub Actions / cpp-linter

/contract-tests/data-model/include/data_model/data_model.hpp:276:8 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: context
nlohmann::json context;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(IdentifyEventParams, context);

enum class Command
{
enum class Command {
Unknown = -1,
EvaluateFlag,
EvaluateAllFlags,
@@ -322,16 +292,15 @@ enum class Command

NLOHMANN_JSON_SERIALIZE_ENUM(Command,
{{Command::Unknown, nullptr},
{Command::EvaluateFlag, "evaluate"},
{Command::EvaluateAllFlags, "evaluateAll"},
{Command::IdentifyEvent, "identifyEvent"},
{Command::CustomEvent, "customEvent"},
{Command::FlushEvents, "flushEvents"},
{Command::ContextBuild, "contextBuild"},
{Command::ContextConvert, "contextConvert"}});

struct CommandParams
{
{Command::EvaluateFlag, "evaluate"},
{Command::EvaluateAllFlags, "evaluateAll"},
{Command::IdentifyEvent, "identifyEvent"},
{Command::CustomEvent, "customEvent"},
{Command::FlushEvents, "flushEvents"},
{Command::ContextBuild, "contextBuild"},
{Command::ContextConvert, "contextConvert"}});

struct CommandParams {
Command command;
std::optional<EvaluateFlagParams> evaluate;
std::optional<EvaluateAllFlagParams> evaluateAll;
9 changes: 4 additions & 5 deletions contract-tests/server-contract-tests/src/entity_manager.cpp
Original file line number Diff line number Diff line change
@@ -11,8 +11,7 @@ using namespace launchdarkly::server_side;

EntityManager::EntityManager(boost::asio::any_io_executor executor,
launchdarkly::Logger& logger)
: counter_{0}, executor_{std::move(executor)}, logger_{logger} {
}
: counter_{0}, executor_{std::move(executor)}, logger_{logger} {}

std::optional<std::string> EntityManager::create(ConfigParams const& in) {
std::string id = std::to_string(counter_++);
@@ -32,9 +31,9 @@ std::optional<std::string> EntityManager::create(ConfigParams const& in) {

auto& endpoints =
config_builder.ServiceEndpoints()
.EventsBaseUrl(default_endpoints.EventsBaseUrl())
.PollingBaseUrl(default_endpoints.PollingBaseUrl())
.StreamingBaseUrl(default_endpoints.StreamingBaseUrl());
.EventsBaseUrl(default_endpoints.EventsBaseUrl())
.PollingBaseUrl(default_endpoints.PollingBaseUrl())
.StreamingBaseUrl(default_endpoints.StreamingBaseUrl());

if (in.serviceEndpoints) {
if (in.serviceEndpoints->streaming) {
Loading

0 comments on commit c6fa406

Please sign in to comment.