Skip to content

Commit

Permalink
fix(cmd-api-server): missing pretsc npm script hyperledger-cacti#500
Browse files Browse the repository at this point in the history
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 hyperledger-cacti#500

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Jan 15, 2021
1 parent cd50124 commit f235572
Show file tree
Hide file tree
Showing 12 changed files with 409 additions and 3 deletions.
13 changes: 13 additions & 0 deletions packages/cactus-cmd-api-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion packages/cactus-cmd-api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"types": "dist/types/main/typescript/index.d.ts",
"scripts": {
"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",
"pretsc": "npm run generate-sdk",
"tsc": "tsc --project ./tsconfig.json",
"watch": "npm-watch",
"webpack": "npm-run-all webpack:dev webpack:prod",
Expand All @@ -35,7 +36,10 @@
"ignore": [
"src/**/generated/*"
],
"extensions": ["ts", "json"],
"extensions": [
"ts",
"json"
],
"quiet": true,
"verbose": false,
"runOnChangeOnly": true
Expand Down Expand Up @@ -85,6 +89,7 @@
"@hyperledger/cactus-core-api": "0.3.0",
"@hyperledger/cactus-plugin-consortium-manual": "0.3.0",
"@hyperledger/cactus-plugin-keychain-memory": "0.3.0",
"axios": "0.21.1",
"body-parser": "1.19.0",
"compression": "1.7.4",
"convict": "6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cactus-cmd-api-server/src/main/json/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"path": "/api/v1/api-server/healthcheck"
}
},
"operationId": "getConsortiumJws",
"operationId": "getHealthCheck",
"parameters": [],
"responses": {
"200": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

git_push.sh
.npmignore
.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
api.ts
base.ts
configuration.ts
index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0.0-beta2
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/* tslint:disable */
/* eslint-disable */
/**
* Hyperledger Cactus API
* Interact with a Cactus deployment through HTTP.
*
* The version of the OpenAPI document: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


import { Configuration } from './configuration';
import globalAxios, { AxiosPromise, AxiosInstance } from 'axios';
// Some imports not used depending on template conditions
// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base';

/**
*
* @export
* @interface HealthCheckResponse
*/
export interface HealthCheckResponse {
/**
*
* @type {boolean}
* @memberof HealthCheckResponse
*/
success?: boolean;
/**
*
* @type {string}
* @memberof HealthCheckResponse
*/
createdAt: string;
/**
*
* @type {MemoryUsage}
* @memberof HealthCheckResponse
*/
memoryUsage: MemoryUsage;
}
/**
*
* @export
* @interface MemoryUsage
*/
export interface MemoryUsage {
/**
*
* @type {number}
* @memberof MemoryUsage
*/
rss?: number;
/**
*
* @type {number}
* @memberof MemoryUsage
*/
heapTotal?: number;
/**
*
* @type {number}
* @memberof MemoryUsage
*/
heapUsed?: number;
/**
*
* @type {number}
* @memberof MemoryUsage
*/
external?: number;
/**
*
* @type {number}
* @memberof MemoryUsage
*/
arrayBuffers?: number;
}

/**
* DefaultApi - axios parameter creator
* @export
*/
export const DefaultApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
* Returns the current timestamp of the API server as proof of health/liveness
* @summary Can be used to verify liveness of an API server instance
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getHealthCheck: async (options: any = {}): Promise<RequestArgs> => {
const localVarPath = `/api/v1/api-server/healthcheck`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, 'https://example.com');
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;



const query = new URLSearchParams(localVarUrlObj.search);
for (const key in localVarQueryParameter) {
query.set(key, localVarQueryParameter[key]);
}
for (const key in options.query) {
query.set(key, options.query[key]);
}
localVarUrlObj.search = (new URLSearchParams(query)).toString();
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
options: localVarRequestOptions,
};
},
}
};

/**
* DefaultApi - functional programming interface
* @export
*/
export const DefaultApiFp = function(configuration?: Configuration) {
return {
/**
* Returns the current timestamp of the API server as proof of health/liveness
* @summary Can be used to verify liveness of an API server instance
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getHealthCheck(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<HealthCheckResponse>> {
const localVarAxiosArgs = await DefaultApiAxiosParamCreator(configuration).getHealthCheck(options);
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
return axios.request(axiosRequestArgs);
};
},
}
};

/**
* DefaultApi - factory interface
* @export
*/
export const DefaultApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
return {
/**
* Returns the current timestamp of the API server as proof of health/liveness
* @summary Can be used to verify liveness of an API server instance
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getHealthCheck(options?: any): AxiosPromise<HealthCheckResponse> {
return DefaultApiFp(configuration).getHealthCheck(options).then((request) => request(axios, basePath));
},
};
};

/**
* DefaultApi - object-oriented interface
* @export
* @class DefaultApi
* @extends {BaseAPI}
*/
export class DefaultApi extends BaseAPI {
/**
* Returns the current timestamp of the API server as proof of health/liveness
* @summary Can be used to verify liveness of an API server instance
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof DefaultApi
*/
public getHealthCheck(options?: any) {
return DefaultApiFp(this.configuration).getHealthCheck(options).then((request) => request(this.axios, this.basePath));
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* tslint:disable */
/* eslint-disable */
/**
* Hyperledger Cactus API
* Interact with a Cactus deployment through HTTP.
*
* The version of the OpenAPI document: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


import { Configuration } from "./configuration";
// Some imports not used depending on template conditions
// @ts-ignore
import globalAxios, { AxiosPromise, AxiosInstance } from 'axios';

export const BASE_PATH = "https://www.cactus.stream".replace(/\/+$/, "");

/**
*
* @export
*/
export const COLLECTION_FORMATS = {
csv: ",",
ssv: " ",
tsv: "\t",
pipes: "|",
};

/**
*
* @export
* @interface RequestArgs
*/
export interface RequestArgs {
url: string;
options: any;
}

/**
*
* @export
* @class BaseAPI
*/
export class BaseAPI {
protected configuration: Configuration | undefined;

constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
if (configuration) {
this.configuration = configuration;
this.basePath = configuration.basePath || this.basePath;
}
}
};

/**
*
* @export
* @class RequiredError
* @extends {Error}
*/
export class RequiredError extends Error {
name: "RequiredError" = "RequiredError";
constructor(public field: string, msg?: string) {
super(msg);
}
}
Loading

0 comments on commit f235572

Please sign in to comment.