Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
sabudilovskiy committed Oct 24, 2023
1 parent bfd645f commit 19cc2ed
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 74 deletions.
8 changes: 8 additions & 0 deletions .gen/objs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ src/openapi/json/serialize/string_property.hpp
src/openapi/json/serialize/reflective.hpp
src/openapi/json/serialize/optional_property.hpp
src/openapi/json/serialize/object_property.hpp
src/openapi/json/serialize/enum.hpp
src/openapi/json/serialize/datetime_property.hpp
src/openapi/json/serialize/base_property.hpp
src/openapi/json/serialize/array_property.hpp
Expand All @@ -67,6 +68,7 @@ src/openapi/json/parse/string_property.hpp
src/openapi/json/parse/reflective.hpp
src/openapi/json/parse/optional_property.hpp
src/openapi/json/parse/object_property.hpp
src/openapi/json/parse/enum.hpp
src/openapi/json/parse/datetime_property.hpp
src/openapi/json/parse/base_property.hpp
src/openapi/json/parse/array_property.hpp
Expand Down Expand Up @@ -110,6 +112,7 @@ src/openapi/doc/path.hpp
src/openapi/doc/optional.hpp
src/openapi/doc/int.hpp
src/openapi/doc/header.hpp
src/openapi/doc/enum.hpp
src/openapi/doc/datetime.hpp
src/openapi/doc/cookie.hpp
src/openapi/doc/body.hpp
Expand Down Expand Up @@ -139,6 +142,11 @@ src/openapi/base/preferences.hpp
src/openapi/base/named_traits.hpp
src/openapi/base/holder_named.hpp
src/openapi/base/holder.hpp
src/openapi/base/enum/string.hpp
src/openapi/base/enum/postgres.hpp
src/openapi/base/enum/introspector.hpp
src/openapi/base/enum/declare.hpp
src/openapi/base/enum/all.hpp
src/openapi/base/doc.hpp
src/openapi/base/all.hpp
src/openapi/as_tuple/vector.hpp
Expand Down
1 change: 1 addition & 0 deletions .gen/unittest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ utests/openapi/http/basic_http_request.cpp
utests/openapi/doc/serialize/basic_response.cpp
utests/openapi/doc/serialize/basic_request.cpp
utests/openapi/doc/serialize/basic_path.cpp
utests/openapi/doc/serialize/basic_enum.cpp
utests/openapi/doc/serialize/basic.cpp
utests/hello_test.cpp
utests/dropper_additional.cpp
Expand Down
1 change: 1 addition & 0 deletions src/openapi/base/all.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <openapi/base/doc.hpp>
#include <openapi/base/enum/all.hpp>
#include <openapi/base/holder.hpp>
#include <openapi/base/holder_named.hpp>
#include <openapi/base/named_traits.hpp>
Expand Down
46 changes: 7 additions & 39 deletions src/openapi/base/named_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,23 @@ namespace checks
template <typename T>
concept HasName = requires
{
{
decltype(T::kName)::kSize
}
->std::convertible_to<std::size_t>;
requires std::is_same_v<utils::ConstexprString<decltype(T::kName)::kSize>,
std::remove_cv_t<decltype(T::kName)>>;
{
T::kName
}
->std::convertible_to<utils::ConstexprString<decltype(T::kName)::kSize>>;
{T::kName};
};

template <typename T>
concept HasNotName = !HasName<T>;
} // namespace checks

namespace details
{
template <checks::HasName T>
constexpr auto _getName()
{
return T::kName;
}

template <checks::HasNotName T>
constexpr auto _getName()
{
using Type = utils::ConstexprString<1>;
return Type{""};
}
} // namespace details

struct ConstexprSetString
{
std::array<std::string_view, 256> test;
};

consteval ConstexprSetString foo()
{
return {};
}

