From 1b7ddcdf2e971893f7c3f8d59df74725bfa1ff53 Mon Sep 17 00:00:00 2001 From: sabudilovskiy Date: Thu, 12 Oct 2023 13:19:17 +0000 Subject: [PATCH] - --- service/main.cpp | 1 - .../controllers/postgres/admin/controller.cpp | 9 +- .../postgres/faculty/controller.cpp | 2 +- .../postgres/faculty/controller.hpp | 2 +- .../controllers/postgres/faculty/fwd.cpp | 2 +- .../controllers/postgres/faculty/fwd.hpp | 2 +- .../postgres/group_stage/controller.cpp | 2 +- .../postgres/group_stage/controller.hpp | 2 +- .../controllers/postgres/group_stage/fwd.cpp | 2 +- .../controllers/postgres/group_stage/fwd.hpp | 2 +- .../postgres/group_stage/sql_queries.hpp | 3 +- .../postgres/lesson/controller.cpp | 3 +- .../postgres/lesson/controller.hpp | 3 +- .../postgres/teacher/controller.cpp | 5 +- .../postgres/teacher/controller.hpp | 23 ++--- .../controllers/postgres/teacher/fwd.cpp | 2 +- .../controllers/postgres/user/controller.hpp | 1 + src/models/admin_account/postgre.hpp | 3 +- src/models/admin_filter/postgre.hpp | 3 +- src/models/faculty/postgre.hpp | 4 +- src/models/faculty_filter/postgre.hpp | 3 +- src/models/group_stage/postgre.hpp | 3 +- src/models/group_stage_filter/postgre.hpp | 3 +- src/models/lesson_filter/postgre.hpp | 3 +- src/models/lesson_v1/postgre.hpp | 4 +- src/models/teacher/postgre.hpp | 3 +- src/models/teacher_filter/postgre.hpp | 3 +- src/models/teacher_info/postgre.hpp | 3 +- src/models/user/postgre.hpp | 3 +- src/models/user_credentials/postgre.hpp | 3 +- src/openapi/all.hpp | 5 +- src/openapi/as_tuple/property.hpp | 2 +- src/openapi/as_tuple/reflective.hpp | 2 +- src/openapi/base/object_property.hpp | 12 +-- src/openapi/base/reflective_checks.hpp | 33 +++++++ src/openapi/base/reflective_preferences.hpp | 20 +---- src/openapi/doc/serialize/base.hpp | 17 ++-- src/openapi/doc/serialize/request.hpp | 3 +- src/openapi/from_tuple/all.hpp | 4 +- src/openapi/from_tuple/default.hpp | 33 +++---- src/openapi/from_tuple/optional.hpp | 56 ++++++------ src/openapi/from_tuple/property.hpp | 32 +++---- src/openapi/from_tuple/reflective.hpp | 67 ++++++++------- src/openapi/from_tuple/vector.hpp | 61 +++++++------ src/openapi/http/base/response_info.hpp | 3 +- src/openapi/json/parse/array_property.hpp | 3 +- src/openapi/json/parse/object_property.hpp | 3 +- src/openapi/json/parse/optional_property.hpp | 3 +- src/openapi/json/parse/string_property.hpp | 5 +- src/openapi/postgres/mapping.hpp | 85 +++++++++++++++++++ src/utils/convert/drop_properties_ref.hpp | 8 +- src/utils/convert/http_request_parse.hpp | 3 +- src/utils/convert/json_parse.hpp | 3 +- src/utils/convert/json_serialize.hpp | 3 +- src/utils/shared_transaction.hpp | 15 ++-- src/views/admin/create/Responses.hpp | 3 +- src/views/admin/create/view.cpp | 5 +- src/views/admin/list/view.cpp | 5 +- src/views/login/view.cpp | 5 +- .../declarations.hpp | 40 --------- src/views/test-openapi-view-register/view.cpp | 45 ---------- src/views/test-openapi-view-register/view.hpp | 7 -- src/views/test-openapi-view/declarations.hpp | 11 ++- src/views/test-openapi-view/view.cpp | 9 +- src/views/timetable/get/view.cpp | 3 +- utests/openapi/doc/serialize/basic.cpp | 9 +- utests/openapi/raw/as_tuple.cpp | 52 +++++++----- utests/openapi/raw/from_tuple.cpp | 59 +++++++------ utests/openapi/raw/to_tuple.cpp | 47 +++++----- utests/remove_namespace.cpp | 7 +- 70 files changed, 452 insertions(+), 443 deletions(-) create mode 100644 src/openapi/base/reflective_checks.hpp create mode 100644 src/openapi/postgres/mapping.hpp delete mode 100644 src/views/test-openapi-view-register/declarations.hpp delete mode 100644 src/views/test-openapi-view-register/view.cpp delete mode 100644 src/views/test-openapi-view-register/view.hpp diff --git a/service/main.cpp b/service/main.cpp index bf4febd2..54f8ba86 100644 --- a/service/main.cpp +++ b/service/main.cpp @@ -34,7 +34,6 @@ #include "views/test-openapi-view/view.hpp" #include "views/timetable/get/view.hpp" - void AppendPgControllers(userver::components::ComponentList& component_list) { using namespace components::controllers::postgres; diff --git a/src/components/controllers/postgres/admin/controller.cpp b/src/components/controllers/postgres/admin/controller.cpp index 8a81e378..bbfd9d88 100644 --- a/src/components/controllers/postgres/admin/controller.cpp +++ b/src/components/controllers/postgres/admin/controller.cpp @@ -46,8 +46,7 @@ std::optional Controller::GetAccountByAdminId( const boost::uuids::uuid& admin_id, ::utils::SharedTransaction transaction) const { - ::utils::FillSharedTransaction(transaction, - pg_cluster_); + ::utils::FillSharedTransaction(transaction, pg_cluster_); auto pg_result = transaction->transaction_.Execute( sql::qGetAdminAccountByAdminId, admin_id); return utils::ConvertPgResultToOptionalItem( @@ -58,8 +57,7 @@ std::optional Controller::CreateAdmin( const models::UserCredentials& user, ::utils::SharedTransaction transaction) const { - ::utils::FillSharedTransaction(transaction, - pg_cluster_); + ::utils::FillSharedTransaction(transaction, pg_cluster_); auto tuple_user = utils::convert::DropPropertiesToConstRefs(user); auto result_id = transaction->transaction_.Execute(sql::qCreateAdminAccount, tuple_user); @@ -75,8 +73,7 @@ std::vector Controller::GetByFilter( std::optional& filter, ::utils::SharedTransaction transaction) const { - ::utils::FillSharedTransaction(transaction, - pg_cluster_); + ::utils::FillSharedTransaction(transaction, pg_cluster_); auto pg_result = utils::PgExecute(transaction, sql::qGetAdminsByFilter, filter); return utils::ConvertPgResultToArray(pg_result); diff --git a/src/components/controllers/postgres/faculty/controller.cpp b/src/components/controllers/postgres/faculty/controller.cpp index 0f4b9dcd..ffd23c16 100644 --- a/src/components/controllers/postgres/faculty/controller.cpp +++ b/src/components/controllers/postgres/faculty/controller.cpp @@ -57,5 +57,5 @@ std::vector Controller::GetByFilter( return utils::ConvertPgResultToArray(pg_result); } -} // namespace +} // namespace components::controllers::postgres::faculty // ::components::controllers::postgres::faculty diff --git a/src/components/controllers/postgres/faculty/controller.hpp b/src/components/controllers/postgres/faculty/controller.hpp index 19b79b8d..e3aeefce 100644 --- a/src/components/controllers/postgres/faculty/controller.hpp +++ b/src/components/controllers/postgres/faculty/controller.hpp @@ -34,5 +34,5 @@ class Controller final : public userver::components::LoggableComponentBase protected: userver::storages::postgres::ClusterPtr pg_cluster_; }; -} // namespace +} // namespace components::controllers::postgres::faculty // ::components::controllers::postgres::faculty diff --git a/src/components/controllers/postgres/faculty/fwd.cpp b/src/components/controllers/postgres/faculty/fwd.cpp index 6bf32739..1648c92d 100644 --- a/src/components/controllers/postgres/faculty/fwd.cpp +++ b/src/components/controllers/postgres/faculty/fwd.cpp @@ -10,5 +10,5 @@ void Append(userver::components::ComponentList& component_list) { component_list.Append(); } -} // namespace +} // namespace components::controllers::postgres::faculty // ::components::controllers::postgres::faculty diff --git a/src/components/controllers/postgres/faculty/fwd.hpp b/src/components/controllers/postgres/faculty/fwd.hpp index 738e42f1..852da1b8 100644 --- a/src/components/controllers/postgres/faculty/fwd.hpp +++ b/src/components/controllers/postgres/faculty/fwd.hpp @@ -5,5 +5,5 @@ namespace components::controllers::postgres::faculty { class Controller; void Append(userver::components::ComponentList& component_list); -} // namespace +} // namespace components::controllers::postgres::faculty // ::components::controllers::postgres::faculty diff --git a/src/components/controllers/postgres/group_stage/controller.cpp b/src/components/controllers/postgres/group_stage/controller.cpp index cba3e27a..5e02f03e 100644 --- a/src/components/controllers/postgres/group_stage/controller.cpp +++ b/src/components/controllers/postgres/group_stage/controller.cpp @@ -57,5 +57,5 @@ std::vector Controller::GetByFilter( return utils::ConvertPgResultToArray(pg_result); } -} // namespace +} // namespace components::controllers::postgres::group_stage // ::components::controllers::postgres::group_stage diff --git a/src/components/controllers/postgres/group_stage/controller.hpp b/src/components/controllers/postgres/group_stage/controller.hpp index 5a203816..006217af 100644 --- a/src/components/controllers/postgres/group_stage/controller.hpp +++ b/src/components/controllers/postgres/group_stage/controller.hpp @@ -34,5 +34,5 @@ class Controller final : public userver::components::LoggableComponentBase protected: userver::storages::postgres::ClusterPtr pg_cluster_; }; -} // namespace +} // namespace components::controllers::postgres::group_stage // ::components::controllers::postgres::group_stage diff --git a/src/components/controllers/postgres/group_stage/fwd.cpp b/src/components/controllers/postgres/group_stage/fwd.cpp index 6416703e..9daef3c7 100644 --- a/src/components/controllers/postgres/group_stage/fwd.cpp +++ b/src/components/controllers/postgres/group_stage/fwd.cpp @@ -10,5 +10,5 @@ void Append(userver::components::ComponentList& component_list) { component_list.Append(); } -} // namespace +} // namespace components::controllers::postgres::group_stage // ::components::controllers::postgres::group_stage diff --git a/src/components/controllers/postgres/group_stage/fwd.hpp b/src/components/controllers/postgres/group_stage/fwd.hpp index f3faeee2..fedae53c 100644 --- a/src/components/controllers/postgres/group_stage/fwd.hpp +++ b/src/components/controllers/postgres/group_stage/fwd.hpp @@ -5,5 +5,5 @@ namespace components::controllers::postgres::group_stage { class Controller; void Append(userver::components::ComponentList& component_list); -} // namespace +} // namespace components::controllers::postgres::group_stage // ::components::controllers::postgres::group_stage diff --git a/src/components/controllers/postgres/group_stage/sql_queries.hpp b/src/components/controllers/postgres/group_stage/sql_queries.hpp index b358d529..61115ee1 100644 --- a/src/components/controllers/postgres/group_stage/sql_queries.hpp +++ b/src/components/controllers/postgres/group_stage/sql_queries.hpp @@ -1,8 +1,7 @@ #pragma once #include -namespace components::controllers::postgres:: - group_stage::sql +namespace components::controllers::postgres::group_stage::sql { const userver::storages::postgres::Query qGetGroupStages(R"( WITH group_stages_info AS(SELECT diff --git a/src/components/controllers/postgres/lesson/controller.cpp b/src/components/controllers/postgres/lesson/controller.cpp index aeb7a801..4129f168 100644 --- a/src/components/controllers/postgres/lesson/controller.cpp +++ b/src/components/controllers/postgres/lesson/controller.cpp @@ -30,8 +30,7 @@ std::vector Controller::Search( const std::optional& filter, ::utils::SharedTransaction transaction) const { - ::utils::FillSharedTransaction(transaction, - pg_cluster_); + ::utils::FillSharedTransaction(transaction, pg_cluster_); auto pg_result = utils::PgExecute(transaction, sql::qGetLessonsByFilter, filter); return utils::ConvertPgResultToArray(pg_result); diff --git a/src/components/controllers/postgres/lesson/controller.hpp b/src/components/controllers/postgres/lesson/controller.hpp index 3f1d01ea..fe71baf4 100644 --- a/src/components/controllers/postgres/lesson/controller.hpp +++ b/src/components/controllers/postgres/lesson/controller.hpp @@ -19,8 +19,7 @@ class Controller final : public userver::components::LoggableComponentBase "lesson_details_controller"; std::vector Search( const std::optional& filter, - ::utils::SharedTransaction transaction = - nullptr) const; + ::utils::SharedTransaction transaction = nullptr) const; Controller(const userver::components::ComponentConfig& config, const userver::components::ComponentContext& context); diff --git a/src/components/controllers/postgres/teacher/controller.cpp b/src/components/controllers/postgres/teacher/controller.cpp index 91af40a4..e8531dfc 100644 --- a/src/components/controllers/postgres/teacher/controller.cpp +++ b/src/components/controllers/postgres/teacher/controller.cpp @@ -51,8 +51,7 @@ std::vector Controller::GetByFilter( std::optional& filter, ::utils::SharedTransaction transaction) const { - ::utils::FillSharedTransaction(transaction, - pg_cluster_); + ::utils::FillSharedTransaction(transaction, pg_cluster_); auto pg_result = utils::PgExecute(transaction, sql::qGetTeachersByFilter, filter); return utils::ConvertPgResultToArray(pg_result); @@ -150,5 +149,5 @@ std::optional Controller::DropRequest( return utils::ConvertPgResultToOptionalItem(pg_result); } -} // namespace +} // namespace components::controllers::postgres::teacher // ::components::controllers::postgres::teacher diff --git a/src/components/controllers/postgres/teacher/controller.hpp b/src/components/controllers/postgres/teacher/controller.hpp index 2f210faf..f826353b 100644 --- a/src/components/controllers/postgres/teacher/controller.hpp +++ b/src/components/controllers/postgres/teacher/controller.hpp @@ -25,42 +25,35 @@ class Controller final : public userver::components::LoggableComponentBase public: std::optional DropRequest( const boost::uuids::uuid& request_id, - ::utils::SharedTransaction transaction = - nullptr) const; + ::utils::SharedTransaction transaction = nullptr) const; std::vector GetAllRequests( - ::utils::SharedTransaction transaction = - nullptr) const; + ::utils::SharedTransaction transaction = nullptr) const; std::optional ApproveAndLink( const boost::uuids::uuid& request_id, const boost::uuids::uuid& teacher_id, - ::utils::SharedTransaction transaction = - nullptr) const; + ::utils::SharedTransaction transaction = nullptr) const; std::optional ApproveAndCreateAccount( const boost::uuids::uuid& request_id, const models::TeacherInfo& teacher_info, - ::utils::SharedTransaction transaction = - nullptr) const; + ::utils::SharedTransaction transaction = nullptr) const; std::optional Link( const boost::uuids::uuid& user_id, const boost::uuids::uuid& teacher_id, - ::utils::SharedTransaction transaction = - nullptr) const; + ::utils::SharedTransaction transaction = nullptr) const; std::vector GetByFilter( std::optional& filter, - ::utils::SharedTransaction transaction = - nullptr) const; + ::utils::SharedTransaction transaction = nullptr) const; std::optional CreateTeacher( const models::TeacherInfo& teacher_info, - ::utils::SharedTransaction transaction = - nullptr) const; + ::utils::SharedTransaction transaction = nullptr) const; ::utils::SharedTransaction CreateTransaction(); protected: userver::storages::postgres::ClusterPtr pg_cluster_; }; -} // namespace +} // namespace components::controllers::postgres::teacher // ::components::controllers::postgres::teacher diff --git a/src/components/controllers/postgres/teacher/fwd.cpp b/src/components/controllers/postgres/teacher/fwd.cpp index 1b77b6cc..89af2130 100644 --- a/src/components/controllers/postgres/teacher/fwd.cpp +++ b/src/components/controllers/postgres/teacher/fwd.cpp @@ -10,5 +10,5 @@ void Append(userver::components::ComponentList& component_list) { component_list.Append(); } -} // namespace +} // namespace components::controllers::postgres::teacher // ::components::controllers::postgres::teacher diff --git a/src/components/controllers/postgres/user/controller.hpp b/src/components/controllers/postgres/user/controller.hpp index eecf350e..1f4b0cba 100644 --- a/src/components/controllers/postgres/user/controller.hpp +++ b/src/components/controllers/postgres/user/controller.hpp @@ -57,6 +57,7 @@ class Controller final : public userver::components::LoggableComponentBase protected: std::optional HandleUserFromPg( userver::storages::postgres::ResultSet& result) const; + private: std::optional root_id; userver::storages::postgres::ClusterPtr pg_cluster_; diff --git a/src/models/admin_account/postgre.hpp b/src/models/admin_account/postgre.hpp index 0e3a5183..de767f50 100644 --- a/src/models/admin_account/postgre.hpp +++ b/src/models/admin_account/postgre.hpp @@ -8,8 +8,7 @@ namespace models { using AdminAccountTuple = - ::utils::convert::drop_properties_to_ref_mut_t< - AdminAccount>; + ::utils::convert::drop_properties_to_ref_mut_t; } // namespace models namespace userver::storages::postgres::io diff --git a/src/models/admin_filter/postgre.hpp b/src/models/admin_filter/postgre.hpp index 11298b04..dd4f121e 100644 --- a/src/models/admin_filter/postgre.hpp +++ b/src/models/admin_filter/postgre.hpp @@ -6,8 +6,7 @@ namespace models { using TupleAdminFilter = - ::utils::convert::drop_properties_to_ref_const_t< - AdminFilter>; + ::utils::convert::drop_properties_to_ref_const_t; } // namespace models namespace userver::storages::postgres::io diff --git a/src/models/faculty/postgre.hpp b/src/models/faculty/postgre.hpp index 3f3cedaa..8fed8d36 100644 --- a/src/models/faculty/postgre.hpp +++ b/src/models/faculty/postgre.hpp @@ -5,9 +5,7 @@ #include "models/faculty/type.hpp" namespace models { -using TupleFaculty = - ::utils::convert::drop_properties_to_ref_const_t< - Faculty>; +using TupleFaculty = ::utils::convert::drop_properties_to_ref_const_t; } // namespace models namespace userver::storages::postgres::io diff --git a/src/models/faculty_filter/postgre.hpp b/src/models/faculty_filter/postgre.hpp index 21e81b85..dd596b29 100644 --- a/src/models/faculty_filter/postgre.hpp +++ b/src/models/faculty_filter/postgre.hpp @@ -6,8 +6,7 @@ namespace models { using TupleFacultyFilter = - ::utils::convert::drop_properties_to_ref_const_t< - FacultyFilter>; + ::utils::convert::drop_properties_to_ref_const_t; } // namespace models namespace userver::storages::postgres::io diff --git a/src/models/group_stage/postgre.hpp b/src/models/group_stage/postgre.hpp index 7e68c357..9a445e4d 100644 --- a/src/models/group_stage/postgre.hpp +++ b/src/models/group_stage/postgre.hpp @@ -6,8 +6,7 @@ namespace models { using TupleGroupStage = - ::utils::convert::drop_properties_to_ref_const_t< - GroupStage>; + ::utils::convert::drop_properties_to_ref_const_t; } // namespace models namespace userver::storages::postgres::io diff --git a/src/models/group_stage_filter/postgre.hpp b/src/models/group_stage_filter/postgre.hpp index fdff11e0..792611db 100644 --- a/src/models/group_stage_filter/postgre.hpp +++ b/src/models/group_stage_filter/postgre.hpp @@ -6,8 +6,7 @@ namespace models { using TupleGroupStageFilter = - ::utils::convert::drop_properties_to_ref_const_t< - GroupStageFilter>; + ::utils::convert::drop_properties_to_ref_const_t; } // namespace models namespace userver::storages::postgres::io diff --git a/src/models/lesson_filter/postgre.hpp b/src/models/lesson_filter/postgre.hpp index 6875cc24..c65d000c 100644 --- a/src/models/lesson_filter/postgre.hpp +++ b/src/models/lesson_filter/postgre.hpp @@ -6,8 +6,7 @@ namespace models { using TupleLessonFilter = - ::utils::convert::drop_properties_to_ref_const_t< - LessonFilter>; + ::utils::convert::drop_properties_to_ref_const_t; } // namespace models namespace userver::storages::postgres::io diff --git a/src/models/lesson_v1/postgre.hpp b/src/models/lesson_v1/postgre.hpp index 49c7f97a..36134974 100644 --- a/src/models/lesson_v1/postgre.hpp +++ b/src/models/lesson_v1/postgre.hpp @@ -10,7 +10,5 @@ #include "models/timestring/postgre.hpp" namespace models { -using TupleLessonV1 = - ::utils::convert::drop_properties_to_ref_mut_t< - LessonV1>; +using TupleLessonV1 = ::utils::convert::drop_properties_to_ref_mut_t; } diff --git a/src/models/teacher/postgre.hpp b/src/models/teacher/postgre.hpp index 98f93be8..38c53677 100644 --- a/src/models/teacher/postgre.hpp +++ b/src/models/teacher/postgre.hpp @@ -7,8 +7,7 @@ namespace models { using ConstTupleTeacher = - ::utils::convert::drop_properties_to_ref_const_t< - Teacher>; + ::utils::convert::drop_properties_to_ref_const_t; } // namespace models diff --git a/src/models/teacher_filter/postgre.hpp b/src/models/teacher_filter/postgre.hpp index 92eabe02..67110089 100644 --- a/src/models/teacher_filter/postgre.hpp +++ b/src/models/teacher_filter/postgre.hpp @@ -6,8 +6,7 @@ namespace models { using TupleTeacherFilter = - ::utils::convert::drop_properties_to_ref_const_t< - TeacherFilter>; + ::utils::convert::drop_properties_to_ref_const_t; } // namespace models namespace userver::storages::postgres::io diff --git a/src/models/teacher_info/postgre.hpp b/src/models/teacher_info/postgre.hpp index a998ef92..b1d0528e 100644 --- a/src/models/teacher_info/postgre.hpp +++ b/src/models/teacher_info/postgre.hpp @@ -7,8 +7,7 @@ namespace models { using ConstTupleTeacherInfo = - ::utils::convert::drop_properties_to_ref_const_t< - TeacherInfo>; + ::utils::convert::drop_properties_to_ref_const_t; } // namespace models diff --git a/src/models/user/postgre.hpp b/src/models/user/postgre.hpp index 76302272..bfc8ddf7 100644 --- a/src/models/user/postgre.hpp +++ b/src/models/user/postgre.hpp @@ -7,8 +7,7 @@ #include "models/user_type/postgre.hpp" namespace models { -using TupleUserRaw = - ::utils::convert::drop_properties_to_ref_const_t; +using TupleUserRaw = ::utils::convert::drop_properties_to_ref_const_t; // using TupleUser = // userver::utils::StrongTypedef; + ::utils::convert::drop_properties_to_ref_const_t; using TupleUserCredentials = TupleUserCredentialsRaw; } // namespace models diff --git a/src/openapi/all.hpp b/src/openapi/all.hpp index eccb9092..e030da02 100644 --- a/src/openapi/all.hpp +++ b/src/openapi/all.hpp @@ -1,10 +1,11 @@ #pragma once +#include #include #include +#include #include #include -#include +#include #include -#include #include diff --git a/src/openapi/as_tuple/property.hpp b/src/openapi/as_tuple/property.hpp index 229c660e..a8bbd210 100644 --- a/src/openapi/as_tuple/property.hpp +++ b/src/openapi/as_tuple/property.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include namespace openapi::raw { template diff --git a/src/openapi/as_tuple/reflective.hpp b/src/openapi/as_tuple/reflective.hpp index 7ccc68d3..714476a0 100644 --- a/src/openapi/as_tuple/reflective.hpp +++ b/src/openapi/as_tuple/reflective.hpp @@ -2,8 +2,8 @@ #include #include -#include #include +#include #include #include diff --git a/src/openapi/base/object_property.hpp b/src/openapi/base/object_property.hpp index b911f443..58b5a843 100644 --- a/src/openapi/base/object_property.hpp +++ b/src/openapi/base/object_property.hpp @@ -1,22 +1,12 @@ #pragma once +#include #include #include "property_base.hpp" namespace openapi { -namespace checks -{ -template -concept IsReflective = requires -{ - requires std::is_class_v; - requires std::is_aggregate_v; - requires !IsProperty; -}; -} // namespace checks - template struct ObjectProperty : public PropertyBase { diff --git a/src/openapi/base/reflective_checks.hpp b/src/openapi/base/reflective_checks.hpp new file mode 100644 index 00000000..05d05bad --- /dev/null +++ b/src/openapi/base/reflective_checks.hpp @@ -0,0 +1,33 @@ +#pragma once +#include +#include +#include +#include + +namespace openapi +{ +namespace checks +{ +template +concept IsReflectiveHelper = requires +{ + requires(IsProperty> && ...); +}; + +template +concept IsReflective = requires +{ + requires std::is_class_v; + requires std::is_aggregate_v; + + requires !IsProperty; +}; + +template +concept IsReflectiveProperty = IsProperty && IsReflective; + +template +concept IsNotReflectiveProperty = IsProperty && !IsReflective; + +} // namespace checks +} // namespace openapi diff --git a/src/openapi/base/reflective_preferences.hpp b/src/openapi/base/reflective_preferences.hpp index 3d10970b..27af37ba 100644 --- a/src/openapi/base/reflective_preferences.hpp +++ b/src/openapi/base/reflective_preferences.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -19,30 +20,17 @@ namespace openapi /* Добавьте это поле в свою структуру, чтобы её схема была с AddditionalProperties: true */ -struct AdditionalProperties +struct AdditionalProperties : PropertyBase { - userver::formats::json::Value value_; - userver::formats::json::Value& operator()() & - { - return value_; - } - const userver::formats::json::Value& operator()() const& - { - return value_; - } - userver::formats::json::Value operator()() && - { - return std::move(value_); - } std::partial_ordering operator<=>(const AdditionalProperties& rhs) const { - return *this <=> rhs.value_; + return *this <=> rhs.value; } std::partial_ordering operator<=>( const userver::formats::json::Value& rhs) const { auto& lhs = *this; - if (lhs.value_ == rhs) + if (lhs.value == rhs) return std::partial_ordering::equivalent; return std::partial_ordering::unordered; } diff --git a/src/openapi/doc/serialize/base.hpp b/src/openapi/doc/serialize/base.hpp index fa346d76..11bfc0fc 100644 --- a/src/openapi/doc/serialize/base.hpp +++ b/src/openapi/doc/serialize/base.hpp @@ -44,18 +44,19 @@ inline void log_yaml_impl(userver::formats::yaml::ValueBuilder yaml, std::clog << ToString(yaml.ExtractValue()) << '\n'; } -#define log_yaml(yaml) \ - ::openapi::log_yaml_impl(yaml, __FILE__, __LINE__, \ - __PRETTY_FUNCTION__) +#define log_yaml(yaml) \ + ::openapi::log_yaml_impl(yaml, __FILE__, __LINE__, __PRETTY_FUNCTION__) -//some_namespace..some_class -//precondition: string from demangle +// some_namespace..some_class +// precondition: string from demangle inline void RemoveNamespaces(std::string& name_class) -{ +{ auto read = std::find(name_class.begin(), name_class.end(), ':'); auto write = read; - while (read != name_class.end()){ - if (*read == ':'){ + while (read != name_class.end()) + { + if (*read == ':') + { read++; *read = '.'; } diff --git a/src/openapi/doc/serialize/request.hpp b/src/openapi/doc/serialize/request.hpp index 83af7a0b..55493c51 100644 --- a/src/openapi/doc/serialize/request.hpp +++ b/src/openapi/doc/serialize/request.hpp @@ -15,7 +15,8 @@ template void AppendRequest(DocHelper doc_helper, std::type_identity) { auto& [root, cur] = doc_helper; - if (cur.IsObject()){ + if (cur.IsObject()) + { return; } cur["description"] = GetOpenApiTypeName(); diff --git a/src/openapi/from_tuple/all.hpp b/src/openapi/from_tuple/all.hpp index 27fc6847..c7f991c0 100644 --- a/src/openapi/from_tuple/all.hpp +++ b/src/openapi/from_tuple/all.hpp @@ -2,6 +2,6 @@ #include #include -#include #include -#include \ No newline at end of file +#include +#include diff --git a/src/openapi/from_tuple/default.hpp b/src/openapi/from_tuple/default.hpp index e62f5cfe..95b5d414 100644 --- a/src/openapi/from_tuple/default.hpp +++ b/src/openapi/from_tuple/default.hpp @@ -2,20 +2,23 @@ #include #include -namespace openapi::raw{ - template - class FromTuple{ - public: - using Dest = T; - using Src = to_tuple_t; - static Dest Do(const Src& src){ - return src; - } - }; +namespace openapi::raw +{ +template +class FromTuple +{ + public: + using Dest = T; + using Src = to_tuple_t; + static Dest Do(const Src& src) + { + return src; + } +}; - template - using dest_t = typename FromTuple::Dest; +template +using dest_t = typename FromTuple::Dest; - template - using src_t = typename FromTuple::Src; -} \ No newline at end of file +template +using src_t = typename FromTuple::Src; +} // namespace openapi::raw diff --git a/src/openapi/from_tuple/optional.hpp b/src/openapi/from_tuple/optional.hpp index 9daf081c..8989e568 100644 --- a/src/openapi/from_tuple/optional.hpp +++ b/src/openapi/from_tuple/optional.hpp @@ -1,30 +1,38 @@ #pragma once #include +#include #include #include -#include "openapi/to_tuple/default.hpp" -namespace openapi::raw{ - template - class FromTuple>{ - public: - using Dst = std::optional; - using Src = Dst; - static Dst Do(const Src& src){ - return src; - } - }; - template - class FromTuple>{ - using Raw = to_tuple_t; - public: - using Src = std::optional; - using Dst = std::optional; - static Dst Do(const Src& src){ - if (src.has_value()){ - return FromTuple::Do(src.value()); - } - else return std::nullopt; +namespace openapi::raw +{ +template +class FromTuple> +{ + public: + using Dst = std::optional; + using Src = Dst; + static Dst Do(const Src& src) + { + return src; + } +}; +template +class FromTuple> +{ + using Raw = to_tuple_t; + + public: + using Src = std::optional; + using Dst = std::optional; + static Dst Do(const Src& src) + { + if (src.has_value()) + { + return FromTuple::Do(src.value()); } - }; -} \ No newline at end of file + else + return std::nullopt; + } +}; +} // namespace openapi::raw diff --git a/src/openapi/from_tuple/property.hpp b/src/openapi/from_tuple/property.hpp index d1fbfce1..73c3ea69 100644 --- a/src/openapi/from_tuple/property.hpp +++ b/src/openapi/from_tuple/property.hpp @@ -1,19 +1,21 @@ #pragma once +#include #include #include -#include "openapi/base/property_base.hpp" -namespace openapi::raw{ - template - class FromTuple{ - using T = typename U::value_type; - public: - using Src = to_tuple_t; - using Dst = U; - static Dst Do(const Src& src){ - return { - FromTuple::Do(src) - }; - } - }; -} \ No newline at end of file +namespace openapi::raw +{ +template +class FromTuple +{ + using T = typename U::value_type; + + public: + using Src = to_tuple_t; + using Dst = U; + static Dst Do(const Src& src) + { + return {FromTuple::Do(src)}; + } +}; +} // namespace openapi::raw diff --git a/src/openapi/from_tuple/reflective.hpp b/src/openapi/from_tuple/reflective.hpp index 7912993a..93991b33 100644 --- a/src/openapi/from_tuple/reflective.hpp +++ b/src/openapi/from_tuple/reflective.hpp @@ -1,36 +1,45 @@ #pragma once +#include +#include +#include #include #include #include #include -#include "boost/pfr/core.hpp" -#include "openapi/base/object_property.hpp" -#include "openapi/base/property_base.hpp" -namespace openapi::raw{ - template - class FromTuple{ - public: - using Src = to_tuple_t; - using Dst = T; - private: - static constexpr auto Indexes = std::make_index_sequence>{}; +namespace openapi::raw +{ +template +class FromTuple +{ + public: + using Src = to_tuple_t; + using Dst = T; - template - static auto HandleMember(const Src& src){ - auto&& member = std::get(src); - using DstMember = boost::pfr::tuple_element_t; - return FromTuple::Do(member); - } - - template - static Dst Construct(const Src& src, std::integer_sequence){ - return Dst{HandleMember(src)...}; - } - public: - static Dst Do(const Src& src){ - auto indexes = Indexes; - return Construct(src, indexes); - } - }; -} \ No newline at end of file + private: + static constexpr auto Indexes = + std::make_index_sequence>{}; + + template + static auto HandleMember(const Src& src) + { + auto&& member = std::get(src); + using DstMember = boost::pfr::tuple_element_t; + return FromTuple::Do(member); + } + + template + static Dst Construct(const Src& src, + std::integer_sequence) + { + return Dst{HandleMember(src)...}; + } + + public: + static Dst Do(const Src& src) + { + auto indexes = Indexes; + return Construct(src, indexes); + } +}; +} // namespace openapi::raw diff --git a/src/openapi/from_tuple/vector.hpp b/src/openapi/from_tuple/vector.hpp index 78242cf6..452d19b5 100644 --- a/src/openapi/from_tuple/vector.hpp +++ b/src/openapi/from_tuple/vector.hpp @@ -1,32 +1,39 @@ #pragma once #include -#include +#include #include -#include "openapi/to_tuple/default.hpp" +#include -namespace openapi::raw{ - template - class FromTuple>{ - public: - using Dst = std::vector; - using Src = Dst; - static Dst Do(const Src& src){ - return src; - } - }; - template - class FromTuple>{ - using Raw = to_tuple_t; - public: - using Src = std::vector; - using Dst = std::vector; - static Dst Do(const Src& src){ - Dst result; - result.reserve(src.size()); - for (auto& elem: src){ - result.emplace_back(FromTuple::Do(elem)); - } - return result; +namespace openapi::raw +{ +template +class FromTuple> +{ + public: + using Dst = std::vector; + using Src = Dst; + static Dst Do(const Src& src) + { + return src; + } +}; +template +class FromTuple> +{ + using Raw = to_tuple_t; + + public: + using Src = std::vector; + using Dst = std::vector; + static Dst Do(const Src& src) + { + Dst result; + result.reserve(src.size()); + for (auto& elem : src) + { + result.emplace_back(FromTuple::Do(elem)); } - }; -} \ No newline at end of file + return result; + } +}; +} // namespace openapi::raw diff --git a/src/openapi/http/base/response_info.hpp b/src/openapi/http/base/response_info.hpp index c8332080..2edacaf5 100644 --- a/src/openapi/http/base/response_info.hpp +++ b/src/openapi/http/base/response_info.hpp @@ -37,7 +37,8 @@ struct ResponseInfo { return std::partial_ordering::unordered; } - if (auto cmp = lhs.response_body_type == rhs.response_body_type; !cmp){ + if (auto cmp = lhs.response_body_type == rhs.response_body_type; !cmp) + { return std::partial_ordering::unordered; } return std::partial_ordering::equivalent; diff --git a/src/openapi/json/parse/array_property.hpp b/src/openapi/json/parse/array_property.hpp index e7d7663e..b8c1b43f 100644 --- a/src/openapi/json/parse/array_property.hpp +++ b/src/openapi/json/parse/array_property.hpp @@ -14,8 +14,7 @@ namespace userver::formats::parse { template ::openapi::ArrayProperty Parse( - const json::Value& item, - To<::openapi::ArrayProperty>) + const json::Value& item, To<::openapi::ArrayProperty>) { using namespace openapi; diff --git a/src/openapi/json/parse/object_property.hpp b/src/openapi/json/parse/object_property.hpp index 02ad0237..4b8e0c95 100644 --- a/src/openapi/json/parse/object_property.hpp +++ b/src/openapi/json/parse/object_property.hpp @@ -20,8 +20,7 @@ namespace userver::formats::parse { template ::openapi::ObjectProperty Parse( - const json::Value& item, - To<::openapi::ObjectProperty>) + const json::Value& item, To<::openapi::ObjectProperty>) { T result; return {item.As()}; diff --git a/src/openapi/json/parse/optional_property.hpp b/src/openapi/json/parse/optional_property.hpp index d60438e2..fc171c6e 100644 --- a/src/openapi/json/parse/optional_property.hpp +++ b/src/openapi/json/parse/optional_property.hpp @@ -20,8 +20,7 @@ namespace userver::formats::parse { template ::openapi::OptionalProperty Parse( - const json::Value& item, - To<::openapi::OptionalProperty>) + const json::Value& item, To<::openapi::OptionalProperty>) { using namespace openapi::traits; constexpr OptionalHelperTraits traits; diff --git a/src/openapi/json/parse/string_property.hpp b/src/openapi/json/parse/string_property.hpp index b5cdc7f4..6965278d 100644 --- a/src/openapi/json/parse/string_property.hpp +++ b/src/openapi/json/parse/string_property.hpp @@ -15,9 +15,8 @@ namespace userver::formats::parse { template -::openapi::StringProperty Parse( - const json::Value& item, - To<::openapi::StringProperty>) +::openapi::StringProperty Parse(const json::Value& item, + To<::openapi::StringProperty>) { using namespace openapi; diff --git a/src/openapi/postgres/mapping.hpp b/src/openapi/postgres/mapping.hpp new file mode 100644 index 00000000..0d6b0359 --- /dev/null +++ b/src/openapi/postgres/mapping.hpp @@ -0,0 +1,85 @@ +#pragma once + +#include +#include +#include +#include +#include +namespace userver::storages::postgres::io +{ + +namespace detail{ + +template +struct OpenapiPropertyFormatter : BufferFormatterBase { + using Inner = typename T::value_type; + using BaseType = BufferFormatterBase; + using ValueFormatter = typename traits::IO::FormatterType; + + using BaseType::BaseType; + + 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; + + using BaseType::BaseType; + + void operator()(const FieldBuffer& buffer) { + Inner val; + ValueParser{val}(buffer); + this->value() = std::move(val); + } +}; +} + +/* +Formatter specialization for openapi::Property +*/ +template +struct BufferFormatter>> + : 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; +}; + +template +struct CppToUserPg +{ + private: + using Inner = typename T::value_type; + public: + static constexpr DBTypeName postgres_name = + CppToUserPg::postgres_name; +}; + +template +struct CppToSystemPg +{ + private: + using Inner = typename T::value_type; + public: + static constexpr auto value = + CppToSystemPg::value; +}; + + +} // namespace userver::storages::postgres::io diff --git a/src/utils/convert/drop_properties_ref.hpp b/src/utils/convert/drop_properties_ref.hpp index 3dc33c16..5f20ea1f 100644 --- a/src/utils/convert/drop_properties_ref.hpp +++ b/src/utils/convert/drop_properties_ref.hpp @@ -72,13 +72,11 @@ auto DropPropertiesToConstRefs(const T& t) } template -using drop_properties_to_ref_const_t = - decltype(::utils::convert::DropPropertiesToConstRefs( - std::declval())); +using drop_properties_to_ref_const_t = decltype( + ::utils::convert::DropPropertiesToConstRefs(std::declval())); template using drop_properties_to_ref_mut_t = - decltype(::utils::convert::DropPropertiesToMutRefs( - std::declval())); + decltype(::utils::convert::DropPropertiesToMutRefs(std::declval())); } // namespace utils::convert diff --git a/src/utils/convert/http_request_parse.hpp b/src/utils/convert/http_request_parse.hpp index f538465b..f800a6e8 100644 --- a/src/utils/convert/http_request_parse.hpp +++ b/src/utils/convert/http_request_parse.hpp @@ -15,8 +15,7 @@ template <::utils::convert::HttpRequestParsable T> T Parse(const userver::server::http::HttpRequest& value, formats::parse::To) { T t; - ::utils::convert::detail::parse::ConverterHttpRequest< - T>::Do(t, value); + ::utils::convert::detail::parse::ConverterHttpRequest::Do(t, value); return t; } } // namespace userver::formats::parse diff --git a/src/utils/convert/json_parse.hpp b/src/utils/convert/json_parse.hpp index 7b43a565..7ba86fd3 100644 --- a/src/utils/convert/json_parse.hpp +++ b/src/utils/convert/json_parse.hpp @@ -24,8 +24,7 @@ template <::utils::convert::JsonParsable T> T Parse(const json::Value& value, To) { T t; - ::utils::convert::detail::parse::ConverterJson::Do( - t, value); + ::utils::convert::detail::parse::ConverterJson::Do(t, value); return t; } diff --git a/src/utils/convert/json_serialize.hpp b/src/utils/convert/json_serialize.hpp index 515a5bf8..a836ab83 100644 --- a/src/utils/convert/json_serialize.hpp +++ b/src/utils/convert/json_serialize.hpp @@ -23,8 +23,7 @@ template <::utils::convert::JsonSeriazable T> json::Value Serialize(const T& t, To) { json::ValueBuilder json; - ::utils::convert::detail::serialize::ConverterJson< - T>::Do(t, json); + ::utils::convert::detail::serialize::ConverterJson::Do(t, json); return json.ExtractValue(); } } // namespace userver::formats::serialize diff --git a/src/utils/shared_transaction.hpp b/src/utils/shared_transaction.hpp index e4871fc7..cdbf9381 100644 --- a/src/utils/shared_transaction.hpp +++ b/src/utils/shared_transaction.hpp @@ -45,11 +45,17 @@ struct SafeTranscaction /* Интрузивный указатель используется для того, чтобы упростить использование -совместных транзакций. Данный класс не является threadsafe, но является safe -относительно совместного использования между разными функциями. Стандартное +совместных транзакций. + +Данный класс не является threadsafe, но является safe +относительно совместного использования между разными функциями. + +Стандартное применение предполагает получение интрузивного птр в каждом методе контроллера, заполнение его при помощи FillSharedTransaction, чтобы гарантировать наличие -какое-либо транзакции. По умолчанию выполняется коммит в деструкторе, чтобы +какое-либо транзакции. + +По умолчанию выполняется коммит в деструкторе, чтобы избежать этого поведения нужно задать противоположное. Благодаря этому явный коммит не нужен. */ @@ -70,8 +76,7 @@ inline void FillSharedTransaction( { if (!transaction) { - transaction = ::utils::MakeSharedTransaction( - ptr, name, auto_commit); + transaction = ::utils::MakeSharedTransaction(ptr, name, auto_commit); } } } // namespace utils diff --git a/src/views/admin/create/Responses.hpp b/src/views/admin/create/Responses.hpp index 7fc63b40..84f5ca55 100644 --- a/src/views/admin/create/Responses.hpp +++ b/src/views/admin/create/Responses.hpp @@ -17,8 +17,7 @@ namespace views::admin::create using namespace utils::convert; struct Response200 { - Property<::models::AdminAccount, "created_account"> - created_account; + Property<::models::AdminAccount, "created_account"> created_account; static constexpr TypeOfBody kTypeOfBody = TypeOfBody::Json; static constexpr PolicyFields kPolicyFields = PolicyFields::ConvertAll; static constexpr userver::server::http::HttpStatus kStatusCode = diff --git a/src/views/admin/create/view.cpp b/src/views/admin/create/view.cpp index fb199be2..e9b4848c 100644 --- a/src/views/admin/create/view.cpp +++ b/src/views/admin/create/view.cpp @@ -19,9 +19,8 @@ #include "models/user_type/serialize.hpp" namespace views::admin::create { -static_assert( - userver::formats::common::impl::kHasSerialize< - userver::formats::json::Value, ::models::User>); +static_assert(userver::formats::common::impl::kHasSerialize< + userver::formats::json::Value, ::models::User>); namespace { namespace pg = components::controllers::postgres; diff --git a/src/views/admin/list/view.cpp b/src/views/admin/list/view.cpp index 68561757..67f5aa93 100644 --- a/src/views/admin/list/view.cpp +++ b/src/views/admin/list/view.cpp @@ -21,9 +21,8 @@ #include "models/user_type/serialize.hpp" namespace views::admin::list { -static_assert( - userver::formats::common::impl::kHasSerialize< - userver::formats::json::Value, ::models::User>); +static_assert(userver::formats::common::impl::kHasSerialize< + userver::formats::json::Value, ::models::User>); namespace { namespace pg = components::controllers::postgres; diff --git a/src/views/login/view.cpp b/src/views/login/view.cpp index 5aea15f6..17d7c4a4 100644 --- a/src/views/login/view.cpp +++ b/src/views/login/view.cpp @@ -20,9 +20,8 @@ namespace views::login { -static_assert( - userver::formats::common::impl::kHasSerialize< - userver::formats::json::Value, ::models::User>); +static_assert(userver::formats::common::impl::kHasSerialize< + userver::formats::json::Value, ::models::User>); namespace { namespace pg = components::controllers::postgres; diff --git a/src/views/test-openapi-view-register/declarations.hpp b/src/views/test-openapi-view-register/declarations.hpp deleted file mode 100644 index fa26a731..00000000 --- a/src/views/test-openapi-view-register/declarations.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#include -#include -#include - -using namespace openapi::types; -using namespace openapi::http; -using namespace openapi::preferences; - -namespace views::test::sign_in -{ -struct RequestBody -{ - String> login; - String> password; - Array, Max<2>, UniqueItems, Name<"some_array">> - some_array; - auto operator<=>(const RequestBody&) const = default; -}; - -struct Request -{ - Body body; - Header, Name<"some_token">> some_token; - auto operator<=>(const Request&) const = default; -}; - -struct ResponseBody -{ - String> some_string; - auto operator<=>(const ResponseBody&) const = default; -}; - -struct Response -{ - Body body; - Header> some_header; - auto operator<=>(const Response&) const = default; -}; -} // namespace views::test::sign_in diff --git a/src/views/test-openapi-view-register/view.cpp b/src/views/test-openapi-view-register/view.cpp deleted file mode 100644 index 81f0262f..00000000 --- a/src/views/test-openapi-view-register/view.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "view.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "declarations.hpp" - -namespace views::test::sign_in -{ -namespace -{ -using Resp200 = Resp; -struct View final : openapi::http::OpenApiHandler -{ - static constexpr std::string_view kName = "test-register-view"; - using Base = openapi::http::OpenApiHandler; - View(const userver::components::ComponentConfig& cfg, - const userver::components::ComponentContext& ctx) - : Base(cfg, ctx) - { - } - Resps Handle(Request&& req) const override - { - Resp200 resp200; - resp200().body().some_string() = - fmt::format("login: {}, password: {}", req.body().login(), - req.body().password()); - resp200().some_header() = req.some_token().value_or("empty"); - return resp200; - } -}; -} // namespace - -void Append(userver::components::ComponentList& component_list) -{ - component_list.Append(); -} - -} // namespace views::test::sign_in diff --git a/src/views/test-openapi-view-register/view.hpp b/src/views/test-openapi-view-register/view.hpp deleted file mode 100644 index cbb61644..00000000 --- a/src/views/test-openapi-view-register/view.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include -namespace views::test::sign_in -{ -void Append(userver::components::ComponentList& component_list); - -} diff --git a/src/views/test-openapi-view/declarations.hpp b/src/views/test-openapi-view/declarations.hpp index 3beb6456..55559092 100644 --- a/src/views/test-openapi-view/declarations.hpp +++ b/src/views/test-openapi-view/declarations.hpp @@ -2,6 +2,7 @@ #include #include #include +#include using namespace openapi::types; using namespace openapi::http; @@ -10,23 +11,20 @@ namespace views::test::login { struct RequestBody { - String> login; - String> password; - Array, Max<2>, UniqueItems, Name<"some_array">> - some_array; + String> login; + String> password; auto operator<=>(const RequestBody&) const = default; }; struct Request { Body body; - Header, Name<"some_token">> some_token; auto operator<=>(const Request&) const = default; }; struct ResponseBody { - String> some_string; + String> some_string; auto operator<=>(const ResponseBody&) const = default; }; @@ -36,4 +34,5 @@ struct Response Header> some_header; auto operator<=>(const Response&) const = default; }; + } // namespace views::test::login diff --git a/src/views/test-openapi-view/view.cpp b/src/views/test-openapi-view/view.cpp index 7e10eccb..6e9de4f7 100644 --- a/src/views/test-openapi-view/view.cpp +++ b/src/views/test-openapi-view/view.cpp @@ -17,7 +17,8 @@ namespace { using Resp200 = Resp; using Resp400 = Resp; -struct View final : public openapi::http::OpenApiHandler +struct View final + : public openapi::http::OpenApiHandler { static constexpr std::string_view kName = "test-login-view"; using Base = openapi::http::OpenApiHandler; @@ -26,13 +27,9 @@ struct View final : public openapi::http::OpenApiHandler); + userver::formats::json::Value, ::models::LessonType>); namespace views::timetable::get { namespace diff --git a/utests/openapi/doc/serialize/basic.cpp b/utests/openapi/doc/serialize/basic.cpp index 803ad0f5..81a6e033 100644 --- a/utests/openapi/doc/serialize/basic.cpp +++ b/utests/openapi/doc/serialize/basic.cpp @@ -34,8 +34,7 @@ struct Credentials UTEST(TestNameStruct, Basic) { - EXPECT_EQ(::openapi::GetOpenApiTypeName< - tests::Credentials>(), + EXPECT_EQ(::openapi::GetOpenApiTypeName(), "tests.Credentials"); } @@ -99,10 +98,8 @@ struct SomeStructure UTEST(Openapi_Doc_Serialize, BasicAdditionalProperties) { ::openapi::Doc doc; - Append(doc, - std::type_identity<::tests::SomeStructure>{}); - Append(doc, - std::type_identity<::tests::SomeStructure>{}); + Append(doc, std::type_identity<::tests::SomeStructure>{}); + Append(doc, std::type_identity<::tests::SomeStructure>{}); auto value = doc().ExtractValue(); auto result_schema = ToString(value); EXPECT_EQ(result_schema, RAW_STRING( diff --git a/utests/openapi/raw/as_tuple.cpp b/utests/openapi/raw/as_tuple.cpp index e987de5b..ffd88ca6 100644 --- a/utests/openapi/raw/as_tuple.cpp +++ b/utests/openapi/raw/as_tuple.cpp @@ -1,4 +1,5 @@ #include + #include #include #include @@ -32,40 +33,38 @@ UTEST(OpenApiAsTuple, BasicStirngReflective) test_class.test() = "first"; test_class.value() = "second"; auto result = AsTuple::Do(test_class); - static_assert(std::is_same_v, std::tuple>); + static_assert(std::is_same_v, + std::tuple>); EXPECT_EQ(std::get<0>(result), "first"); EXPECT_EQ(std::get<1>(result), "second"); - //assert refs + // assert refs EXPECT_EQ(&std::get<0>(result), &test_class.test()); EXPECT_EQ(&std::get<1>(result), &test_class.value()); } -UTEST(OpenApiAsTuple, BasicArrayReflective){ +UTEST(OpenApiAsTuple, BasicArrayReflective) +{ using T = Array>; T t; - t().emplace_back(TestClass{ - .test = {"first"}, - .value = {"second"} - }); - t().emplace_back(TestClass{ - .test = {"third"}, - .value = {"fourth"} - }); + t().emplace_back(TestClass{.test = {"first"}, .value = {"second"}}); + t().emplace_back(TestClass{.test = {"third"}, .value = {"fourth"}}); auto result = AsTuple::Do(t); - static_assert(std::is_same_v, std::vector>>); + static_assert( + std::is_same_v, + std::vector>>); EXPECT_EQ(std::get<0>(result[0]), "first"); EXPECT_EQ(std::get<1>(result[0]), "second"); EXPECT_EQ(std::get<0>(result[1]), "third"); EXPECT_EQ(std::get<1>(result[1]), "fourth"); - //assert refs + // assert refs EXPECT_EQ(&std::get<0>(result[0]), &t()[0].test()); EXPECT_EQ(&std::get<1>(result[0]), &t()[0].value()); EXPECT_EQ(&std::get<0>(result[1]), &t()[1].test()); EXPECT_EQ(&std::get<1>(result[1]), &t()[1].value()); } -namespace { - +namespace +{ struct TestClass2 { Object> some_field; @@ -81,27 +80,34 @@ struct SomeRequest }; template -decltype(auto) Get(auto&& tuple){ +decltype(auto) Get(auto&& tuple) +{ auto& head = std::get(tuple); - if constexpr (sizeof...(Indexes) != 0){ + if constexpr (sizeof...(Indexes) != 0) + { return Get(head); } - else { + else + { return head; } } -} +} // namespace -UTEST(OpenApiAsTuple, BasicRequest){ - static_assert(std::is_same_v, std::tuple, std::string&, std::string&>>); +UTEST(OpenApiAsTuple, BasicRequest) +{ + static_assert( + std::is_same_v, + std::tuple, + std::string&, std::string&>>); SomeRequest some_req; auto result = AsTuple::Do(some_req); Get<0, 0>(result) = "first"; Get<0, 1>(result) = "second"; Get<1>(result) = "third"; Get<2>(result) = "fourth"; - //clang-format off + // clang-format off SomeRequest expected{ .body = {TestClass{ .test = {"first"}, @@ -110,6 +116,6 @@ UTEST(OpenApiAsTuple, BasicRequest){ .some_header = {"third"}, .some_cookie = {"fourth"} }; - //clang-format on + // clang-format on EXPECT_EQ(some_req, expected); } diff --git a/utests/openapi/raw/from_tuple.cpp b/utests/openapi/raw/from_tuple.cpp index 71fdc472..6a65751c 100644 --- a/utests/openapi/raw/from_tuple.cpp +++ b/utests/openapi/raw/from_tuple.cpp @@ -1,12 +1,12 @@ +#include #include #include +#include #include #include #include #include #include -#include "boost/pfr/core.hpp" -#include "openapi/from_tuple/default.hpp" using namespace openapi; @@ -27,7 +27,8 @@ struct TestClass } // namespace -UTEST(OpenApiFromTuple, BasicString){ +UTEST(OpenApiFromTuple, BasicString) +{ using T = String>; static_assert(std::is_same_v, std::string>); std::string raw = "value"; @@ -37,7 +38,8 @@ UTEST(OpenApiFromTuple, BasicString){ UTEST(OpenApiFromTuple, BasicStirngReflective) { - static_assert(std::is_same_v, std::tuple>); + static_assert( + std::is_same_v, std::tuple>); std::tuple tuple; std::get<0>(tuple) = "first"; std::get<1>(tuple) = "second"; @@ -46,19 +48,16 @@ UTEST(OpenApiFromTuple, BasicStirngReflective) EXPECT_EQ(result.value(), "second"); } -UTEST(OpenApiFromTuple, BasicArrayReflective){ +UTEST(OpenApiFromTuple, BasicArrayReflective) +{ using Raw = std::vector>; using T = Array>; - static_assert(std::is_same_v, std::vector>>); + static_assert( + std::is_same_v, + std::vector>>); T expected; - expected().emplace_back(TestClass{ - .test = {"first"}, - .value = {"second"} - }); - expected().emplace_back(TestClass{ - .test = {"third"}, - .value = {"fourth"} - }); + expected().emplace_back(TestClass{.test = {"first"}, .value = {"second"}}); + expected().emplace_back(TestClass{.test = {"third"}, .value = {"fourth"}}); Raw raw; raw.emplace_back(std::pair{"first", "second"}); raw.emplace_back(std::pair{"third", "fourth"}); @@ -70,8 +69,8 @@ UTEST(OpenApiFromTuple, BasicArrayReflective){ EXPECT_EQ(expected()[1].value(), got()[1].value()); } -namespace { - +namespace +{ struct TestClass2 { Object> some_field; @@ -87,24 +86,30 @@ struct SomeRequest }; template -decltype(auto) Get(auto&& tuple){ +decltype(auto) Get(auto&& tuple) +{ auto& head = std::get(tuple); - if constexpr (sizeof...(Indexes) != 0){ + if constexpr (sizeof...(Indexes) != 0) + { return Get(head); } - else { + else + { return head; } } -} +} // namespace -UTEST(OpenApiFromTuple, BasicRequest){ - static_assert(std::is_same_v, std::tuple, std::string, std::string>>); - std::tuple, std::string, std::string> tuple{ - {"first", "second"}, "third", "fourth" - }; - //clang-format off +UTEST(OpenApiFromTuple, BasicRequest) +{ + static_assert( + std::is_same_v, + std::tuple, + std::string, std::string>>); + std::tuple, std::string, std::string> + tuple{{"first", "second"}, "third", "fourth"}; + // clang-format off SomeRequest expected{ .body = {TestClass{ .test = {"first"}, @@ -113,7 +118,7 @@ UTEST(OpenApiFromTuple, BasicRequest){ .some_header = {"third"}, .some_cookie = {"fourth"} }; - //clang-format on + // clang-format on auto got = FromTuple::Do(tuple); EXPECT_EQ(expected, got); } diff --git a/utests/openapi/raw/to_tuple.cpp b/utests/openapi/raw/to_tuple.cpp index 6f36853f..f5c87c46 100644 --- a/utests/openapi/raw/to_tuple.cpp +++ b/utests/openapi/raw/to_tuple.cpp @@ -31,32 +31,30 @@ UTEST(OpenApiToTuple, BasicStirngReflective) test_class.test() = "first"; test_class.value() = "second"; auto result = ToTuple::Do(test_class); - static_assert(std::is_same_v, std::tuple>); + static_assert(std::is_same_v, + std::tuple>); EXPECT_EQ(std::get<0>(result), "first"); EXPECT_EQ(std::get<1>(result), "second"); } -UTEST(OpenApiToTuple, BasicArrayReflective){ +UTEST(OpenApiToTuple, BasicArrayReflective) +{ using T = Array>; T t; - t().emplace_back(TestClass{ - .test = {"first"}, - .value = {"second"} - }); - t().emplace_back(TestClass{ - .test = {"third"}, - .value = {"fourth"} - }); + t().emplace_back(TestClass{.test = {"first"}, .value = {"second"}}); + t().emplace_back(TestClass{.test = {"third"}, .value = {"fourth"}}); auto result = AsTuple::Do(t); - static_assert(std::is_same_v, std::vector>>); + static_assert( + std::is_same_v, + std::vector>>); EXPECT_EQ(std::get<0>(result[0]), "first"); EXPECT_EQ(std::get<1>(result[0]), "second"); EXPECT_EQ(std::get<0>(result[1]), "third"); EXPECT_EQ(std::get<1>(result[1]), "fourth"); } -namespace { - +namespace +{ struct TestClass2 { Object> some_field; @@ -72,21 +70,28 @@ struct SomeRequest }; template -decltype(auto) Get(auto&& tuple){ +decltype(auto) Get(auto&& tuple) +{ auto& head = std::get(tuple); - if constexpr (sizeof...(Indexes) != 0){ + if constexpr (sizeof...(Indexes) != 0) + { return Get(head); } - else { + else + { return head; } } -} +} // namespace -UTEST(OpenApiToTuple, BasicRequest){ - static_assert(std::is_same_v, std::tuple, std::string, std::string>>); - //clang-format off +UTEST(OpenApiToTuple, BasicRequest) +{ + static_assert( + std::is_same_v, + std::tuple, + std::string, std::string>>); + // clang-format off SomeRequest some_req{ .body = {TestClass{ .test = {"first"}, @@ -95,7 +100,7 @@ UTEST(OpenApiToTuple, BasicRequest){ .some_header = {"third"}, .some_cookie = {"fourth"} }; - //clang-format on + // clang-format on auto result = ToTuple::Do(some_req); auto first = Get<0, 0>(result); auto second = Get<0, 1>(result); diff --git a/utests/remove_namespace.cpp b/utests/remove_namespace.cpp index 14e9b0c9..b14218db 100644 --- a/utests/remove_namespace.cpp +++ b/utests/remove_namespace.cpp @@ -1,8 +1,9 @@ +#include #include -#include "openapi/doc/serialize/base.hpp" -UTEST(RemoveNamespace, Basic){ +UTEST(RemoveNamespace, Basic) +{ std::string test = "some_namespace::some_class"; ::openapi::RemoveNamespaces(test); EXPECT_EQ(test, "some_namespace.some_class"); -} \ No newline at end of file +}