Skip to content

Commit 3034091

Browse files
committed
Work-around openapi-ts issue
1 parent 404f10c commit 3034091

18 files changed

+227
-17
lines changed

CMakeLists.txt

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ add_custom_command(
1111
)
1212

1313
set(APIGEN_SCHEMAS
14-
AddUserParams
15-
LoginParams
16-
LoginResp
1714
HapiError
15+
AddUserParams
1816
AddUserResp
17+
LoginParams
18+
LoginResp
1919
ListParams
2020
ListResp
21-
EmptyParams
2221
AddBucketParams
23-
EmptyResp # Must be last
24-
)
22+
AddBucketResp
23+
SessionCheckParams
24+
SessionCheckResp # Must be last
25+
)
2526

2627

2728
add_custom_target(apigen)

src/ApiHandler.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include "apigen/GeneratorsHapiError.hpp"
1818
#include "apigen/GeneratorsListResp.hpp"
1919
#include "apigen/GeneratorsListParams.hpp"
20-
#include "apigen/GeneratorsEmptyParams.hpp"
21-
#include "apigen/GeneratorsEmptyResp.hpp"
20+
#include "apigen/GeneratorsSessionCheckResp.hpp"
21+
#include "apigen/GeneratorsAddBucketResp.hpp"
2222
#include "apigen/GeneratorsAddBucketParams.hpp"
2323
#include <argon2.h>
2424
#include <folly/Random.h>
@@ -305,7 +305,7 @@ ApiHandler::ApiResponse ApiHandler::runRequest()
305305
else if(func=="list")
306306
resp = list(params, *session);
307307
else if(func=="sessionCheck")
308-
resp = Api::EmptyResp();
308+
resp = Api::SessionCheckResp();
309309
else if(func=="addBucket")
310310
resp = addBucket(params, *session);
311311
}
@@ -509,7 +509,7 @@ Api::ListResp ApiHandler::listBuckets(const Api::ListParams& params, const ApiSe
509509
return buckets::getBucketNames();
510510
}
511511

