generated from userver-framework/service_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a68c2a
commit bfd645f
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include <openapi/base/holder.hpp> | ||
#include <openapi/base/named_traits.hpp> | ||
#include <openapi/base/preferences.hpp> | ||
#include <utils/constexpr_string.hpp> | ||
namespace openapi | ||
{ | ||
struct HolderNamed | ||
{ | ||
traits::HolderField<utils::FixedString> name; | ||
}; | ||
|
||
template <utils::ConstexprString value> | ||
consteval void Apply(HolderNamed& holder, preferences::Name<value>) | ||
{ | ||
holder.name = value; | ||
} | ||
|
||
namespace details | ||
{ | ||
template <typename... Option> | ||
auto resolve_named_traits() | ||
{ | ||
constexpr HolderNamed holder = | ||
traits::ResolveHolder<HolderNamed, Option...>(); | ||
static_assert(holder.name.counter_changes <= 1, | ||
"Don't use more 1 Name in template args"); | ||
constexpr auto name = utils::MakeConstexprString<holder.name()>(); | ||
return NamedTraits<name>{}; | ||
} | ||
} // namespace details | ||
|
||
template <typename... Option> | ||
using named_traits_from_options_t = | ||
decltype(details::resolve_named_traits<Option...>()); | ||
} // namespace openapi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <exception> | ||
#include <openapi/all.hpp> | ||
#include <stdexcept> | ||
#include <string_view> | ||
#include <userver/formats/json/value_builder.hpp> | ||
#include <userver/formats/serialize/boost_uuid.hpp> | ||
#include <userver/utest/utest.hpp> | ||
#include <userver/utils/datetime.hpp> | ||
#include <utility> | ||
#include <utils/constexpr_optional.hpp> | ||
#include <utils/constexpr_string.hpp> | ||
#include <utils/serialize/uuid/string.hpp> | ||
#include <utils/tests_macros.hpp> | ||
#include <vector> | ||
|
||
using namespace openapi::preferences; | ||
using namespace openapi::types; | ||
|
||
UTEST(Openapi_Json_Serialize, BasicDatetime) | ||
{ | ||
using Serializable = Datetime<>; | ||
Serializable serializable{ | ||
userver::utils::datetime::GuessLocalTimezoneStringtime( | ||
"2011-08-12T20:17:46.384Z")}; | ||
userver::formats::json::ValueBuilder json{serializable}; | ||
auto json_text = ToString(json.ExtractValue()); | ||
EXPECT_EQ(json_text, "\"2011-08-12T20:17:46.384+0000\""); | ||
} |