From 0013875b3b93f66ad31f85b7467000d3039f83d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt-Alexander=20Mokro=C3=9F?= Date: Wed, 9 Oct 2019 11:40:13 +0200 Subject: [PATCH] Added `hide` to `Endpoint::Info` to hide endpoints from swagger (i.E. used in CORS-Macros for option-endpoints) --- src/oatpp/codegen/api_controller/cors_define.hpp | 5 +++++ src/oatpp/web/server/api/Endpoint.cpp | 2 +- src/oatpp/web/server/api/Endpoint.hpp | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/oatpp/codegen/api_controller/cors_define.hpp b/src/oatpp/codegen/api_controller/cors_define.hpp index b7542799..6b946e70 100644 --- a/src/oatpp/codegen/api_controller/cors_define.hpp +++ b/src/oatpp/codegen/api_controller/cors_define.hpp @@ -45,6 +45,7 @@ ENDPOINT_INTERCEPTOR(ENDPOINTNAME, CORS) { \ ) \ return resp; \ } \ +ENDPOINT_INFO(ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { info->hide = true; } \ ENDPOINT("OPTIONS", Z__ENDPOINT_##ENDPOINTNAME->info()->path, ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { \ auto resp = createResponse(Status::CODE_204, ""); \ OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY( \ @@ -67,6 +68,7 @@ ENDPOINT_INTERCEPTOR(ENDPOINTNAME, CORS) { \ ) \ return resp; \ } \ +ENDPOINT_INFO(ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { info->hide = true; } \ ENDPOINT("OPTIONS", Z__ENDPOINT_##ENDPOINTNAME->info()->path, ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { \ auto resp = createResponse(Status::CODE_204, ""); \ OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY( \ @@ -89,6 +91,7 @@ ENDPOINT_INTERCEPTOR(ENDPOINTNAME, CORS) { \ ) \ return resp; \ } \ +ENDPOINT_INFO(ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { info->hide = true; } \ ENDPOINT("OPTIONS", Z__ENDPOINT_##ENDPOINTNAME->info()->path, ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { \ auto resp = createResponse(Status::CODE_204, ""); \ OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY( \ @@ -111,6 +114,7 @@ ENDPOINT_INTERCEPTOR(ENDPOINTNAME, CORS) { \ ) \ return resp; \ } \ +ENDPOINT_INFO(ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { info->hide = true; } \ ENDPOINT("OPTIONS", Z__ENDPOINT_##ENDPOINTNAME->info()->path, ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { \ auto resp = createResponse(Status::CODE_204, ""); \ OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY( \ @@ -128,6 +132,7 @@ ENDPOINT_INTERCEPTOR(ENDPOINTNAME, CORS) { \ OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY(ORIGIN, METHODS, HEADERS, MAX_AGE) \ return resp; \ } \ +ENDPOINT_INFO(ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { info->hide = true; } \ ENDPOINT("OPTIONS", Z__ENDPOINT_##ENDPOINTNAME->info()->path, ZZ__CORS_OPTIONS_ENDPOINT_##ENDPOINTNAME) { \ auto resp = createResponse(Status::CODE_204, ""); \ OATPP_MACRO_API_CONTROLLER_ADDCORS_BODY(ORIGIN, METHODS, HEADERS, MAX_AGE) \ diff --git a/src/oatpp/web/server/api/Endpoint.cpp b/src/oatpp/web/server/api/Endpoint.cpp index 399b7417..7ad78333 100644 --- a/src/oatpp/web/server/api/Endpoint.cpp +++ b/src/oatpp/web/server/api/Endpoint.cpp @@ -55,7 +55,7 @@ Endpoint::Info::Param& Endpoint::Info::Params::operator [](const oatpp::String& return m_params[name]; } -Endpoint::Info::Info() +Endpoint::Info::Info() : hide(false) {} std::shared_ptr Endpoint::Info::createShared(){ diff --git a/src/oatpp/web/server/api/Endpoint.hpp b/src/oatpp/web/server/api/Endpoint.hpp index 425a950e..3982007a 100644 --- a/src/oatpp/web/server/api/Endpoint.hpp +++ b/src/oatpp/web/server/api/Endpoint.hpp @@ -128,6 +128,7 @@ public: oatpp::String path; oatpp::String method; oatpp::String authorization; + oatpp::Boolean hide; Param body; oatpp::String bodyContentType;