Skip to content
Merged
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
32 changes: 29 additions & 3 deletions App/Server/OpenAPIGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,34 @@ QJsonObject initializeObject(const QString &_host = "127.0.0.1", const quint16 _

QJsonObject OpenAPIGenerator::retrieveJson(
const QString &_host,
const quint16 _port
const quint16 _port,
const QString &_module
) {
auto FnFilterPaths = [&_module](const QJsonObject &_openApiInfo) -> QJsonObject {
if (_module.isEmpty())
return _openApiInfo;

QJsonObject OpenApiInfo = _openApiInfo;

QJsonObject Paths = OpenApiInfo["paths"].toObject();
QJsonObject OutPaths;

QString ModulePath = "/" + _module + "/";
for (auto it = Paths.constBegin();
it != Paths.constEnd();
it++
) {
if (it.key().startsWith(ModulePath) == false)
continue;

OutPaths[it.key()] = it.value();
}

OpenApiInfo["paths"] = OutPaths;

return OpenApiInfo;
};

if (OpenAPIGenerator::CachedJson.isEmpty() == false) {
QJsonObject Return = OpenAPIGenerator::CachedJson;

Expand All @@ -93,7 +119,7 @@ QJsonObject OpenAPIGenerator::retrieveJson(

Return["host"] = HostPort;

return Return;
return FnFilterPaths(Return);
}

OpenAPIGenerator::CachedJson = initializeObject(_host, _port);
Expand Down Expand Up @@ -592,7 +618,7 @@ QJsonObject OpenAPIGenerator::retrieveJson(
OpenAPIGenerator::CachedJson["paths"] = PathsObject;
//OpenAPIGenerator::CachedJson["tags"] = TagsArray;

return OpenAPIGenerator::CachedJson;
return FnFilterPaths(OpenAPIGenerator::CachedJson);
}

} //namespace Targoman::API::Server
6 changes: 5 additions & 1 deletion App/Server/OpenAPIGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ namespace Targoman::API::Server {
class OpenAPIGenerator
{
public:
static QJsonObject retrieveJson(const QString& _host = "127.0.0.1", const quint16 _port = 80);
static QJsonObject retrieveJson(
const QString& _host = "127.0.0.1",
const quint16 _port = 80,
const QString &_module = {}
);

private:
static QJsonObject CachedJson;
Expand Down
6 changes: 4 additions & 2 deletions App/Server/StaticModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ StaticModule::StaticModule() :
{ ; }

TAPI::RawData_t IMPL_REST_GET_OR_POST(StaticModule, openAPI_json, (
APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM
APICALLBOOM_TYPE_JWT_ANONYMOUSE_IMPL &APICALLBOOM_PARAM,
const QString &_module
)) {
gServerStats.Success.inc();

return TAPI::RawData_t(
QJsonDocument(OpenAPIGenerator::retrieveJson(
APICALLBOOM_PARAM.host(),
APICALLBOOM_PARAM.port()
APICALLBOOM_PARAM.port(),
_module
)).toJson(QJsonDocument::Compact),
"application/json; charset=utf-8"
);
Expand Down
3 changes: 2 additions & 1 deletion App/Server/StaticModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ private slots:
TAPI::RawData_t EXREST_GET_OR_POST(
openAPI_json,
(
APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM
APICALLBOOM_TYPE_JWT_ANONYMOUSE_DECL &APICALLBOOM_PARAM,
const QString &_module = {}
),
"",
{
Expand Down
10 changes: 10 additions & 0 deletions App/Server/clsRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,16 @@ quint16 clsRequestHandler::port() const

void clsRequestHandler::findAndCallAPI(QString _api) {
QStringList Queries = this->Request->url().query().split('&', QString::SkipEmptyParts);
QStringList PathParts = _api.split('/', QString::SkipEmptyParts);

//auto route to StaticModule::openAPI_json with module parameter
if ((PathParts.length() == 2) && (PathParts.last() == "openAPI.json")) {
Queries.append(QString("module=%1").arg(PathParts.first()));

PathParts.removeFirst();

_api = '/' + PathParts.join('/');
}

QString ExtraAPIPath;
QString MethodString = this->Request->methodString();
Expand Down