Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
sabudilovskiy committed Oct 21, 2023
1 parent 0a68c2a commit bfd645f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/openapi/base/holder_named.hpp
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
30 changes: 30 additions & 0 deletions utests/openapi/json/serialize/datetime.cpp
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\"");
}

0 comments on commit bfd645f

Please sign in to comment.