Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ std::vector<Input> Action::getInputs() const
return EMPTY_INPUTS;
}

std::map<qttp::HttpStatus, QString> Action::getResponses() const
{
return {};
}

std::vector<QStringPair> Action::getHeaders() const
{
return Global::getDefaultHeaders();
Expand Down Expand Up @@ -251,6 +256,16 @@ std::vector<Input> SimpleAction::getInputs() const
return m_Inputs;
}

void SimpleAction::setResponses(const std::map<qttp::HttpStatus, QString>& responses)
{
m_Responses.insert(responses.begin(), responses.end());
}

std::map<qttp::HttpStatus, QString> SimpleAction::getResponses() const
{
return m_Responses;
}

std::vector<QStringPair> SimpleAction::getHeaders() const
{
return m_Headers;
Expand Down
9 changes: 9 additions & 0 deletions src/action.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef QTTPACTION_H
#define QTTPACTION_H

#include <map>

#include "qttp_global.h"
#include "httproute.h"
#include "httpdata.h"
Expand Down Expand Up @@ -60,6 +62,9 @@ class QTTPSHARED_EXPORT Action
//! The inputs help SwaggerUI include parameters.
virtual std::vector<Input> getInputs() const;

//! The possible responses of this action - used for SwaggerUI.
virtual std::map<qttp::HttpStatus, QString> 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<qttp::HttpPath>& routes, Visibility visibility = Visibility::Show);
Expand Down Expand Up @@ -118,6 +123,9 @@ class QTTPSHARED_EXPORT SimpleAction : public Action
void setInputs(const std::vector<Input>& inputs);
std::vector<Input> getInputs() const;

void setResponses(const std::map<qttp::HttpStatus, QString>& responses);
std::map<qttp::HttpStatus, QString> getResponses() const;

QTTP_PROTECTED:

std::vector<QStringPair> getHeaders() const;
Expand All @@ -131,6 +139,7 @@ class QTTPSHARED_EXPORT SimpleAction : public Action
QByteArray m_Description;
QStringList m_Tags;
std::vector<Input> m_Inputs;
std::map<qttp::HttpStatus, QString> m_Responses;
std::vector<QStringPair> m_Headers;
};

Expand Down
11 changes: 10 additions & 1 deletion src/swagger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(response.first)), QJsonObject {
{ "description", response.second }
});
}

QString actionName = action->getName();
const vector<Input> & inputs = action->getInputs();

Expand Down Expand Up @@ -216,7 +224,8 @@ void Swagger::initialize()
{ "description", action->getDescription() },
{ "operationId", routePath },
{ "parameters", routeParameters },
{ "tags", tags }
{ "tags", tags },
{ "responses", responses }
});
paths[routePath] = pathRoute;
}
Expand Down