oatpp / oatpp-swagger

OpenApi 3.0.0 docs + Swagger UI for oatpp services
https://oatpp.io/
Apache License 2.0
95 stars 54 forks source link

Added possibility to customize the path to the Swagger UI #58

Closed EDDragonWolf closed 2 years ago

EDDragonWolf commented 2 years ago

Proposal: I think it'll be a useful option to allow changing the default Swagger UI path (/swagger/ui) during the server configuration.

Usage example:

#define SWAGGER_ROOT_PATH "/"
#define SWAGGER_UI_PATH ""
#include "oatpp-swagger/Controller.hpp"

...

router->addController(oatpp::swagger::Controller::createShared(docEndpoints));
bamkrs commented 2 years ago

Yeah, nice idea. However, I would propose setting those defines via cmake cache-variables so they are easy to set and handle.

EDDragonWolf commented 2 years ago

Do you mean to add their definitions to the CMakeList.txt file and remove it from the header files?

For example, add something like this

add_compile_definitions(
    # Default root path to the Swagger
    SWAGGER_ROOT_PATH="/swagger"
    # Default path suffix to the Swagger UI
    SWAGGER_UI_PATH="/ui"
)

and remove

#ifndef SWAGGER_ROOT_PATH
#define SWAGGER_ROOT_PATH "/swagger"
#endif
#ifndef SWAGGER_UI_PATH
#define SWAGGER_UI_PATH "/ui"
#endif
bamkrs commented 2 years ago

Yes, and have the paths be set as a cached variable so they behave like cmake-options.

https://stackoverflow.com/questions/8709877/cmake-string-options

EDDragonWolf commented 2 years ago

Added, please, take a look