diff --git a/src/action.cpp b/src/action.cpp index 7c7fb3cb..f5cf00c1 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -139,6 +139,11 @@ std::vector Action::getInputs() const return EMPTY_INPUTS; } +std::map Action::getResponses() const +{ + return {}; +} + std::vector Action::getHeaders() const { return Global::getDefaultHeaders(); @@ -251,6 +256,16 @@ std::vector SimpleAction::getInputs() const return m_Inputs; } +void SimpleAction::setResponses(const std::map& responses) +{ + m_Responses.insert(responses.begin(), responses.end()); +} + +std::map SimpleAction::getResponses() const +{ + return m_Responses; +} + std::vector SimpleAction::getHeaders() const { return m_Headers; diff --git a/src/action.h b/src/action.h index 7630c6c6..ccb1a419 100644 --- a/src/action.h +++ b/src/action.h @@ -1,6 +1,8 @@ #ifndef QTTPACTION_H #define QTTPACTION_H +#include + #include "qttp_global.h" #include "httproute.h" #include "httpdata.h" @@ -60,6 +62,9 @@ class QTTPSHARED_EXPORT Action //! The inputs help SwaggerUI include parameters. virtual std::vector getInputs() const; + //! The possible responses of this action - used for SwaggerUI. + virtual std::map getResponses() const; + bool registerRoute(HttpMethod method, const QString& path, Visibility visibility = Visibility::Show); bool registerRoute(const qttp::HttpPath& path, Visibility visibility = Visibility::Show); void registerRoute(const std::vector& routes, Visibility visibility = Visibility::Show); @@ -118,6 +123,9 @@ class QTTPSHARED_EXPORT SimpleAction : public Action void setInputs(const std::vector& inputs); std::vector getInputs() const; + void setResponses(const std::map& responses); + std::map getResponses() const; + QTTP_PROTECTED: std::vector getHeaders() const; @@ -131,6 +139,7 @@ class QTTPSHARED_EXPORT SimpleAction : public Action QByteArray m_Description; QStringList m_Tags; std::vector m_Inputs; + std::map m_Responses; std::vector m_Headers; }; diff --git a/src/swagger.cpp b/src/swagger.cpp index f409577f..a2c6fcce 100644 --- a/src/swagger.cpp +++ b/src/swagger.cpp @@ -84,6 +84,14 @@ void Swagger::initialize() QJsonArray required; QJsonArray tags = QJsonArray::fromStringList(action->getTags()); + QJsonObject responses; + for(auto response : action->getResponses()) + { + responses.insert(QString::number(static_cast(response.first)), QJsonObject { + { "description", response.second } + }); + } + QString actionName = action->getName(); const vector & inputs = action->getInputs(); @@ -216,7 +224,8 @@ void Swagger::initialize() { "description", action->getDescription() }, { "operationId", routePath }, { "parameters", routeParameters }, - { "tags", tags } + { "tags", tags }, + { "responses", responses } }); paths[routePath] = pathRoute; }