Skip to content

Commit a79b11a

Browse files
committed
fix(cmd-api-server): missing pretsc npm script #500
Adds the `pretsc` script that generates the Typescript client files based on the openapi.json specs. Also updated the openapi.json so that the healthcheck endpoint has a shortened operation ID (which is a separate, larger effort that is still pending across the entire code-base so figured it's good to start addressing it piece by piece at least while we are at it). Also added the axios dependency to the cmd-api-server package since this is necessary for the exported Typescript API client object to work properly (it is being used for sending the HTTP requests) Fixes #500 Signed-off-by: Peter Somogyvari <[email protected]> (cherry picked from commit 2b7f1cc0adbab31382443d44072ef4e01f73cb88) Signed-off-by: Peter Somogyvari <[email protected]>
1 parent fad9fff commit a79b11a

File tree

12 files changed

+409
-3
lines changed

12 files changed

+409
-3
lines changed

packages/cactus-cmd-api-server/package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cactus-cmd-api-server/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"types": "dist/types/main/typescript/index.d.ts",
1717
"scripts": {
1818
"generate-sdk": "openapi-generator generate --input-spec src/main/json/openapi.json -g typescript-axios -o src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected",
19+
"pretsc": "npm run generate-sdk",
1920
"tsc": "tsc --project ./tsconfig.json",
2021
"watch": "npm-watch",
2122
"webpack": "npm-run-all webpack:dev webpack:prod",
@@ -35,7 +36,10 @@
3536
"ignore": [
3637
"src/**/generated/*"
3738
],
38-
"extensions": ["ts", "json"],
39+
"extensions": [
40+
"ts",
41+
"json"
42+
],
3943
"quiet": true,
4044
"verbose": false,
4145
"runOnChangeOnly": true
@@ -85,6 +89,7 @@
8589
"@hyperledger/cactus-core-api": "0.3.0",
8690
"@hyperledger/cactus-plugin-consortium-manual": "0.3.0",
8791
"@hyperledger/cactus-plugin-keychain-memory": "0.3.0",
92+
"axios": "0.21.1",
8893
"body-parser": "1.19.0",
8994
"compression": "1.7.4",
9095
"convict": "6.0.0",

packages/cactus-cmd-api-server/src/main/json/openapi.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"path": "/api/v1/api-server/healthcheck"
8888
}
8989
},
90-
"operationId": "getConsortiumJws",
90+
"operationId": "getHealthCheck",
9191
"parameters": [],
9292
"responses": {
9393
"200": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
24+
25+
git_push.sh
26+
.npmignore
27+
.gitignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
api.ts
2+
base.ts
3+
configuration.ts
4+
index.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.0.0-beta2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* Hyperledger Cactus API
5+
* Interact with a Cactus deployment through HTTP.
6+
*
7+
* The version of the OpenAPI document: 0.0.1
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
16+
import { Configuration } from './configuration';
17+
import globalAxios, { AxiosPromise, AxiosInstance } from 'axios';
18+
// Some imports not used depending on template conditions
19+
// @ts-ignore
20+
import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base';
21+
22+
/**
23+
*
24+
* @export
25+
* @interface HealthCheckResponse
26+
*/
27+
export interface HealthCheckResponse {
28+
/**
29+
*
30+
* @type {boolean}
31+
* @memberof HealthCheckResponse
32+
*/
33+
success?: boolean;
34+
/**
35+
*
36+
* @type {string}
37+
* @memberof HealthCheckResponse
38+
*/
39+
createdAt: string;
40+
/**
41+
*
42+
* @type {MemoryUsage}
43+
* @memberof HealthCheckResponse
44+
*/
45+
memoryUsage: MemoryUsage;
46+
}
47+
/**
48+
*
49+
* @export
50+
* @interface MemoryUsage
51+
*/
52+
export interface MemoryUsage {
53+
/**
54+
*
55+
* @type {number}
56+
* @memberof MemoryUsage
57+
*/
58+
rss?: number;
59+
/**
60+
*
61+
* @type {number}
62+
* @memberof MemoryUsage
63+
*/
64+
heapTotal?: number;
65+
/**
66+
*
67+
* @type {number}
68+
* @memberof MemoryUsage
69+
*/
70+
heapUsed?: number;
71+
/**
72+
*
73+
* @type {number}
74+
* @memberof MemoryUsage
75+
*/
76+
external?: number;
77+
/**
78+
*
79+
* @type {number}
80+
* @memberof MemoryUsage
81+
*/
82+
arrayBuffers?: number;
83+
}
84+
85+
/**
86+
* DefaultApi - axios parameter creator
87+
* @export
88+
*/
89+
export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) {
90+
return {
91+
/**
92+
* Returns the current timestamp of the API server as proof of health/liveness
93+
* @summary Can be used to verify liveness of an API server instance
94+
* @param {*} [options] Override http request option.
95+
* @throws {RequiredError}
96+
*/
97+
getHealthCheck: async (options: any = {}): Promise<RequestArgs> => {
98+
const localVarPath = `/api/v1/api-server/healthcheck`;
99+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
100+
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
101+
let baseOptions;
102+
if (configuration) {
103+
baseOptions = configuration.baseOptions;
104+
}
105+
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
106+
const localVarHeaderParameter = {} as any;
107+
const localVarQueryParameter = {} as any;
108+
109+
110+
111+
const query = new URLSearchParams(localVarUrlObj.search);
112+
for (const key in localVarQueryParameter) {
113+
query.set(key, localVarQueryParameter[key]);
114+
}
115+
for (const key in options.query) {
116+
query.set(key, options.query[key]);
117+
}
118+
localVarUrlObj.search = (new URLSearchParams(query)).toString();
119+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
120+
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
121+
122+
return {
123+
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
124+
options: localVarRequestOptions,
125+
};
126+
},
127+
}
128+
};
129+
130+
/**
131+
* DefaultApi - functional programming interface
132+
* @export
133+
*/
134+
export const DefaultApiFp = function(configuration?: Configuration) {
135+
return {
136+
/**
137+
* Returns the current timestamp of the API server as proof of health/liveness
138+
* @summary Can be used to verify liveness of an API server instance
139+
* @param {*} [options] Override http request option.
140+
* @throws {RequiredError}
141+
*/
142+
async getHealthCheck(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<HealthCheckResponse>> {
143+
const localVarAxiosArgs = await DefaultApiAxiosParamCreator(configuration).getHealthCheck(options);
144+
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
145+
const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
146+
return axios.request(axiosRequestArgs);
147+
};
148+
},
149+
}
150+
};
151+
152+
/**
153+
* DefaultApi - factory interface
154+
* @export
155+
*/
156+
export const DefaultApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
157+
return {
158+
/**
159+
* Returns the current timestamp of the API server as proof of health/liveness
160+
* @summary Can be used to verify liveness of an API server instance
161+
* @param {*} [options] Override http request option.
162+
* @throws {RequiredError}
163+
*/
164+
getHealthCheck(options?: any): AxiosPromise<HealthCheckResponse> {
165+
return DefaultApiFp(configuration).getHealthCheck(options).then((request) => request(axios, basePath));
166+
},
167+
};
168+
};
169+
170+
/**
171+
* DefaultApi - object-oriented interface
172+
* @export
173+
* @class DefaultApi
174+
* @extends {BaseAPI}
175+
*/
176+
export class DefaultApi extends BaseAPI {
177+
/**
178+
* Returns the current timestamp of the API server as proof of health/liveness
179+
* @summary Can be used to verify liveness of an API server instance
180+
* @param {*} [options] Override http request option.
181+
* @throws {RequiredError}
182+
* @memberof DefaultApi
183+
*/
184+
public getHealthCheck(options?: any) {
185+
return DefaultApiFp(this.configuration).getHealthCheck(options).then((request) => request(this.axios, this.basePath));
186+
}
187+
}
188+
189+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* Hyperledger Cactus API
5+
* Interact with a Cactus deployment through HTTP.
6+
*
7+
* The version of the OpenAPI document: 0.0.1
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
16+
import { Configuration } from "./configuration";
17+
// Some imports not used depending on template conditions
18+
// @ts-ignore
19+
import globalAxios, { AxiosPromise, AxiosInstance } from 'axios';
20+
21+
export const BASE_PATH = "https://www.cactus.stream".replace(/\/+$/, "");
22+
23+
/**
24+
*
25+
* @export
26+
*/
27+
export const COLLECTION_FORMATS = {
28+
csv: ",",
29+
ssv: " ",
30+
tsv: "\t",
31+
pipes: "|",
32+
};
33+
34+
/**
35+
*
36+
* @export
37+
* @interface RequestArgs
38+
*/
39+
export interface RequestArgs {
40+
url: string;
41+
options: any;
42+
}
43+
44+
/**
45+
*
46+
* @export
47+
* @class BaseAPI
48+
*/
49+
export class BaseAPI {
50+
protected configuration: Configuration | undefined;
51+
52+
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
53+
if (configuration) {
54+
this.configuration = configuration;
55+
this.basePath = configuration.basePath || this.basePath;
56+
}
57+
}
58+
};
59+
60+
/**
61+
*
62+
* @export
63+
* @class RequiredError
64+
* @extends {Error}
65+
*/
66+
export class RequiredError extends Error {
67+
name: "RequiredError" = "RequiredError";
68+
constructor(public field: string, msg?: string) {
69+
super(msg);
70+
}
71+
}

0 commit comments

Comments
 (0)