From 19cc2ed08552f4e838804bf91619d20299f9b2ce Mon Sep 17 00:00:00 2001 From: sabudilovskiy Date: Tue, 24 Oct 2023 17:39:10 +0000 Subject: [PATCH] - --- .gen/objs.txt | 8 ++++ .gen/unittest.txt | 1 + src/openapi/base/all.hpp | 1 + src/openapi/base/named_traits.hpp | 46 +++---------------- src/openapi/doc/all.hpp | 1 + src/openapi/doc/reflective.hpp | 7 ++- src/openapi/json/parse/all.hpp | 1 + src/openapi/json/serialize/all.hpp | 1 + .../json/serialize/datetime_property.hpp | 18 +++----- src/utils/constexpr_string.hpp | 8 +++- src/utils/shared_transaction.hpp | 28 +++++++---- third_party/userver | 2 +- utests/openapi/doc/serialize/basic.cpp | 4 +- utests/openapi/doc/serialize/basic_path.cpp | 2 +- .../openapi/doc/serialize/basic_request.cpp | 2 +- .../openapi/doc/serialize/basic_response.cpp | 2 +- utests/openapi/http/basic_http_request.cpp | 2 +- utests/openapi/json/parse/basic_array.cpp | 6 ++- 18 files changed, 66 insertions(+), 74 deletions(-) diff --git a/.gen/objs.txt b/.gen/objs.txt index 06d52203..5a6658cb 100644 --- a/.gen/objs.txt +++ b/.gen/objs.txt @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/.gen/unittest.txt b/.gen/unittest.txt index 2d5b9ed9..3e564128 100644 --- a/.gen/unittest.txt +++ b/.gen/unittest.txt @@ -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 diff --git a/src/openapi/base/all.hpp b/src/openapi/base/all.hpp index 3ebe6b80..bc518cef 100644 --- a/src/openapi/base/all.hpp +++ b/src/openapi/base/all.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include #include #include diff --git a/src/openapi/base/named_traits.hpp b/src/openapi/base/named_traits.hpp index e2bc0d05..63b31b6b 100644 --- a/src/openapi/base/named_traits.hpp +++ b/src/openapi/base/named_traits.hpp @@ -18,55 +18,23 @@ namespace checks template concept HasName = requires { - { - decltype(T::kName)::kSize - } - ->std::convertible_to; - requires std::is_same_v, - std::remove_cv_t>; - { - T::kName - } - ->std::convertible_to>; + {T::kName}; }; -template -concept HasNotName = !HasName; } // namespace checks -namespace details -{ -template -constexpr auto _getName() -{ - return T::kName; -} - -template -constexpr auto _getName() -{ - using Type = utils::ConstexprString<1>; - return Type{""}; -} -} // namespace details - -struct ConstexprSetString -{ - std::array test; -}; - -consteval ConstexprSetString foo() -{ - return {}; -} - namespace traits { // returns ConstexprString template constexpr auto GetName() { - return details::_getName(); + if constexpr (checks::HasName) + { + return T::kName; + } + else + return utils::kEmptyString; } template diff --git a/src/openapi/doc/all.hpp b/src/openapi/doc/all.hpp index e034f891..b23f4b42 100644 --- a/src/openapi/doc/all.hpp +++ b/src/openapi/doc/all.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openapi/doc/reflective.hpp b/src/openapi/doc/reflective.hpp index a494018f..4e044b2d 100644 --- a/src/openapi/doc/reflective.hpp +++ b/src/openapi/doc/reflective.hpp @@ -37,11 +37,10 @@ inline void AppendField(DocHelper, std::type_identity) template requires checks::is_reflective_v void Append(DocHelper doc_helper, - std::type_identity, - bool append_cur_place = true) + std::type_identity) { std::string name_type = GetOpenApiTypeName(); - if (append_cur_place) + if (&doc_helper.cur_place != &doc_helper.root) { PlaceRefToType(doc_helper.cur_place); } @@ -66,7 +65,7 @@ template requires checks::is_reflective_v void Append(Doc& doc, std::type_identity) { auto& root = doc.value_; - Append(DocHelper{root, root}, std::type_identity{}, false); + Append(DocHelper{root, root}, std::type_identity{}); } } // namespace openapi diff --git a/src/openapi/json/parse/all.hpp b/src/openapi/json/parse/all.hpp index 0c4d5e0d..24d8e841 100644 --- a/src/openapi/json/parse/all.hpp +++ b/src/openapi/json/parse/all.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openapi/json/serialize/all.hpp b/src/openapi/json/serialize/all.hpp index 85fc482b..84fd71b4 100644 --- a/src/openapi/json/serialize/all.hpp +++ b/src/openapi/json/serialize/all.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openapi/json/serialize/datetime_property.hpp b/src/openapi/json/serialize/datetime_property.hpp index b67bcaea..3c3eb2a0 100644 --- a/src/openapi/json/serialize/datetime_property.hpp +++ b/src/openapi/json/serialize/datetime_property.hpp @@ -1,24 +1,20 @@ #pragma once -#include +#include #include #include #include namespace openapi { -template +template userver::formats::json::Value Serialize( - const DateTimeProperty& item, - userver::formats::serialize::To) + const T& item, + userver::formats::serialize::To< + userver::formats::json::Value>) requires HasIntrospector { - 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 diff --git a/src/utils/constexpr_string.hpp b/src/utils/constexpr_string.hpp index 18627026..a401cf46 100644 --- a/src/utils/constexpr_string.hpp +++ b/src/utils/constexpr_string.hpp @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include namespace utils @@ -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 @@ -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(); diff --git a/src/utils/shared_transaction.hpp b/src/utils/shared_transaction.hpp index c738d949..39cd16c9 100644 --- a/src/utils/shared_transaction.hpp +++ b/src/utils/shared_transaction.hpp @@ -1,7 +1,9 @@ #pragma once #include +#include #include #include +#include #include #include #include @@ -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(); } } diff --git a/third_party/userver b/third_party/userver index 60bb041f..e682d58e 160000 --- a/third_party/userver +++ b/third_party/userver @@ -1 +1 @@ -Subproject commit 60bb041fd12f4b163a7a74903c524c432ff5b1a8 +Subproject commit e682d58e0d046db7ce4043e4ad2aa875fb0876b6 diff --git a/utests/openapi/doc/serialize/basic.cpp b/utests/openapi/doc/serialize/basic.cpp index 98dda1ee..d5363ea8 100644 --- a/utests/openapi/doc/serialize/basic.cpp +++ b/utests/openapi/doc/serialize/basic.cpp @@ -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{}); @@ -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>{}); diff --git a/utests/openapi/doc/serialize/basic_path.cpp b/utests/openapi/doc/serialize/basic_path.cpp index 1d3f4e68..44599ebb 100644 --- a/utests/openapi/doc/serialize/basic_path.cpp +++ b/utests/openapi/doc/serialize/basic_path.cpp @@ -33,7 +33,7 @@ struct SomeResponse }; } // namespace tests_path -UTEST(Openapi_Doc_Serialize, BasicPath) +UTEST(Openapi_Doc, BasicPath) { Doc doc; std::string path = "/login"; diff --git a/utests/openapi/doc/serialize/basic_request.cpp b/utests/openapi/doc/serialize/basic_request.cpp index 4c557f2e..aa7472d7 100644 --- a/utests/openapi/doc/serialize/basic_request.cpp +++ b/utests/openapi/doc/serialize/basic_request.cpp @@ -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()]; diff --git a/utests/openapi/doc/serialize/basic_response.cpp b/utests/openapi/doc/serialize/basic_response.cpp index b42c4b6d..2f5931b6 100644 --- a/utests/openapi/doc/serialize/basic_response.cpp +++ b/utests/openapi/doc/serialize/basic_response.cpp @@ -25,7 +25,7 @@ struct SomeResponse }; } // namespace tests -UTEST(Openapi_Doc_Serialize, BasicResponse) +UTEST(Openapi_Doc, BasicResponse) { Doc doc; AppendResponse(doc, std::type_identity{}); diff --git a/utests/openapi/http/basic_http_request.cpp b/utests/openapi/http/basic_http_request.cpp index fdfbaf75..e0bb3346 100644 --- a/utests/openapi/http/basic_http_request.cpp +++ b/utests/openapi/http/basic_http_request.cpp @@ -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); } diff --git a/utests/openapi/json/parse/basic_array.cpp b/utests/openapi/json/parse/basic_array.cpp index 3bd472c3..dff7282b 100644 --- a/utests/openapi/json/parse/basic_array.cpp +++ b/utests/openapi/json/parse/basic_array.cpp @@ -12,6 +12,8 @@ #include using namespace openapi; +using namespace openapi::types; +using namespace openapi::preferences; UTEST(Openapi_Json_Parse, BasicArrayProperty) { @@ -43,10 +45,10 @@ UTEST(Openapi_Json_Parse, BasicArrayPropertyMin) UTEST(Openapi_Json_Parse, BasicArrayPropertyMax) { - using Type = types::Array, preferences::Min<1>>; + using Type = Array, Min<1>, UniqueItems>; constexpr auto jsonString = R"( { - "test" : [1,2,2] + "test" : [1,2,3] } )"; auto json = userver::formats::json::FromString(jsonString);