Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-7395 - add openapi-client-generator for etherpad #5048

Merged
merged 6 commits into from
Jun 6, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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
.gitignore
.npmignore
git_push.sh
FILES
VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
api.ts
api/author-api.ts
api/default-api.ts
api/group-api.ts
api/pad-api.ts
api/session-api.ts
base.ts
common.ts
configuration.ts
index.ts
models/create-author-using-get200-response-data.ts
models/create-author-using-get200-response.ts
models/create-diff-htmlusing-get200-response.ts
models/create-group-using-get200-response-data.ts
models/create-group-using-get200-response.ts
models/create-group-using-get400-response.ts
models/create-group-using-get401-response.ts
models/create-group-using-get500-response.ts
models/create-session-using-get200-response-data.ts
models/create-session-using-get200-response.ts
models/delete-group-using-get200-response.ts
models/get-author-name-using-get200-response-data-info.ts
models/get-author-name-using-get200-response-data.ts
models/get-author-name-using-get200-response.ts
models/get-chat-head-using-get200-response-data.ts
models/get-chat-head-using-get200-response.ts
models/get-chat-history-using-get200-response-data-messages-inner.ts
models/get-chat-history-using-get200-response-data.ts
models/get-chat-history-using-get200-response.ts
models/get-htmlusing-get200-response-data.ts
models/get-htmlusing-get200-response.ts
models/get-last-edited-using-get200-response-data.ts
models/get-last-edited-using-get200-response.ts
models/get-public-status-using-get200-response-data.ts
models/get-public-status-using-get200-response.ts
models/get-read-only-idusing-get200-response-data.ts
models/get-read-only-idusing-get200-response.ts
models/get-revisions-count-using-get200-response-data.ts
models/get-revisions-count-using-get200-response.ts
models/get-session-info-using-get200-response-data-info.ts
models/get-session-info-using-get200-response-data.ts
models/get-session-info-using-get200-response.ts
models/get-text-using-get200-response-data.ts
models/get-text-using-get200-response.ts
models/index.ts
models/list-all-groups-using-get200-response-data.ts
models/list-all-groups-using-get200-response.ts
models/list-authors-of-pad-using-get200-response-data.ts
models/list-authors-of-pad-using-get200-response.ts
models/list-pads-using-get200-response-data.ts
models/list-pads-using-get200-response.ts
models/list-sessions-of-group-using-get200-response-data.ts
models/list-sessions-of-group-using-get200-response.ts
models/message.ts
models/pad-users-count-using-get200-response-data.ts
models/pad-users-count-using-get200-response.ts
models/pad-users-using-get200-response-data.ts
models/pad-users-using-get200-response.ts
models/session-info.ts
models/user-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.6.0

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

724 changes: 410 additions & 314 deletions apps/server/src/infra/etherpad-client/etherpad-api-client/api/pad-api.ts

Large diffs are not rendered by default.

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions apps/server/src/infra/etherpad-client/etherpad-api-client/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
*/


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

export const BASE_PATH = "http://localhost:9001/api/1.3.0".replace(/\/+$/, "");