namespace traits
{
// returns ConstexprString
template <typename T>
constexpr auto GetName()
{
return details::_getName<T>();
if constexpr (checks::HasName<T>)
{
return T::kName;
}
else
return utils::kEmptyString;
}

template <typename Traits>
Expand Down
1 change: 1 addition & 0 deletions src/openapi/doc/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <openapi/doc/body.hpp>
#include <openapi/doc/cookie.hpp>
#include <openapi/doc/datetime.hpp>
#include <openapi/doc/enum.hpp>
#include <openapi/doc/header.hpp>
#include <openapi/doc/int.hpp>
#include <openapi/doc/optional.hpp>
Expand Down
7 changes: 3 additions & 4 deletions src/openapi/doc/reflective.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ inline void AppendField(DocHelper, std::type_identity<AdditionalProperties>)

template <typename T>
requires checks::is_reflective_v<T> void Append(DocHelper doc_helper,
std::type_identity<T>,
bool append_cur_place = true)
std::type_identity<T>)
{
std::string name_type = GetOpenApiTypeName<T>();
if (append_cur_place)
if (&doc_helper.cur_place != &doc_helper.root)
{
PlaceRefToType<T>(doc_helper.cur_place);
}
Expand All @@ -66,7 +65,7 @@ template <typename T>
requires checks::is_reflective_v<T> void Append(Doc& doc, std::type_identity<T>)
{
auto& root = doc.value_;
Append(DocHelper{root, root}, std::type_identity<T>{}, false);
Append(DocHelper{root, root}, std::type_identity<T>{});
}

} // namespace openapi
1 change: 1 addition & 0 deletions src/openapi/json/parse/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <openapi/json/parse/array_property.hpp>
#include <openapi/json/parse/base_property.hpp>
#include <openapi/json/parse/datetime_property.hpp>
#include <openapi/json/parse/enum.hpp>
#include <openapi/json/parse/object_property.hpp>
#include <openapi/json/parse/optional_property.hpp>
#include <openapi/json/parse/reflective.hpp>
Expand Down
1 change: 1 addition & 0 deletions src/openapi/json/serialize/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <openapi/json/serialize/array_property.hpp>
#include <openapi/json/serialize/base_property.hpp>
#include <openapi/json/serialize/datetime_property.hpp>
#include <openapi/json/serialize/enum.hpp>
#include <openapi/json/serialize/object_property.hpp>
#include <openapi/json/serialize/optional_property.hpp>
#include <openapi/json/serialize/reflective.hpp>
Expand Down
18 changes: 7 additions & 11 deletions src/openapi/json/serialize/datetime_property.hpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
#pragma once

#include <openapi/base/properties/datetime.hpp>
#include <openapi/base/enum/string.hpp>
#include <userver/formats/json/value.hpp>
#include <userver/formats/json/value_builder.hpp>
#include <userver/utils/datetime.hpp>

namespace openapi
{
template <typename Traits>
template <typename T>
userver::formats::json::Value Serialize(
const DateTimeProperty<Traits>& item,
userver::formats::serialize::To<userver::formats::json::Value>)
const T& item,
userver::formats::serialize::To<
userver::formats::json::Value>) requires HasIntrospector<T>
{
using namespace openapi;

auto& value = item();

auto string = userver::utils::datetime::Timestring(value.GetUnderlying());
return userver::formats::json::ValueBuilder{string}
.ExtractValue();
std::string str = openapi::to_string_view(item);
return userver::formats::json::ValueBuilder{str}.ExtractValue();
}

} // namespace openapi
8 changes: 6 additions & 2 deletions src/utils/constexpr_string.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <algorithm>
#include <array>
#include <iostream>
#include <string_view>

namespace utils
Expand Down Expand Up @@ -35,7 +34,7 @@ struct ConstexprString

constexpr std::string_view AsStringView() const
{
return {contents.begin(), contents.begin() + Size - 1};
return std::string_view{contents.data(), Size - 1};
}

std::string AsString() const
Expand All @@ -53,6 +52,11 @@ struct ConstexprString
return Size == 1;
}

constexpr auto size() const
{
return Size;
}

