From 97aecbe53b6f610db1ea709ca673d02f1b01a9c4 Mon Sep 17 00:00:00 2001 From: sabudilovskiy Date: Tue, 17 Oct 2023 14:26:12 +0000 Subject: [PATCH] - --- .gen/objs.txt | 10 ++ .gen/unittest.txt | 4 + service/main.cpp | 2 +- .../controllers/postgres/admin/controller.cpp | 3 +- .../postgres/teacher/controller.cpp | 3 +- .../controllers/postgres/user/controller.cpp | 5 +- src/legacy/models/register_request/type.hpp | 3 +- src/legacy/views/admin/create/view.cpp | 2 +- src/legacy/views/admin/list/view.cpp | 2 +- src/legacy/views/faculty/list/view.cpp | 2 +- src/legacy/views/group-stage/list/view.cpp | 2 +- src/legacy/views/login/view.cpp | 2 +- src/legacy/views/register/view.cpp | 6 +- src/legacy/views/teacher/create/view.cpp | 2 +- src/legacy/views/teacher/list/view.cpp | 2 +- .../teacher/request/approve/link/view.cpp | 2 +- .../teacher/request/approve/new/view.cpp | 2 +- .../views/teacher/request/list/view.cpp | 2 +- src/legacy/views/timetable/get/Responses.hpp | 5 +- src/legacy/views/timetable/get/view.cpp | 2 +- src/openapi/as_tuple/reflective.hpp | 5 +- src/openapi/base/all.hpp | 3 + src/openapi/base/object_property.hpp | 10 +- src/openapi/base/property_base.hpp | 4 +- src/openapi/base/reflective_checks.hpp | 22 +++-- src/openapi/base/reflective_preferences.hpp | 20 ++-- src/openapi/base/reflective_utils.hpp | 18 ++-- src/openapi/doc/serialize/all.hpp | 1 + src/openapi/doc/serialize/base.hpp | 16 +-- src/openapi/doc/serialize/reflective.hpp | 11 ++- src/openapi/doc/serialize/request.hpp | 5 +- src/openapi/doc/serialize/response.hpp | 5 +- src/openapi/from_tuple/reflective.hpp | 4 +- src/openapi/http/base/response.hpp | 5 +- src/openapi/http/parse/request.hpp | 5 +- src/openapi/http/serialize/response.hpp | 7 +- src/openapi/json/parse/all.hpp | 1 + src/openapi/json/parse/reflective.hpp | 5 +- src/openapi/json/serialize/all.hpp | 1 + src/openapi/json/serialize/array_property.hpp | 7 +- src/openapi/json/serialize/reflective.hpp | 17 ++-- src/openapi/postgres/mapping.hpp | 97 ++++++++++--------- src/openapi/to_tuple/reflective.hpp | 4 +- src/openapi/types/all.hpp | 1 + src/views/test-openapi-view/declarations.hpp | 2 +- src/views/test-openapi-view/view.cpp | 2 +- .../openapi/doc/serialize/basic_request.cpp | 1 - 47 files changed, 195 insertions(+), 147 deletions(-) diff --git a/.gen/objs.txt b/.gen/objs.txt index c89a27a2..70a8c07e 100644 --- a/.gen/objs.txt +++ b/.gen/objs.txt @@ -4,6 +4,8 @@ src/views/test-openapi-view/declarations.hpp src/utils/type_holder.hpp src/utils/tests_macros.hpp src/utils/shared_transaction.hpp +src/utils/serialize/uuid/string.hpp +src/utils/serialize/uuid/string.cpp src/utils/postgres_helper.hpp src/utils/perform_common_errors.hpp src/utils/perform_common_errors.cpp @@ -32,6 +34,7 @@ src/utils/constexpr_optional.hpp src/utils/component_list_fwd.hpp src/utils/compilers_macros.hpp src/utils/common_errors.hpp +src/openapi/types/uuid_type.hpp src/openapi/types/string_type.hpp src/openapi/types/optional_type.hpp src/openapi/types/object_type.hpp @@ -48,12 +51,14 @@ 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/base_property.hpp src/openapi/json/serialize/array_property.hpp src/openapi/json/serialize/all.hpp 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/base_property.hpp src/openapi/json/parse/array_property.hpp src/openapi/json/parse/all.hpp src/openapi/json/all.hpp @@ -83,6 +88,7 @@ src/openapi/from_tuple/property.hpp src/openapi/from_tuple/optional.hpp src/openapi/from_tuple/default.hpp src/openapi/from_tuple/all.hpp +src/openapi/doc/serialize/uuid.hpp src/openapi/doc/serialize/response.hpp src/openapi/doc/serialize/request.hpp src/openapi/doc/serialize/remove_requests.hpp @@ -94,8 +100,11 @@ src/openapi/doc/serialize/body.hpp src/openapi/doc/serialize/base.hpp src/openapi/doc/serialize/array.hpp src/openapi/doc/serialize/all.hpp +src/openapi/base/uuid_traits.hpp +src/openapi/base/uuid_property.hpp src/openapi/base/string_traits.hpp src/openapi/base/string_property.hpp +src/openapi/base/reflective_uuid_fix.hpp src/openapi/base/reflective_utils.hpp src/openapi/base/reflective_preferences.hpp src/openapi/base/reflective_checks.hpp @@ -108,6 +117,7 @@ src/openapi/base/object_property.hpp src/openapi/base/object_field_names.hpp src/openapi/base/named_traits.hpp src/openapi/base/is_optional_property.hpp +src/openapi/base/holder.hpp src/openapi/base/doc.hpp src/openapi/base/array_traits.hpp src/openapi/base/array_property.hpp diff --git a/.gen/unittest.txt b/.gen/unittest.txt index 28f25ed6..f7c1baa8 100644 --- a/.gen/unittest.txt +++ b/.gen/unittest.txt @@ -2,13 +2,17 @@ utests/remove_namespace.cpp utests/openapi/raw/to_tuple.cpp utests/openapi/raw/from_tuple.cpp utests/openapi/raw/as_tuple.cpp +utests/openapi/json/serialize/uuid.cpp utests/openapi/json/serialize/basic_string.cpp utests/openapi/json/serialize/basic_optional.cpp utests/openapi/json/serialize/basic_object.cpp utests/openapi/json/serialize/basic_array.cpp +utests/openapi/json/parse/uuid.cpp utests/openapi/json/parse/basic_string.cpp utests/openapi/json/parse/basic_object.cpp utests/openapi/json/parse/basic_array.cpp +utests/openapi/http/uuid_response.cpp +utests/openapi/http/uuid_request.cpp utests/openapi/http/basic_http_response.cpp utests/openapi/http/basic_http_request.cpp utests/openapi/doc/serialize/basic_response.cpp diff --git a/service/main.cpp b/service/main.cpp index eacc309f..a96842ef 100644 --- a/service/main.cpp +++ b/service/main.cpp @@ -30,8 +30,8 @@ #include "legacy/views/teacher/request/approve/link/view.hpp" #include "legacy/views/teacher/request/approve/new/view.hpp" #include "legacy/views/teacher/request/list/view.hpp" -#include "views/test-openapi-view/view.hpp" #include "legacy/views/timetable/get/view.hpp" +#include "views/test-openapi-view/view.hpp" void AppendPgControllers(userver::components::ComponentList& component_list) { diff --git a/src/legacy/components/controllers/postgres/admin/controller.cpp b/src/legacy/components/controllers/postgres/admin/controller.cpp index 37f82ee5..e3008409 100644 --- a/src/legacy/components/controllers/postgres/admin/controller.cpp +++ b/src/legacy/components/controllers/postgres/admin/controller.cpp @@ -76,7 +76,8 @@ std::vector Controller::GetByFilter( ::utils::FillSharedTransaction(transaction, pg_cluster_); auto pg_result = utils::PgExecute(transaction, sql::qGetAdminsByFilter, filter); - return utils::ConvertPgResultToArray(pg_result); + return utils::ConvertPgResultToArray( + pg_result); } } // namespace legacy::components::controllers::postgres::admin diff --git a/src/legacy/components/controllers/postgres/teacher/controller.cpp b/src/legacy/components/controllers/postgres/teacher/controller.cpp index ba2f4950..a8f03dc3 100644 --- a/src/legacy/components/controllers/postgres/teacher/controller.cpp +++ b/src/legacy/components/controllers/postgres/teacher/controller.cpp @@ -136,7 +136,8 @@ std::vector Controller::GetAllRequests( { utils::FillSharedTransaction(transaction, pg_cluster_); auto pg_result = utils::PgExecute(transaction, sql::qGetAllRequests); - return utils::ConvertPgResultToArray(pg_result); + return utils::ConvertPgResultToArray( + pg_result); } std::optional Controller::DropRequest( diff --git a/src/legacy/components/controllers/postgres/user/controller.cpp b/src/legacy/components/controllers/postgres/user/controller.cpp index 21d66088..f66cfcb7 100644 --- a/src/legacy/components/controllers/postgres/user/controller.cpp +++ b/src/legacy/components/controllers/postgres/user/controller.cpp @@ -21,8 +21,8 @@ #include #include -#include "legacy/components/controllers/postgres/user/sql_queries.hpp" #include "config_schema.hpp" +#include "legacy/components/controllers/postgres/user/sql_queries.hpp" #include "legacy/models/user/postgre.hpp" #include "legacy/models/user/type.hpp" #include "legacy/models/user_credentials/postgre.hpp" @@ -59,7 +59,8 @@ utils::SharedTransaction Controller::CreateTransaction() } void Controller::InternalForceCreateUser( - const boost::uuids::uuid&, const legacy::models::UserCredentials& user_credentials, + const boost::uuids::uuid&, + const legacy::models::UserCredentials& user_credentials, utils::SharedTransaction transaction) { utils::FillSharedTransaction(transaction, pg_cluster_); diff --git a/src/legacy/models/register_request/type.hpp b/src/legacy/models/register_request/type.hpp index 03107128..d254f1ef 100644 --- a/src/legacy/models/register_request/type.hpp +++ b/src/legacy/models/register_request/type.hpp @@ -11,7 +11,8 @@ namespace legacy::models using namespace utils::convert; struct RegisterRequest { - Property user_credentials; + Property + user_credentials; OptionalProperty description; OptionalProperty desired_type; static constexpr TypeOfBody kTypeOfBody = diff --git a/src/legacy/views/admin/create/view.cpp b/src/legacy/views/admin/create/view.cpp index 5c44a73c..a8a72d71 100644 --- a/src/legacy/views/admin/create/view.cpp +++ b/src/legacy/views/admin/create/view.cpp @@ -11,9 +11,9 @@ #include "Request.hpp" #include "Responses.hpp" +#include "http/handler_parsed.hpp" #include "legacy/components/controllers/postgres/admin/controller.hpp" #include "legacy/components/controllers/postgres/user/controller.hpp" -#include "http/handler_parsed.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" #include "legacy/models/user_type/serialize.hpp" diff --git a/src/legacy/views/admin/list/view.cpp b/src/legacy/views/admin/list/view.cpp index 093878fe..7cd6181d 100644 --- a/src/legacy/views/admin/list/view.cpp +++ b/src/legacy/views/admin/list/view.cpp @@ -13,9 +13,9 @@ #include "Request.hpp" #include "Responses.hpp" +#include "http/handler_parsed.hpp" #include "legacy/components/controllers/postgres/admin/controller.hpp" #include "legacy/components/controllers/postgres/user/controller.hpp" -#include "http/handler_parsed.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" #include "legacy/models/user_type/serialize.hpp" diff --git a/src/legacy/views/faculty/list/view.cpp b/src/legacy/views/faculty/list/view.cpp index f02df830..7d845cde 100644 --- a/src/legacy/views/faculty/list/view.cpp +++ b/src/legacy/views/faculty/list/view.cpp @@ -13,8 +13,8 @@ #include "Request.hpp" #include "Responses.hpp" -#include "legacy/components/controllers/postgres/faculty/controller.hpp" #include "http/handler_parsed.hpp" +#include "legacy/components/controllers/postgres/faculty/controller.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" #include "legacy/models/user_type/serialize.hpp" diff --git a/src/legacy/views/group-stage/list/view.cpp b/src/legacy/views/group-stage/list/view.cpp index e5d45482..4bea6742 100644 --- a/src/legacy/views/group-stage/list/view.cpp +++ b/src/legacy/views/group-stage/list/view.cpp @@ -13,9 +13,9 @@ #include "Request.hpp" #include "Responses.hpp" +#include "http/handler_parsed.hpp" #include "legacy/components/controllers/postgres/faculty/controller.hpp" #include "legacy/components/controllers/postgres/group_stage/controller.hpp" -#include "http/handler_parsed.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/education_type/all.hpp" #include "legacy/models/user/serialize.hpp" diff --git a/src/legacy/views/login/view.cpp b/src/legacy/views/login/view.cpp index 29ad3ab6..85546fc1 100644 --- a/src/legacy/views/login/view.cpp +++ b/src/legacy/views/login/view.cpp @@ -11,9 +11,9 @@ #include "Request.hpp" #include "Responses.hpp" +#include "http/handler_parsed.hpp" #include "legacy/components/controllers/postgres/token/controller.hpp" #include "legacy/components/controllers/postgres/user/controller.hpp" -#include "http/handler_parsed.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" #include "legacy/models/user_type/serialize.hpp" diff --git a/src/legacy/views/register/view.cpp b/src/legacy/views/register/view.cpp index 4acde507..b14fd9d1 100644 --- a/src/legacy/views/register/view.cpp +++ b/src/legacy/views/register/view.cpp @@ -17,9 +17,9 @@ #include #include "Request.hpp" +#include "http/handler_parsed.hpp" #include "legacy/components/controllers/postgres/token/controller.hpp" #include "legacy/components/controllers/postgres/user/controller.hpp" -#include "http/handler_parsed.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" #include "legacy/models/user_type/parse.hpp" @@ -97,8 +97,8 @@ class Handler final HandleDesiredType(transaction, request, user_id.value()); Response200 resp; resp.id() = *id; - resp.user() = - legacy::models::User{.id = {*user_id}, .type = {legacy::models::UserType::kUser}}; + resp.user() = legacy::models::User{ + .id = {*user_id}, .type = {legacy::models::UserType::kUser}}; return resp; } diff --git a/src/legacy/views/teacher/create/view.cpp b/src/legacy/views/teacher/create/view.cpp index 8ceca283..7ff066c4 100644 --- a/src/legacy/views/teacher/create/view.cpp +++ b/src/legacy/views/teacher/create/view.cpp @@ -13,9 +13,9 @@ #include "Request.hpp" #include "Responses.hpp" +#include "http/handler_parsed.hpp" #include "legacy/components/controllers/postgres/teacher/controller.hpp" #include "legacy/components/controllers/postgres/user/controller.hpp" -#include "http/handler_parsed.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" #include "legacy/models/user_type/serialize.hpp" diff --git a/src/legacy/views/teacher/list/view.cpp b/src/legacy/views/teacher/list/view.cpp index fcb8ec68..20a6d16b 100644 --- a/src/legacy/views/teacher/list/view.cpp +++ b/src/legacy/views/teacher/list/view.cpp @@ -13,8 +13,8 @@ #include "Request.hpp" #include "Responses.hpp" -#include "legacy/components/controllers/postgres/teacher/controller.hpp" #include "http/handler_parsed.hpp" +#include "legacy/components/controllers/postgres/teacher/controller.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" #include "legacy/models/user_type/serialize.hpp" diff --git a/src/legacy/views/teacher/request/approve/link/view.cpp b/src/legacy/views/teacher/request/approve/link/view.cpp index e3efc934..cd6366cc 100644 --- a/src/legacy/views/teacher/request/approve/link/view.cpp +++ b/src/legacy/views/teacher/request/approve/link/view.cpp @@ -15,9 +15,9 @@ #include "Request.hpp" #include "Responses.hpp" +#include "http/handler_parsed.hpp" #include "legacy/components/controllers/postgres/teacher/controller.hpp" #include "legacy/components/controllers/postgres/user/controller.hpp" -#include "http/handler_parsed.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" #include "legacy/models/user_type/serialize.hpp" diff --git a/src/legacy/views/teacher/request/approve/new/view.cpp b/src/legacy/views/teacher/request/approve/new/view.cpp index 9e920d72..11b4ecb9 100644 --- a/src/legacy/views/teacher/request/approve/new/view.cpp +++ b/src/legacy/views/teacher/request/approve/new/view.cpp @@ -15,9 +15,9 @@ #include "Request.hpp" #include "Responses.hpp" +#include "http/handler_parsed.hpp" #include "legacy/components/controllers/postgres/teacher/controller.hpp" #include "legacy/components/controllers/postgres/user/controller.hpp" -#include "http/handler_parsed.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" #include "legacy/models/user_type/serialize.hpp" diff --git a/src/legacy/views/teacher/request/list/view.cpp b/src/legacy/views/teacher/request/list/view.cpp index 556eb3e0..51241835 100644 --- a/src/legacy/views/teacher/request/list/view.cpp +++ b/src/legacy/views/teacher/request/list/view.cpp @@ -15,9 +15,9 @@ #include "Request.hpp" #include "Responses.hpp" +#include "http/handler_parsed.hpp" #include "legacy/components/controllers/postgres/teacher/controller.hpp" #include "legacy/components/controllers/postgres/user/controller.hpp" -#include "http/handler_parsed.hpp" #include "legacy/models/auth_token/serialize.hpp" #include "legacy/models/user/serialize.hpp" #include "legacy/models/user_type/serialize.hpp" diff --git a/src/legacy/views/timetable/get/Responses.hpp b/src/legacy/views/timetable/get/Responses.hpp index e506d97e..aaf93fea 100644 --- a/src/legacy/views/timetable/get/Responses.hpp +++ b/src/legacy/views/timetable/get/Responses.hpp @@ -28,7 +28,8 @@ struct Response200 static_assert(userver::formats::common::impl::kHasSerialize< userver::formats::json::Value, legacy::models::LessonV1>); -static_assert(userver::formats::common::impl::kHasSerialize< - userver::formats::json::Value, std::vector>); +static_assert( + userver::formats::common::impl::kHasSerialize< + userver::formats::json::Value, std::vector>); } // namespace legacy::views::timetable::get diff --git a/src/legacy/views/timetable/get/view.cpp b/src/legacy/views/timetable/get/view.cpp index bf79da0d..95222ca6 100644 --- a/src/legacy/views/timetable/get/view.cpp +++ b/src/legacy/views/timetable/get/view.cpp @@ -18,8 +18,8 @@ #include "Request.hpp" #include "Responses.hpp" -#include "legacy/components/controllers/postgres/lesson/controller.hpp" #include "http/handler_parsed.hpp" +#include "legacy/components/controllers/postgres/lesson/controller.hpp" #include "legacy/models/day/all.hpp" #include "legacy/models/education_type/all.hpp" #include "legacy/models/lesson_v1/parse.hpp" diff --git a/src/openapi/as_tuple/reflective.hpp b/src/openapi/as_tuple/reflective.hpp index 714476a0..feae67d9 100644 --- a/src/openapi/as_tuple/reflective.hpp +++ b/src/openapi/as_tuple/reflective.hpp @@ -6,11 +6,10 @@ #include #include #include - namespace openapi::raw { -template -class AsTuple +template +requires checks::is_reflective_v class AsTuple { private: using Type = T; diff --git a/src/openapi/base/all.hpp b/src/openapi/base/all.hpp index c8fac553..432b6156 100644 --- a/src/openapi/base/all.hpp +++ b/src/openapi/base/all.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -13,5 +14,7 @@ #include #include #include +#include #include #include +#include diff --git a/src/openapi/base/object_property.hpp b/src/openapi/base/object_property.hpp index 58b5a843..073da2ee 100644 --- a/src/openapi/base/object_property.hpp +++ b/src/openapi/base/object_property.hpp @@ -7,13 +7,15 @@ namespace openapi { -template -struct ObjectProperty : public PropertyBase +template +requires checks::is_reflective_v struct ObjectProperty + : public PropertyBase { }; -template -struct Property : public ObjectProperty +template +requires checks::is_reflective_v struct Property + : public ObjectProperty { }; diff --git a/src/openapi/base/property_base.hpp b/src/openapi/base/property_base.hpp index 5f038c78..0f880e01 100644 --- a/src/openapi/base/property_base.hpp +++ b/src/openapi/base/property_base.hpp @@ -28,8 +28,8 @@ struct PropertyBase { } - auto operator<=>(const PropertyBase& r) const = default; - auto operator<=>(const T& r) const + auto operator<=>(const PropertyBase& r) const = default; + auto operator<=>(const value_type& r) const { return value <=> r; } diff --git a/src/openapi/base/reflective_checks.hpp b/src/openapi/base/reflective_checks.hpp index 05d05bad..c1e72272 100644 --- a/src/openapi/base/reflective_checks.hpp +++ b/src/openapi/base/reflective_checks.hpp @@ -15,19 +15,25 @@ concept IsReflectiveHelper = requires }; template -concept IsReflective = requires -{ - requires std::is_class_v; - requires std::is_aggregate_v; +concept IsReflective = + std::is_class_v&& std::is_aggregate_v && !IsProperty; - requires !IsProperty; -}; +template +constexpr bool is_reflective_v = IsReflective; + +template +concept IsReflectiveProperty = + IsProperty&& IsReflective; + +template +constexpr bool is_reflective_property_v = IsReflectiveProperty; template -concept IsReflectiveProperty = IsProperty && IsReflective; +concept IsNotReflectiveProperty = + IsProperty && !IsReflective; template -concept IsNotReflectiveProperty = IsProperty && !IsReflective; +constexpr bool is_not_reflective_property_v = IsNotReflectiveProperty; } // namespace checks } // namespace openapi diff --git a/src/openapi/base/reflective_preferences.hpp b/src/openapi/base/reflective_preferences.hpp index 27af37ba..53a2cedb 100644 --- a/src/openapi/base/reflective_preferences.hpp +++ b/src/openapi/base/reflective_preferences.hpp @@ -67,17 +67,18 @@ consteval void resolve_fields(ReflectivePreferencesHelper& helper, (apply(helper), ...); } -template -consteval void resolve_tuple(ReflectivePreferencesHelper& helper, - std::integer_sequence) +template +requires checks::is_reflective_v consteval void resolve_tuple( + ReflectivePreferencesHelper& helper, std::integer_sequence) { using Tuple = std::tuple>...>; resolve_fields(helper, std::type_identity{}); } -template -consteval ReflectivePreferencesHelper resolve_helper() +template +requires checks::is_reflective_v consteval ReflectivePreferencesHelper +resolve_helper() { ReflectivePreferencesHelper helper{}; constexpr size_t size = boost::pfr::tuple_size_v; @@ -86,8 +87,9 @@ consteval ReflectivePreferencesHelper resolve_helper() return helper; } -template -AdditionalPropertiesStatus consteval resolve_additional_properties_status() +template +requires checks::is_reflective_v + AdditionalPropertiesStatus consteval resolve_additional_properties_status() { constexpr ReflectivePreferencesHelper helper = resolve_helper(); if constexpr (helper.counter_additional_properties == 0) @@ -104,8 +106,8 @@ AdditionalPropertiesStatus consteval resolve_additional_properties_status() } } } // namespace impl -template -struct ReflectivePreferences +template +requires checks::is_reflective_v struct ReflectivePreferences { static constexpr AdditionalPropertiesStatus additional_properties_status = impl::resolve_additional_properties_status(); diff --git a/src/openapi/base/reflective_utils.hpp b/src/openapi/base/reflective_utils.hpp index 23f92dbf..9f454069 100644 --- a/src/openapi/base/reflective_utils.hpp +++ b/src/openapi/base/reflective_utils.hpp @@ -12,17 +12,17 @@ namespace openapi { namespace impl { -template -auto MakeTypeTupleHelper(std::type_identity, - std::integer_sequence) +template +requires checks::is_reflective_v auto MakeTypeTupleHelper( + std::type_identity, std::integer_sequence) { using Type = std::tuple>...>; return std::type_identity{}; } } // namespace impl -template -auto MakeSequence() +template +requires checks::is_reflective_v auto MakeSequence() { return std::make_index_sequence::value>(); } @@ -32,8 +32,8 @@ auto MakeSequence() Используйте для быстрого разбинда рефлективных структур в вариадик пак */ -template -auto MakeTypeTuple() +template +requires checks::is_reflective_v auto MakeTypeTuple() { auto seq = MakeSequence(); return impl::MakeTypeTupleHelper(std::type_identity{}, seq); @@ -56,8 +56,8 @@ void CallAllFields(Callable&& callable, Callable должна принимать std::type_identity */ -template -void CallAllFields(Callable&& callable) +template +requires checks::is_reflective_v void CallAllFields(Callable&& callable) { auto tuple_identity = MakeTypeTuple(); impl::CallAllFields(std::forward(callable), tuple_identity); diff --git a/src/openapi/doc/serialize/all.hpp b/src/openapi/doc/serialize/all.hpp index 4c892bac..70955de4 100644 --- a/src/openapi/doc/serialize/all.hpp +++ b/src/openapi/doc/serialize/all.hpp @@ -10,3 +10,4 @@ #include #include #include +#include diff --git a/src/openapi/doc/serialize/base.hpp b/src/openapi/doc/serialize/base.hpp index 11bfc0fc..72b28c8d 100644 --- a/src/openapi/doc/serialize/base.hpp +++ b/src/openapi/doc/serialize/base.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -97,8 +96,9 @@ std::string GetRawTypeName() return raw_name; } -template -void PlaceRefToType(userver::formats::yaml::ValueBuilder& place) +template +requires checks::is_reflective_v void PlaceRefToType( + userver::formats::yaml::ValueBuilder& place) { if (!place.IsObject()) { @@ -109,8 +109,9 @@ void PlaceRefToType(userver::formats::yaml::ValueBuilder& place) place["$ref"] = std::move(ref_str); } -template -void PlaceRefToResponse(userver::formats::yaml::ValueBuilder& place) +template +requires checks::is_reflective_v void PlaceRefToResponse( + userver::formats::yaml::ValueBuilder& place) { if (!place.IsObject()) { @@ -121,8 +122,9 @@ void PlaceRefToResponse(userver::formats::yaml::ValueBuilder& place) place["$ref"] = std::move(ref_str); } -template -void PlaceRefToRequest(userver::formats::yaml::ValueBuilder& place) +template +requires checks::is_reflective_v void PlaceRefToRequest( + userver::formats::yaml::ValueBuilder& place) { if (!place.IsObject()) { diff --git a/src/openapi/doc/serialize/reflective.hpp b/src/openapi/doc/serialize/reflective.hpp index 1a73e8aa..d73158e2 100644 --- a/src/openapi/doc/serialize/reflective.hpp +++ b/src/openapi/doc/serialize/reflective.hpp @@ -33,9 +33,10 @@ inline void AppendField(DocHelper, std::type_identity) { } -template -void Append(DocHelper doc_helper, std::type_identity, - bool append_cur_place = true) +template +requires checks::is_reflective_v void Append(DocHelper doc_helper, + std::type_identity, + bool append_cur_place = true) { std::string name_type = GetOpenApiTypeName(); if (append_cur_place) @@ -59,8 +60,8 @@ void Append(DocHelper doc_helper, std::type_identity, } } -template -void Append(Doc& doc, std::type_identity) +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); diff --git a/src/openapi/doc/serialize/request.hpp b/src/openapi/doc/serialize/request.hpp index 55493c51..87573db2 100644 --- a/src/openapi/doc/serialize/request.hpp +++ b/src/openapi/doc/serialize/request.hpp @@ -11,8 +11,9 @@ namespace openapi { -template -void AppendRequest(DocHelper doc_helper, std::type_identity) +template +requires checks::is_reflective_v void AppendRequest(DocHelper doc_helper, + std::type_identity) { auto& [root, cur] = doc_helper; if (cur.IsObject()) diff --git a/src/openapi/doc/serialize/response.hpp b/src/openapi/doc/serialize/response.hpp index 064f5f2e..30d30652 100644 --- a/src/openapi/doc/serialize/response.hpp +++ b/src/openapi/doc/serialize/response.hpp @@ -11,8 +11,9 @@ namespace openapi { -template -void AppendResponse(Doc& doc, std::type_identity) +template +requires checks::is_reflective_v void AppendResponse(Doc& doc, + std::type_identity) { auto& root = doc.value_; userver::formats::yaml::ValueBuilder response = diff --git a/src/openapi/from_tuple/reflective.hpp b/src/openapi/from_tuple/reflective.hpp index 93991b33..60aad5e8 100644 --- a/src/openapi/from_tuple/reflective.hpp +++ b/src/openapi/from_tuple/reflective.hpp @@ -9,8 +9,8 @@ namespace openapi::raw { -template -class FromTuple +template +requires checks::is_reflective_v class FromTuple { public: using Src = to_tuple_t; diff --git a/src/openapi/http/base/response.hpp b/src/openapi/http/base/response.hpp index e419b74f..6c2768f9 100644 --- a/src/openapi/http/base/response.hpp +++ b/src/openapi/http/base/response.hpp @@ -7,6 +7,7 @@ namespace openapi::http { -template -using Resp = ResponseProperty>; +template +requires checks::is_reflective_v using Resp = + ResponseProperty>; } diff --git a/src/openapi/http/parse/request.hpp b/src/openapi/http/parse/request.hpp index d7760598..4d630811 100644 --- a/src/openapi/http/parse/request.hpp +++ b/src/openapi/http/parse/request.hpp @@ -18,8 +18,9 @@ namespace openapi::http { -template -T Parse(const RequestInfo& info, userver::formats::parse::To) +template +requires checks::is_reflective_v T Parse(const RequestInfo& info, + userver::formats::parse::To) { T t; auto matcher_header = [&]( diff --git a/src/openapi/http/serialize/response.hpp b/src/openapi/http/serialize/response.hpp index 843f5616..9ddf9a30 100644 --- a/src/openapi/http/serialize/response.hpp +++ b/src/openapi/http/serialize/response.hpp @@ -21,9 +21,10 @@ namespace openapi::http { -template -ResponseInfo Serialize(const ResponseProperty& item, - userver::formats::serialize::To) +template +requires checks::is_reflective_v ResponseInfo +Serialize(const ResponseProperty& item, + userver::formats::serialize::To) { ResponseInfo result{}; result.userver_code = Traits::code; diff --git a/src/openapi/json/parse/all.hpp b/src/openapi/json/parse/all.hpp index 3daf0f22..22b49eac 100644 --- a/src/openapi/json/parse/all.hpp +++ b/src/openapi/json/parse/all.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include #include #include diff --git a/src/openapi/json/parse/reflective.hpp b/src/openapi/json/parse/reflective.hpp index fdc775f0..244b5202 100644 --- a/src/openapi/json/parse/reflective.hpp +++ b/src/openapi/json/parse/reflective.hpp @@ -82,8 +82,9 @@ void parse_additional_properties( namespace userver::formats::parse { -template <::openapi::checks::IsReflective T> -T Parse(const json::Value& item, To) +template +requires openapi::checks::is_reflective_v T Parse(const json::Value& item, + To) { using namespace openapi; T result; diff --git a/src/openapi/json/serialize/all.hpp b/src/openapi/json/serialize/all.hpp index 3d4a7e2d..bda8a7a0 100644 --- a/src/openapi/json/serialize/all.hpp +++ b/src/openapi/json/serialize/all.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include diff --git a/src/openapi/json/serialize/array_property.hpp b/src/openapi/json/serialize/array_property.hpp index e1e29d6b..e84bd9b6 100644 --- a/src/openapi/json/serialize/array_property.hpp +++ b/src/openapi/json/serialize/array_property.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -63,10 +64,6 @@ userver::formats::json::Value Serialize( index++; } } - for (auto& elem : serialized_value) - { - result.PushBack(elem); - } - return result.ExtractValue(); + return userver::formats::json::ValueBuilder{item()}.ExtractValue(); } } // namespace openapi diff --git a/src/openapi/json/serialize/reflective.hpp b/src/openapi/json/serialize/reflective.hpp index f93be4ff..9c93d230 100644 --- a/src/openapi/json/serialize/reflective.hpp +++ b/src/openapi/json/serialize/reflective.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -20,8 +21,8 @@ namespace openapi::detail { -template -inline void serialize_without_additional( +template +requires checks::is_reflective_v inline void serialize_without_additional( const T& item, userver::formats::json::ValueBuilder& result) { auto matcher_common = [&result](const F& field) { @@ -36,9 +37,9 @@ inline void serialize_without_additional( boost::pfr::for_each_field(item, std::move(matcher_all)); } -template -inline void serialize_additional(const T& item, - userver::formats::json::ValueBuilder& result) +template +requires checks::is_reflective_v inline void serialize_additional( + const T& item, userver::formats::json::ValueBuilder& result) { // noop auto matcher_common = [](const F&) {}; @@ -62,9 +63,9 @@ inline void serialize_additional(const T& item, namespace userver::formats::serialize { -template <::openapi::checks::IsReflective T> -userver::formats::json::Value Serialize(const T& item, - To) +template +requires openapi::checks::is_reflective_v userver::formats::json::Value +Serialize(const T& item, To) { using namespace openapi; userver::formats::json::ValueBuilder result{ diff --git a/src/openapi/postgres/mapping.hpp b/src/openapi/postgres/mapping.hpp index 0d6b0359..0b12484d 100644 --- a/src/openapi/postgres/mapping.hpp +++ b/src/openapi/postgres/mapping.hpp @@ -2,84 +2,91 @@ #include #include +#include #include #include -#include namespace userver::storages::postgres::io { - -namespace detail{ - +namespace detail +{ template -struct OpenapiPropertyFormatter : BufferFormatterBase { - using Inner = typename T::value_type; - using BaseType = BufferFormatterBase; - using ValueFormatter = typename traits::IO::FormatterType; +struct OpenapiPropertyFormatter : BufferFormatterBase +{ + using Inner = typename T::value_type; + using BaseType = BufferFormatterBase; + using ValueFormatter = typename traits::IO::FormatterType; - using BaseType::BaseType; + using BaseType::BaseType; - template - void operator()(const UserTypes& types, Buffer& buffer) const { - ValueFormatter{this->value()}(types, buffer); - } + template + void operator()(const UserTypes& types, Buffer& buffer) const + { + ValueFormatter{this->value()}(types, buffer); + } }; template -struct OpenapiPropertyParser : BufferParserBase { - using BaseType = BufferParserBase; - using Inner = typename T::value_type; - using ValueParser = typename traits::IO::ParserType; +struct OpenapiPropertyParser : BufferParserBase +{ + using BaseType = BufferParserBase; + using Inner = typename T::value_type; + using ValueParser = typename traits::IO::ParserType; - using BaseType::BaseType; + using BaseType::BaseType; - void operator()(const FieldBuffer& buffer) { - Inner val; - ValueParser{val}(buffer); - this->value() = std::move(val); - } + void operator()(const FieldBuffer& buffer) + { + Inner val; + ValueParser{val}(buffer); + this->value() = std::move(val); + } }; -} +} // namespace detail /* Formatter specialization for openapi::Property */ template -struct BufferFormatter>> - : detail::OpenapiPropertyFormatter { - using BaseType = detail::OpenapiPropertyFormatter; - using BaseType::BaseType; +struct BufferFormatter< + T, std::enable_if_t>> + : detail::OpenapiPropertyFormatter +{ + using BaseType = detail::OpenapiPropertyFormatter; + using BaseType::BaseType; }; /* Parser specialization for openapi::Property */ template -struct BufferParser>> - : detail::OpenapiPropertyParser { - using BaseType = detail::OpenapiPropertyParser; - using BaseType::BaseType; +struct BufferParser< + T, std::enable_if_t>> + : detail::OpenapiPropertyParser +{ + using BaseType = detail::OpenapiPropertyParser; + using BaseType::BaseType; }; -template -struct CppToUserPg +template +requires openapi::checks::is_reflective_property_v struct CppToUserPg { - private: + private: using Inner = typename T::value_type; - public: + + public: static constexpr DBTypeName postgres_name = - CppToUserPg::postgres_name; + CppToUserPg::postgres_name; }; -template -struct CppToSystemPg +template +requires openapi::checks::is_not_reflective_property_v struct CppToSystemPg< + T> { - private: + private: using Inner = typename T::value_type; - public: - static constexpr auto value = - CppToSystemPg::value; -}; + public: + static constexpr auto value = CppToSystemPg::value; +}; } // namespace userver::storages::postgres::io diff --git a/src/openapi/to_tuple/reflective.hpp b/src/openapi/to_tuple/reflective.hpp index f37f38d5..cbeb2019 100644 --- a/src/openapi/to_tuple/reflective.hpp +++ b/src/openapi/to_tuple/reflective.hpp @@ -9,8 +9,8 @@ namespace openapi::raw { -template -class ToTuple +template +requires checks::is_reflective_v class ToTuple { private: using Type = T; diff --git a/src/openapi/types/all.hpp b/src/openapi/types/all.hpp index 2bdbc611..eef72e69 100644 --- a/src/openapi/types/all.hpp +++ b/src/openapi/types/all.hpp @@ -4,3 +4,4 @@ #include #include #include +#include diff --git a/src/views/test-openapi-view/declarations.hpp b/src/views/test-openapi-view/declarations.hpp index d46f0ca4..55559092 100644 --- a/src/views/test-openapi-view/declarations.hpp +++ b/src/views/test-openapi-view/declarations.hpp @@ -35,4 +35,4 @@ struct Response auto operator<=>(const Response&) const = default; }; -} // namespace legacy::views::test::login +} // namespace views::test::login diff --git a/src/views/test-openapi-view/view.cpp b/src/views/test-openapi-view/view.cpp index 0644fc58..6e9de4f7 100644 --- a/src/views/test-openapi-view/view.cpp +++ b/src/views/test-openapi-view/view.cpp @@ -40,4 +40,4 @@ void Append(userver::components::ComponentList& component_list) component_list.Append(); } -} // namespace legacy::views::test::login +} // namespace views::test::login diff --git a/utests/openapi/doc/serialize/basic_request.cpp b/utests/openapi/doc/serialize/basic_request.cpp index 593178aa..c99df0a0 100644 --- a/utests/openapi/doc/serialize/basic_request.cpp +++ b/utests/openapi/doc/serialize/basic_request.cpp @@ -8,7 +8,6 @@ #include #include - using namespace openapi; using namespace types; using namespace preferences;