Expand All @@ -38,7 +39,7 @@ export const COLLECTION_FORMATS = {
*/
export interface RequestArgs {
url: string;
options: any;
options: RawAxiosRequestConfig;
}

/**
Expand All @@ -52,7 +53,7 @@ export class BaseAPI {
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
if (configuration) {
this.configuration = configuration;
this.basePath = configuration.basePath || this.basePath;
this.basePath = configuration.basePath ?? basePath;
}
}
};
Expand All @@ -64,8 +65,22 @@ export class BaseAPI {
* @extends {Error}
*/
export class RequiredError extends Error {
name: "RequiredError" = "RequiredError";
constructor(public field: string, msg?: string) {
super(msg);
this.name = "RequiredError"
}
}

interface ServerMap {
[key: string]: {
url: string,
description: string,
}[];
}

/**
*
* @export
*/
export const operationServerMap: ServerMap = {
}
48 changes: 30 additions & 18 deletions apps/server/src/infra/etherpad-client/etherpad-api-client/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
*/


import { Configuration } from "./configuration";
import { RequiredError, RequestArgs } from "./base";
import { AxiosInstance } from 'axios';
import type { Configuration } from "./configuration";
import type { RequestArgs } from "./base";
import type { AxiosInstance, AxiosResponse } from 'axios';
import { RequiredError } from "./base";

/**
*
Expand Down Expand Up @@ -83,24 +84,35 @@ export const setOAuthToObject = async function (object: any, name: string, scope
}
}

function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void {
if (parameter == null) return;
if (typeof parameter === "object") {
if (Array.isArray(parameter)) {
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
}
else {
Object.keys(parameter).forEach(currentKey =>
setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
);
}
}
else {
if (urlSearchParams.has(key)) {
urlSearchParams.append(key, parameter);
}
else {
urlSearchParams.set(key, parameter);
}
}
}

/**
*
* @export
*/
export const setSearchParams = function (url: URL, ...objects: any[]) {
const searchParams = new URLSearchParams(url.search);
for (const object of objects) {
for (const key in object) {
if (Array.isArray(object[key])) {
searchParams.delete(key);
for (const item of object[key]) {
searchParams.append(key, item);
}
} else {
searchParams.set(key, object[key]);
}
}
}
setFlattenedQueryParams(searchParams, objects);
url.search = searchParams.toString();
}

Expand Down Expand Up @@ -131,8 +143,8 @@ export const toPathString = function (url: URL) {
* @export
*/
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url};
return axios.request(axiosRequestArgs);
return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
return axios.request<T, R>(axiosRequestArgs);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ConfigurationParameters {
password?: string;
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
basePath?: string;
serverIndex?: number;
baseOptions?: any;
formDataCtor?: new () => any;
}
Expand Down Expand Up @@ -58,6 +59,13 @@ export class Configuration {
* @memberof Configuration
*/
basePath?: string;
/**
* override server index
*
* @type {number}
* @memberof Configuration
*/
serverIndex?: number;
/**
* base options for axios calls
*
Expand All @@ -80,6 +88,7 @@ export class Configuration {
this.password = param.password;
this.accessToken = param.accessToken;
this.basePath = param.basePath;
this.serverIndex = param.serverIndex;
this.baseOptions = param.baseOptions;
this.formDataCtor = param.formDataCtor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
/**
*
* @export
* @interface InlineResponse2004Data
* @interface CreateAuthorUsingGET200ResponseData
*/
export interface InlineResponse2004Data {
export interface CreateAuthorUsingGET200ResponseData {
/**
*
* @type {string}
* @memberof InlineResponse2004Data
* @memberof CreateAuthorUsingGET200ResponseData
*/
sessionID?: string;
'authorID'?: string;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* tslint:disable */
/* eslint-disable */
/**
* Etherpad API
* Etherpad is a real-time collaborative editor scalable to thousands of simultaneous real time users. It provides full data export capabilities, and runs on your server, under your control.
*
* The version of the OpenAPI document: 1.3.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


// May contain unused imports in some cases
// @ts-ignore
import type { CreateAuthorUsingGET200ResponseData } from './create-author-using-get200-response-data';

/**
*
* @export
* @interface CreateAuthorUsingGET200Response
*/
export interface CreateAuthorUsingGET200Response {
/**
*
* @type {number}
* @memberof CreateAuthorUsingGET200Response
*/
'code'?: number;
/**
*
* @type {string}
* @memberof CreateAuthorUsingGET200Response
*/
'message'?: string;
/**
*
* @type {CreateAuthorUsingGET200ResponseData}
* @memberof CreateAuthorUsingGET200Response
*/
'data'?: CreateAuthorUsingGET200ResponseData;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* tslint:disable */
/* eslint-disable */
/**
* Etherpad API
* Etherpad is a real-time collaborative editor scalable to thousands of simultaneous real time users. It provides full data export capabilities, and runs on your server, under your control.
*
* The version of the OpenAPI document: 1.3.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/



/**
*
* @export
* @interface CreateDiffHTMLUsingGET200Response
*/
export interface CreateDiffHTMLUsingGET200Response {
/**
*
* @type {number}
* @memberof CreateDiffHTMLUsingGET200Response
*/
'code'?: number;
/**
*
* @type {string}
* @memberof CreateDiffHTMLUsingGET200Response
*/
'message'?: string;
/**
*
* @type {object}
* @memberof CreateDiffHTMLUsingGET200Response
*/
'data'?: object;
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
/**
*
* @export
* @interface InlineResponse2003Data
* @interface CreateGroupUsingGET200ResponseData
*/
export interface InlineResponse2003Data {
export interface CreateGroupUsingGET200ResponseData {
/**
*
* @type {string}
* @memberof InlineResponse2003Data
* @memberof CreateGroupUsingGET200ResponseData
*/
authorID?: string;
'groupID'?: string;
}


Loading
Loading