512-
Api::EmptyResp ApiHandler::addBucket(const Api::AddBucketParams& params, const ApiSessionStorage& sessionStorage)
512+
Api::AddBucketResp ApiHandler::addBucket(const Api::AddBucketParams& params, const ApiSessionStorage& sessionStorage)
513513
{
514514
if(params.bucketName.empty())
515515
throw ApiError(Api::Herror::invalidParameters);;

src/ApiHandler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "apigen/HapiError.hpp"
1313
#include "apigen/ListResp.hpp"
1414
#include "apigen/ListParams.hpp"
15-
#include "apigen/EmptyResp.hpp"
15+
#include "apigen/AddBucketResp.hpp"
1616
#include "apigen/AddBucketParams.hpp"
1717
#include "Session.h"
1818
#include <proxygen/httpserver/RequestHandler.h>
@@ -56,7 +56,7 @@ class ApiHandler : public proxygen::RequestHandler
5656
std::pair<Api::LoginResp, std::string> login(const Api::LoginParams& params);
5757
Api::ListResp list(const Api::ListParams& params, const ApiSessionStorage& sessionStorage);
5858
Api::ListResp listBuckets(const Api::ListParams& params, const ApiSessionStorage& sessionStorage);
59-
Api::EmptyResp addBucket(const Api::AddBucketParams& params, const ApiSessionStorage& sessionStorage);
59+
Api::AddBucketResp addBucket(const Api::AddBucketParams& params, const ApiSessionStorage& sessionStorage);
6060

6161
std::string func;
6262
std::string body;

src/api.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ paths:
7373
content:
7474
application/json:
7575
schema:
76-
$ref: 'schemas/EmptyParams.json'
76+
$ref: 'schemas/SessionCheckParams.json'
7777
responses:
7878
'200':
7979
description: OK
8080
content:
8181
application/json:
8282
schema:
83-
$ref: 'schemas/EmptyResp.json'
83+
$ref: 'schemas/SessionCheckResp.json'
8484
'400':
8585
description: Error
8686
content:
@@ -101,7 +101,7 @@ paths:
101101
content:
102102
application/json:
103103
schema:
104-
$ref: 'schemas/EmptyResp.json'
104+
$ref: 'schemas/AddBucketResp.json'
105105
'400':
106106
description: Error
107107
content:

src/apigen/AddBucketResp.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// To parse this JSON data, first install
2+
//
3+
// json.hpp https://github.com/nlohmann/json
4+
//
5+
// Then include this file, and then do
6+
//
7+
// AddBucketResp.cpp data = nlohmann::json::parse(jsonString);
8+
9+
#pragma once
10+
11+
#include <optional>
12+
#include <nlohmann/json.hpp>
13+
#include "helper.hpp"
14+
15+
#include "AddBucketResp.hpp"
16+
namespace Api {
17+
}

src/apigen/AddBucketResp.hpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// To parse this JSON data, first install
2+
//
3+
// json.hpp https://github.com/nlohmann/json
4+
//
5+
// Then include this file, and then do
6+
//
7+
// AddBucketResp.hpp data = nlohmann::json::parse(jsonString);
8+
9+
#pragma once
10+
11+
#include <optional>
12+
#include <nlohmann/json.hpp>
13+
#include "helper.hpp"
14+
15+
namespace Api {
16+
using nlohmann::json;
17+
18+
struct AddBucketResp {
19+
std::optional<std::string> dummy;
20+
};
21+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// To parse this JSON data, first install
2+
//
3+
// json.hpp https://github.com/nlohmann/json
4+
//
5+
// Then include this file, and then do
6+
//
7+
// Generators.hpp data = nlohmann::json::parse(jsonString);
8+
9+
#pragma once
10+
11+
#include <optional>
12+
#include <nlohmann/json.hpp>
13+
#include "helper.hpp"
14+
15+
#include "AddBucketResp.hpp"
16+
17+
namespace Api {
18+
void from_json(const json & j, AddBucketResp & x);
19+
void to_json(json & j, const AddBucketResp & x);
20+
21+
inline void from_json(const json & j, AddBucketResp& x) {
22+
x.dummy = get_stack_optional<std::string>(j, "dummy");
23+
}
24+
25+
inline void to_json(json & j, const AddBucketResp & x) {
26+
j = json::object();
27+
j["dummy"] = x.dummy;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// To parse this JSON data, first install
2+
//
3+
// json.hpp https://github.com/nlohmann/json
4+
//
5+
// Then include this file, and then do
6+
//
7+
// Generators.hpp data = nlohmann::json::parse(jsonString);
8+
9+
#pragma once
10+
11+
#include <nlohmann/json.hpp>
12+
#include "helper.hpp"
13+
14+
#include "SessionCheckParams.hpp"
15+
16+
namespace Api {
17+
void from_json(const json & j, SessionCheckParams & x);
18+
void to_json(json & j, const SessionCheckParams & x);
19+
20+
inline void from_json(const json & j, SessionCheckParams& x) {
21+
x.ses = j.at("ses").get<std::string>();
22+
}
23+
24+
inline void to_json(json & j, const SessionCheckParams & x) {
25+
j = json::object();
26+
j["ses"] = x.ses;
27+
}
28+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// To parse this JSON data, first install
2+
//
3+
// json.hpp https://github.com/nlohmann/json
4+
//
5+
// Then include this file, and then do
6+
//
7+
// Generators.hpp data = nlohmann::json::parse(jsonString);
8+
9+
#pragma once
10+
11+
#include <optional>
12+
#include <nlohmann/json.hpp>
13+
#include "helper.hpp"
14+
15+
#include "SessionCheckResp.hpp"
16+
17+
namespace Api {
18+
void from_json(const json & j, SessionCheckResp & x);
19+
void to_json(json & j, const SessionCheckResp & x);
20+
21+
inline void from_json(const json & j, SessionCheckResp& x) {
22+
x.dummy = get_stack_optional<std::string>(j, "dummy");
23+
}
24+
25+
inline void to_json(json & j, const SessionCheckResp & x) {
26+
j = json::object();
27+
j["dummy"] = x.dummy;
28+
}
29+
}

src/apigen/SessionCheckParams.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// To parse this JSON data, first install
2+
//
3+
// json.hpp https://github.com/nlohmann/json
4+
//
5+
// Then include this file, and then do
6+
//
7+
// SessionCheckParams.cpp data = nlohmann::json::parse(jsonString);
8+
9+
#pragma once
10+
11+
#include <nlohmann/json.hpp>
12+
#include "helper.hpp"
13+
14+
#include "SessionCheckParams.hpp"
15+
namespace Api {
16+
}

src/apigen/SessionCheckParams.hpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// To parse this JSON data, first install
2+
//
3+
// json.hpp https://github.com/nlohmann/json
4+
//
5+
// Then include this file, and then do
6+
//
7+
// SessionCheckParams.hpp data = nlohmann::json::parse(jsonString);
8+
9+
#pragma once
10+
11+
#include <nlohmann/json.hpp>
12+
#include "helper.hpp"
13+
14+
namespace Api {
15+
using nlohmann::json;
16+
17+
struct SessionCheckParams {
18+
std::string ses;
19+
};
20+
}

src/apigen/SessionCheckResp.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// To parse this JSON data, first install
2+
//
3+
// json.hpp https://github.com/nlohmann/json
4+
//
5+
// Then include this file, and then do
6+
//
7+
// SessionCheckResp.cpp data = nlohmann::json::parse(jsonString);
8+
9+
#pragma once
10+
11+
#include <optional>
12+
#include <nlohmann/json.hpp>
13+
#include "helper.hpp"
14+
15+
#include "SessionCheckResp.hpp"
16+
namespace Api {
17+
}

src/apigen/SessionCheckResp.hpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// To parse this JSON data, first install
2+
//
3+
// json.hpp https://github.com/nlohmann/json
4+
//
5+
// Then include this file, and then do
6+
//
7+
// SessionCheckResp.hpp data = nlohmann::json::parse(jsonString);
8+
9+
#pragma once
10+
11+
#include <optional>
12+
#include <nlohmann/json.hpp>
13+
#include "helper.hpp"
14+
15+
namespace Api {
16+
using nlohmann::json;
17+
18+
struct SessionCheckResp {
19+
std::optional<std::string> dummy;
20+
};
21+
}
File renamed without changes.
File renamed without changes.

src/schemas/SessionCheckResp.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"properties": {
5+
"dummy": {
6+
"type": "string"
7+
}
8+
}
9+
}

www/src/api/sdk.gen.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const postApiV1B64Be5124B034028A58913931942E205List = (data: PostApiV1B64
6666
* Check if session is ok
6767
* @param data The data for the request.
6868
* @param data.requestBody
69-
* @returns __paths__1api_v1_b64be512_4b03_4028_a589_13931942e205_1addBucket_post_responses_200_content_application_1json_schema OK
69+
* @returns unknown OK
7070
* @throws ApiError
7171
*/
7272
export const postApiV1B64Be5124B034028A58913931942E205SessionCheck = (data: PostApiV1B64Be5124B034028A58913931942E205SessionCheckData = {}): CancelablePromise<PostApiV1B64Be5124B034028A58913931942E205SessionCheckResponse> => {

www/src/api/types.gen.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export type PostApiV1B64Be5124B034028A58913931942E205SessionCheckData = {
4949
};
5050
};
5151

52-
export type PostApiV1B64Be5124B034028A58913931942E205SessionCheckResponse = (__paths__1api_v1_b64be512_4b03_4028_a589_13931942e205_1addBucket_post_responses_200_content_application_1json_schema);
52+
export type PostApiV1B64Be5124B034028A58913931942E205SessionCheckResponse = ({
53+
dummy?: string;
54+
});
5355

5456
export type PostApiV1B64Be5124B034028A58913931942E205AddBucketData = {
5557
requestBody?: {

0 commit comments

Comments
 (0)