Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
sabudilovskiy committed Apr 11, 2024
1 parent 5eb2327 commit 5533aac
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 16 deletions.
18 changes: 10 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@ set(CMAKE_CXX_STANDARD 20)

set(openapi-extension-userver_BUILD_UNIT_TESTS false)
set(openapi-extension-userver_BUILD_TEST_SERVICES false)
set(USERVER_LTO OFF)

add_subdirectory(uopenapi)

include(uopenapi/CMake/CreatePart.cmake)
set(USERVER_FEATURE_POSTGRESQL ON)

enable_testing()
include(FetchContent)
FetchContent_Declare(
uopenapi
GIT_REPOSITORY https://github.com/sabudilovskiy/userver-openapi-extension
GIT_TAG "26b3160c9a3317fe15b7c569de70f1e3fbc70592"
)
FetchContent_MakeAvailable(uopenapi)

CreateTrivialPart(
name "src"
path "/src"
)

target_link_libraries(${src_module} PUBLIC openapi-extension-userver_library)
target_link_libraries(${src_module} PUBLIC userver-postgresql)
target_compile_options(${src_module} PUBLIC "-Wno-missing-field-initializers")

add_executable(service service/main.cpp)

target_link_libraries(service PUBLIC ${src_module})

include(uopenapi/userver/cmake/UserverTestsuite.cmake)
SET(USERVER_PYTHON "python3")
userver_testsuite_add_simple()
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ find-c-compiler:

.PHONY: format
format:
python3.10 uopenapi/scripts/generate_all_headers.py library/uopenapi uopenapi
python3.10 uopenapi/scripts/format_includes.py library boost uopenapi checks
python3.10 scripts/format_includes.py library boost uopenapi checks
find checks -name '*pp' -type f | xargs clang-format-17 -i
find library -name '*pp' -type f | xargs clang-format-17 -i
make add-eol P=tests
Expand Down
56 changes: 56 additions & 0 deletions scripts/format_includes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import sys

def check_line(line: str, words):
index_include: int = line.find("#include")
if index_include == -1:
return False
index_include += len('#include')
line_after_include = line[index_include:]
index: int = line_after_include.find("\"") + 1
if (index == 0):
return False
file = line_after_include[index:]
for word in words:
if (file.startswith(word)):
return True
return False


def format_line(line: str):
return line.replace("\"", "<", 1).replace("\"", ">", 1)



def format_file(input_path, words):
with open(input_path, 'r') as file:
content = file.readlines()

formatted_content = []
for line in content:
if check_line(line, words):
formatted_content.append(format_line(line))
else:
formatted_content.append(line)

with open(input_path, 'w') as file:
file.writelines(formatted_content)

def format_directory(directory, words):
for root, _, files in os.walk(directory):
for file_name in files:
if file_name.endswith(('.hpp', '.cpp')):
file_path = os.path.join(root, file_name)
format_file(file_path, words)
def main():
if len(sys.argv) < 3:
print('Usage: python3 format_includes.py <directory> start_words...')
return

input_path = sys.argv[1]
words = sys.argv[2:]
format_directory(input_path, words)


if __name__ == '__main__':
main()
6 changes: 4 additions & 2 deletions service/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include <userver/utils/daemon_run.hpp>
#include <views/login/handler_fwd.hpp>
#include <views/register/handler_fwd.hpp>
#include <uopenapi/http/openapi_descriptor.h>
#include <uopenapi/components/schema/schema_storage.hpp>
#include <uopenapi/components/schema/schema_http_distributor.hpp>
#include <userver/storages/postgres/component.hpp>

int main(int argc, char* argv[]) {
Expand All @@ -17,7 +18,8 @@ int main(int argc, char* argv[]) {
.Append<userver::components::HttpClient>()
.Append<userver::clients::dns::Component>()
.Append<userver::server::handlers::TestsControl>();
component_list.Append<uopenapi::http::openapi_descriptor>();
component_list.Append<uopenapi::components::schema_storage>();
component_list.Append<uopenapi::components::schema_http_distributor>();
component_list.Append<userver::components::Postgres>("todo_db");
views::login::Append(component_list);
views::Register::Append(component_list);
Expand Down
2 changes: 1 addition & 1 deletion src/models/error_response.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <string>
#include <uopenapi/enum/declare.hpp>
#include <uopenapi/enum_helpers/declare.hpp>

namespace models{
UOPENAPI_DECLARE_ENUM(ErrorCode,
Expand Down
2 changes: 1 addition & 1 deletion src/views/login/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <userver/formats/serialize/boost_uuid.hpp>

namespace views::login{
using base = uopenapi::http::openapi_handler<Request,Response200,Response400 >;
using base = uopenapi::components::openapi_handler<Request,Response200,Response400 >;
struct handler : base{
static constexpr std::string_view kName = "login_handler";
handler(const userver::components::ComponentConfig& cfg,
Expand Down
2 changes: 1 addition & 1 deletion src/views/register/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <userver/formats/serialize/boost_uuid.hpp>

namespace views::Register{
using base = uopenapi::http::openapi_handler<Request,Response200,Response400 >;
using base = uopenapi::components::openapi_handler<Request,Response200,Response400 >;
struct handler : base{
static constexpr std::string_view kName = "register_handler";
handler(const userver::components::ComponentConfig& cfg,
Expand Down
1 change: 0 additions & 1 deletion uopenapi
Submodule uopenapi deleted from 87b98f

0 comments on commit 5533aac

Please sign in to comment.