constexpr auto c_str() const -> const char*
{
return contents.data();
Expand Down
28 changes: 19 additions & 9 deletions src/utils/shared_transaction.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pragma once
#include <boost/uuid/uuid.hpp>
#include <exception>
#include <string_view>
#include <type_traits>
#include <userver/logging/log.hpp>
#include <userver/storages/postgres/cluster.hpp>
#include <userver/storages/postgres/cluster_types.hpp>
#include <userver/storages/postgres/io/row_types.hpp>
Expand Down Expand Up @@ -137,16 +139,24 @@ struct SafeTranscaction
}
~SafeTranscaction()
{
switch (action_on_death)
try
{
case ActionOnDeath::kCommit:
transaction_.Commit();
return;
case ActionOnDeath::kRollback:
transaction_.Rollback();
return;
case ActionOnDeath::kNone:
return;
switch (action_on_death)
{
case ActionOnDeath::kCommit:
transaction_.Commit();
return;
case ActionOnDeath::kRollback:
transaction_.Rollback();
return;
case ActionOnDeath::kNone:
return;
}
}
catch (std::exception& exc)
{
LOG_ERROR() << "Error while do action in SafeTransaction: "
<< exc.what();
}
}

Expand Down
2 changes: 1 addition & 1 deletion third_party/userver
Submodule userver updated 653 files
4 changes: 2 additions & 2 deletions utests/openapi/doc/serialize/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct User
};
} // namespace tests2

UTEST(Openapi_Doc_Serialize, MoreOneNamespace)
UTEST(Openapi_Doc, MoreOneNamespace)
{
::openapi::Doc doc;
Append(doc, std::type_identity<tests2::User>{});
Expand Down Expand Up @@ -93,7 +93,7 @@ struct SomeStructure
};
} // namespace tests

UTEST(Openapi_Doc_Serialize, BasicAdditionalProperties)
UTEST(Openapi_Doc, BasicAdditionalProperties)
{
::openapi::Doc doc;
Append(doc, std::type_identity<::tests::SomeStructure>{});
Expand Down
2 changes: 1 addition & 1 deletion utests/openapi/doc/serialize/basic_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct SomeResponse
};
} // namespace tests_path

UTEST(Openapi_Doc_Serialize, BasicPath)
UTEST(Openapi_Doc, BasicPath)
{
Doc doc;
std::string path = "/login";
Expand Down
2 changes: 1 addition & 1 deletion utests/openapi/doc/serialize/basic_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct SomeRequest
};
} // namespace tests

UTEST(Openapi_Doc_Serialize, BasicRequest)
UTEST(Openapi_Doc, BasicRequest)
{
::openapi::Doc doc;
auto response = doc()["requests"][GetOpenApiTypeName<tests::SomeRequest>()];
Expand Down
2 changes: 1 addition & 1 deletion utests/openapi/doc/serialize/basic_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct SomeResponse
};
} // namespace tests

UTEST(Openapi_Doc_Serialize, BasicResponse)
UTEST(Openapi_Doc, BasicResponse)
{
Doc doc;
AppendResponse(doc, std::type_identity<tests::SomeResponse>{});
Expand Down
2 changes: 1 addition & 1 deletion utests/openapi/http/basic_http_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using namespace openapi::preferences;
using namespace openapi::types;
using namespace std::literals;

UTEST(Openapi_Doc_Serialize, BasicStatusCode)
UTEST(Openapi_Doc, BasicStatusCode)
{
EXPECT_EQ(Code<200>::value, userver::server::http::HttpStatus::kOk);
}
Expand Down
6 changes: 4 additions & 2 deletions utests/openapi/json/parse/basic_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <vector>

using namespace openapi;
using namespace openapi::types;
using namespace openapi::preferences;

UTEST(Openapi_Json_Parse, BasicArrayProperty)
{
Expand Down Expand Up @@ -43,10 +45,10 @@ UTEST(Openapi_Json_Parse, BasicArrayPropertyMin)

UTEST(Openapi_Json_Parse, BasicArrayPropertyMax)
{
using Type = types::Array<int, preferences::Max<2>, preferences::Min<1>>;
using Type = Array<int, Max<2>, Min<1>, UniqueItems>;
constexpr auto jsonString = R"(
{
"test" : [1,2,2]
"test" : [1,2,3]
}
)";
auto json = userver::formats::json::FromString(jsonString);
Expand Down

0 comments on commit 19cc2ed

Please sign in to comment.