Work-around openapi-ts issue

This commit is contained in:
Martin Raiber 2025-02-25 22:29:28 +01:00
parent 404f10cf86
commit 30340919ba
18 changed files with 227 additions and 17 deletions

View File

@ -11,17 +11,18 @@ add_custom_command(
)
set(APIGEN_SCHEMAS
AddUserParams
LoginParams
LoginResp
HapiError
AddUserParams
AddUserResp
LoginParams
LoginResp
ListParams
ListResp
EmptyParams
AddBucketParams
EmptyResp # Must be last
)
AddBucketResp
SessionCheckParams
SessionCheckResp # Must be last
)
add_custom_target(apigen)

View File

@ -17,8 +17,8 @@
#include "apigen/GeneratorsHapiError.hpp"
#include "apigen/GeneratorsListResp.hpp"
#include "apigen/GeneratorsListParams.hpp"
#include "apigen/GeneratorsEmptyParams.hpp"
#include "apigen/GeneratorsEmptyResp.hpp"
#include "apigen/GeneratorsSessionCheckResp.hpp"
#include "apigen/GeneratorsAddBucketResp.hpp"
#include "apigen/GeneratorsAddBucketParams.hpp"
#include <argon2.h>
#include <folly/Random.h>
@ -305,7 +305,7 @@ ApiHandler::ApiResponse ApiHandler::runRequest()
else if(func=="list")
resp = list(params, *session);
else if(func=="sessionCheck")
resp = Api::EmptyResp();
resp = Api::SessionCheckResp();
else if(func=="addBucket")
resp = addBucket(params, *session);
}
@ -509,7 +509,7 @@ Api::ListResp ApiHandler::listBuckets(const Api::ListParams& params, const ApiSe
return buckets::getBucketNames();
}
Api::EmptyResp ApiHandler::addBucket(const Api::AddBucketParams& params, const ApiSessionStorage& sessionStorage)
Api::AddBucketResp ApiHandler::addBucket(const Api::AddBucketParams& params, const ApiSessionStorage& sessionStorage)
{
if(params.bucketName.empty())
throw ApiError(Api::Herror::invalidParameters);;

View File

@ -12,7 +12,7 @@
#include "apigen/HapiError.hpp"
#include "apigen/ListResp.hpp"
#include "apigen/ListParams.hpp"
#include "apigen/EmptyResp.hpp"
#include "apigen/AddBucketResp.hpp"
#include "apigen/AddBucketParams.hpp"
#include "Session.h"
#include <proxygen/httpserver/RequestHandler.h>
@ -56,7 +56,7 @@ private:
std::pair<Api::LoginResp, std::string> login(const Api::LoginParams& params);
Api::ListResp list(const Api::ListParams& params, const ApiSessionStorage& sessionStorage);
Api::ListResp listBuckets(const Api::ListParams& params, const ApiSessionStorage& sessionStorage);
Api::EmptyResp addBucket(const Api::AddBucketParams& params, const ApiSessionStorage& sessionStorage);
Api::AddBucketResp addBucket(const Api::AddBucketParams& params, const ApiSessionStorage& sessionStorage);
std::string func;
std::string body;

View File

@ -73,14 +73,14 @@ paths:
content:
application/json:
schema:
$ref: 'schemas/EmptyParams.json'
$ref: 'schemas/SessionCheckParams.json'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: 'schemas/EmptyResp.json'
$ref: 'schemas/SessionCheckResp.json'
'400':
description: Error
content:
@ -101,7 +101,7 @@ paths:
content:
application/json:
schema:
$ref: 'schemas/EmptyResp.json'
$ref: 'schemas/AddBucketResp.json'
'400':
description: Error
content:

View File

@ -0,0 +1,17 @@
// To parse this JSON data, first install
//
// json.hpp https://github.com/nlohmann/json
//
// Then include this file, and then do
//
// AddBucketResp.cpp data = nlohmann::json::parse(jsonString);
#pragma once
#include <optional>
#include <nlohmann/json.hpp>
#include "helper.hpp"
#include "AddBucketResp.hpp"
namespace Api {
}

View File

@ -0,0 +1,21 @@
// To parse this JSON data, first install
//
// json.hpp https://github.com/nlohmann/json
//
// Then include this file, and then do
//
// AddBucketResp.hpp data = nlohmann::json::parse(jsonString);
#pragma once
#include <optional>
#include <nlohmann/json.hpp>
#include "helper.hpp"
namespace Api {
using nlohmann::json;
struct AddBucketResp {
std::optional<std::string> dummy;
};
}

View File

@ -0,0 +1,29 @@
// To parse this JSON data, first install
//
// json.hpp https://github.com/nlohmann/json
//
// Then include this file, and then do
//
// Generators.hpp data = nlohmann::json::parse(jsonString);
#pragma once
#include <optional>
#include <nlohmann/json.hpp>
#include "helper.hpp"
#include "AddBucketResp.hpp"
namespace Api {
void from_json(const json & j, AddBucketResp & x);
void to_json(json & j, const AddBucketResp & x);
inline void from_json(const json & j, AddBucketResp& x) {
x.dummy = get_stack_optional<std::string>(j, "dummy");
}
inline void to_json(json & j, const AddBucketResp & x) {
j = json::object();
j["dummy"] = x.dummy;
}
}

View File

@ -0,0 +1,28 @@
// To parse this JSON data, first install
//
// json.hpp https://github.com/nlohmann/json
//
// Then include this file, and then do
//
// Generators.hpp data = nlohmann::json::parse(jsonString);
#pragma once
#include <nlohmann/json.hpp>
#include "helper.hpp"
#include "SessionCheckParams.hpp"
namespace Api {
void from_json(const json & j, SessionCheckParams & x);
void to_json(json & j, const SessionCheckParams & x);
inline void from_json(const json & j, SessionCheckParams& x) {
x.ses = j.at("ses").get<std::string>();
}
inline void to_json(json & j, const SessionCheckParams & x) {
j = json::object();
j["ses"] = x.ses;
}
}

View File

@ -0,0 +1,29 @@
// To parse this JSON data, first install
//
// json.hpp https://github.com/nlohmann/json
//
// Then include this file, and then do
//
// Generators.hpp data = nlohmann::json::parse(jsonString);
#pragma once
#include <optional>
#include <nlohmann/json.hpp>
#include "helper.hpp"
#include "SessionCheckResp.hpp"
namespace Api {
void from_json(const json & j, SessionCheckResp & x);
void to_json(json & j, const SessionCheckResp & x);
inline void from_json(const json & j, SessionCheckResp& x) {
x.dummy = get_stack_optional<std::string>(j, "dummy");
}
inline void to_json(json & j, const SessionCheckResp & x) {
j = json::object();
j["dummy"] = x.dummy;
}
}

View File

@ -0,0 +1,16 @@
// To parse this JSON data, first install
//
// json.hpp https://github.com/nlohmann/json
//
// Then include this file, and then do
//
// SessionCheckParams.cpp data = nlohmann::json::parse(jsonString);
#pragma once
#include <nlohmann/json.hpp>
#include "helper.hpp"
#include "SessionCheckParams.hpp"
namespace Api {
}

View File

@ -0,0 +1,20 @@
// To parse this JSON data, first install
//
// json.hpp https://github.com/nlohmann/json
//
// Then include this file, and then do
//
// SessionCheckParams.hpp data = nlohmann::json::parse(jsonString);
#pragma once
#include <nlohmann/json.hpp>
#include "helper.hpp"
namespace Api {
using nlohmann::json;
struct SessionCheckParams {
std::string ses;
};
}

View File

@ -0,0 +1,17 @@
// To parse this JSON data, first install
//
// json.hpp https://github.com/nlohmann/json
//
// Then include this file, and then do
//
// SessionCheckResp.cpp data = nlohmann::json::parse(jsonString);
#pragma once
#include <optional>
#include <nlohmann/json.hpp>
#include "helper.hpp"
#include "SessionCheckResp.hpp"
namespace Api {
}

View File

@ -0,0 +1,21 @@
// To parse this JSON data, first install
//
// json.hpp https://github.com/nlohmann/json
//
// Then include this file, and then do
//
// SessionCheckResp.hpp data = nlohmann::json::parse(jsonString);
#pragma once
#include <optional>
#include <nlohmann/json.hpp>
#include "helper.hpp"
namespace Api {
using nlohmann::json;
struct SessionCheckResp {
std::optional<std::string> dummy;
};
}

View File

@ -0,0 +1,9 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"dummy": {
"type": "string"
}
}
}

View File

@ -66,7 +66,7 @@ export const postApiV1B64Be5124B034028A58913931942E205List = (data: PostApiV1B64
* Check if session is ok
* @param data The data for the request.
* @param data.requestBody
* @returns __paths__1api_v1_b64be512_4b03_4028_a589_13931942e205_1addBucket_post_responses_200_content_application_1json_schema OK
* @returns unknown OK
* @throws ApiError
*/
export const postApiV1B64Be5124B034028A58913931942E205SessionCheck = (data: PostApiV1B64Be5124B034028A58913931942E205SessionCheckData = {}): CancelablePromise<PostApiV1B64Be5124B034028A58913931942E205SessionCheckResponse> => {

View File

@ -49,7 +49,9 @@ export type PostApiV1B64Be5124B034028A58913931942E205SessionCheckData = {
};
};
export type PostApiV1B64Be5124B034028A58913931942E205SessionCheckResponse = (__paths__1api_v1_b64be512_4b03_4028_a589_13931942e205_1addBucket_post_responses_200_content_application_1json_schema);
export type PostApiV1B64Be5124B034028A58913931942E205SessionCheckResponse = ({
dummy?: string;
});
export type PostApiV1B64Be5124B034028A58913931942E205AddBucketData = {
requestBody?: {