@gewis/grooster-backend-ts 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/base.ts CHANGED
@@ -5,18 +5,19 @@
5
5
  * A GEWIS Rooster maker
6
6
  *
7
7
  * The version of the OpenAPI document: 0.1
8
- *
8
+ *
9
9
  *
10
10
  * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
11
  * https://openapi-generator.tech
12
12
  * Do not edit the class manually.
13
13
  */
14
14
 
15
- import type { Configuration } from "./configuration";
15
+
16
+ import type { Configuration } from './configuration';
16
17
  // Some imports not used depending on template conditions
17
18
  // @ts-ignore
18
- import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from "axios";
19
- import globalAxios from "axios";
19
+ import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
20
+ import globalAxios from 'axios';
20
21
 
21
22
  export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
22
23
 
@@ -25,10 +26,10 @@ export const BASE_PATH = "http://localhost".replace(/\/+$/, "");
25
26
  * @export
26
27
  */
27
28
  export const COLLECTION_FORMATS = {
28
- csv: ",",
29
- ssv: " ",
30
- tsv: "\t",
31
- pipes: "|",
29
+ csv: ",",
30
+ ssv: " ",
31
+ tsv: "\t",
32
+ pipes: "|",
32
33
  };
33
34
 
34
35
  /**
@@ -37,8 +38,8 @@ export const COLLECTION_FORMATS = {
37
38
  * @interface RequestArgs
38
39
  */
39
40
  export interface RequestArgs {
40
- url: string;
41
- options: RawAxiosRequestConfig;
41
+ url: string;
42
+ options: RawAxiosRequestConfig;
42
43
  }
43
44
 
44
45
  /**
@@ -47,19 +48,15 @@ export interface RequestArgs {
47
48
  * @class BaseAPI
48
49
  */
49
50
  export class BaseAPI {
50
- protected configuration: Configuration | undefined;
51
+ protected configuration: Configuration | undefined;
51
52
 
52
- constructor(
53
- configuration?: Configuration,
54
- protected basePath: string = BASE_PATH,
55
- protected axios: AxiosInstance = globalAxios,
56
- ) {
57
- if (configuration) {
58
- this.configuration = configuration;
59
- this.basePath = configuration.basePath ?? basePath;
53
+ constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) {
54
+ if (configuration) {
55
+ this.configuration = configuration;
56
+ this.basePath = configuration.basePath ?? basePath;
57
+ }
60
58
  }
61
- }
62
- }
59
+ };
63
60
 
64
61
  /**
65
62
  *
@@ -68,24 +65,22 @@ export class BaseAPI {
68
65
  * @extends {Error}
69
66
  */
70
67
  export class RequiredError extends Error {
71
- constructor(
72
- public field: string,
73
- msg?: string,
74
- ) {
75
- super(msg);
76
- this.name = "RequiredError";
77
- }
68
+ constructor(public field: string, msg?: string) {
69
+ super(msg);
70
+ this.name = "RequiredError"
71
+ }
78
72
  }
79
73
 
80
74
  interface ServerMap {
81
- [key: string]: {
82
- url: string;
83
- description: string;
84
- }[];
75
+ [key: string]: {
76
+ url: string,
77
+ description: string,
78
+ }[];
85
79
  }
86
80
 
87
81
  /**
88
82
  *
89
83
  * @export
90
84
  */
91
- export const operationServerMap: ServerMap = {};
85
+ export const operationServerMap: ServerMap = {
86
+ }
package/src/common.ts CHANGED
@@ -5,139 +5,105 @@
5
5
  * A GEWIS Rooster maker
6
6
  *
7
7
  * The version of the OpenAPI document: 0.1
8
- *
8
+ *
9
9
  *
10
10
  * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
11
  * https://openapi-generator.tech
12
12
  * Do not edit the class manually.
13
13
  */
14
14
 
15
+
15
16
  import type { Configuration } from "./configuration";
16
17
  import type { RequestArgs } from "./base";
17
- import type { AxiosInstance, AxiosResponse } from "axios";
18
+ import type { AxiosInstance, AxiosResponse } from 'axios';
18
19
  import { RequiredError } from "./base";
19
20
 
20
21
  /**
21
22
  *
22
23
  * @export
23
24
  */
24
- export const DUMMY_BASE_URL = "https://example.com";
25
+ export const DUMMY_BASE_URL = 'https://example.com'
25
26
 
26
27
  /**
27
28
  *
28
29
  * @throws {RequiredError}
29
30
  * @export
30
31
  */
31
- export const assertParamExists = function (
32
- functionName: string,
33
- paramName: string,
34
- paramValue: unknown,
35
- ) {
36
- if (paramValue === null || paramValue === undefined) {
37
- throw new RequiredError(
38
- paramName,
39
- `Required parameter ${paramName} was null or undefined when calling ${functionName}.`,
40
- );
41
- }
42
- };
32
+ export const assertParamExists = function (functionName: string, paramName: string, paramValue: unknown) {
33
+ if (paramValue === null || paramValue === undefined) {
34
+ throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
35
+ }
36
+ }
43
37
 
44
38
  /**
45
39
  *
46
40
  * @export
47
41
  */
48
- export const setApiKeyToObject = async function (
49
- object: any,
50
- keyParamName: string,
51
- configuration?: Configuration,
52
- ) {
53
- if (configuration && configuration.apiKey) {
54
- const localVarApiKeyValue =
55
- typeof configuration.apiKey === "function"
56
- ? await configuration.apiKey(keyParamName)
57
- : await configuration.apiKey;
58
- object[keyParamName] = localVarApiKeyValue;
59
- }
60
- };
42
+ export const setApiKeyToObject = async function (object: any, keyParamName: string, configuration?: Configuration) {
43
+ if (configuration && configuration.apiKey) {
44
+ const localVarApiKeyValue = typeof configuration.apiKey === 'function'
45
+ ? await configuration.apiKey(keyParamName)
46
+ : await configuration.apiKey;
47
+ object[keyParamName] = localVarApiKeyValue;
48
+ }
49
+ }
61
50
 
62
51
  /**
63
52
  *
64
53
  * @export
65
54
  */
66
- export const setBasicAuthToObject = function (
67
- object: any,
68
- configuration?: Configuration,
69
- ) {
70
- if (configuration && (configuration.username || configuration.password)) {
71
- object["auth"] = {
72
- username: configuration.username,
73
- password: configuration.password,
74
- };
75
- }
76
- };
55
+ export const setBasicAuthToObject = function (object: any, configuration?: Configuration) {
56
+ if (configuration && (configuration.username || configuration.password)) {
57
+ object["auth"] = { username: configuration.username, password: configuration.password };
58
+ }
59
+ }
77
60
 
78
61
  /**
79
62
  *
80
63
  * @export
81
64
  */
82
- export const setBearerAuthToObject = async function (
83
- object: any,
84
- configuration?: Configuration,
85
- ) {
86
- if (configuration && configuration.accessToken) {
87
- const accessToken =
88
- typeof configuration.accessToken === "function"
89
- ? await configuration.accessToken()
90
- : await configuration.accessToken;
91
- object["Authorization"] = "Bearer " + accessToken;
92
- }
93
- };
65
+ export const setBearerAuthToObject = async function (object: any, configuration?: Configuration) {
66
+ if (configuration && configuration.accessToken) {
67
+ const accessToken = typeof configuration.accessToken === 'function'
68
+ ? await configuration.accessToken()
69
+ : await configuration.accessToken;
70
+ object["Authorization"] = "Bearer " + accessToken;
71
+ }
72
+ }
94
73
 
95
74
  /**
96
75
  *
97
76
  * @export
98
77
  */
99
- export const setOAuthToObject = async function (
100
- object: any,
101
- name: string,
102
- scopes: string[],
103
- configuration?: Configuration,
104
- ) {
105
- if (configuration && configuration.accessToken) {
106
- const localVarAccessTokenValue =
107
- typeof configuration.accessToken === "function"
108
- ? await configuration.accessToken(name, scopes)
109
- : await configuration.accessToken;
110
- object["Authorization"] = "Bearer " + localVarAccessTokenValue;
111
- }
112
- };
78
+ export const setOAuthToObject = async function (object: any, name: string, scopes: string[], configuration?: Configuration) {
79
+ if (configuration && configuration.accessToken) {
80
+ const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
81
+ ? await configuration.accessToken(name, scopes)
82
+ : await configuration.accessToken;
83
+ object["Authorization"] = "Bearer " + localVarAccessTokenValue;
84
+ }
85
+ }
113
86
 
114
- function setFlattenedQueryParams(
115
- urlSearchParams: URLSearchParams,
116
- parameter: any,
117
- key: string = "",
118
- ): void {
119
- if (parameter == null) return;
120
- if (typeof parameter === "object") {
121
- if (Array.isArray(parameter)) {
122
- (parameter as any[]).forEach((item) =>
123
- setFlattenedQueryParams(urlSearchParams, item, key),
124
- );
125
- } else {
126
- Object.keys(parameter).forEach((currentKey) =>
127
- setFlattenedQueryParams(
128
- urlSearchParams,
129
- parameter[currentKey],
130
- `${key}${key !== "" ? "." : ""}${currentKey}`,
131
- ),
132
- );
87
+ function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void {
88
+ if (parameter == null) return;
89
+ if (typeof parameter === "object") {
90
+ if (Array.isArray(parameter)) {
91
+ (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
92
+ }
93
+ else {
94
+ Object.keys(parameter).forEach(currentKey =>
95
+ setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`)
96
+ );
97
+ }
133
98
  }
134
- } else {
135
- if (urlSearchParams.has(key)) {
136
- urlSearchParams.append(key, parameter);
137
- } else {
138
- urlSearchParams.set(key, parameter);
99
+ else {
100
+ if (urlSearchParams.has(key)) {
101
+ urlSearchParams.append(key, parameter);
102
+ }
103
+ else {
104
+ urlSearchParams.set(key, parameter);
105
+ }
139
106
  }
140
- }
141
107
  }
142
108
 
143
109
  /**
@@ -145,58 +111,40 @@ function setFlattenedQueryParams(
145
111
  * @export
146
112
  */
147
113
  export const setSearchParams = function (url: URL, ...objects: any[]) {
148
- const searchParams = new URLSearchParams(url.search);
149
- setFlattenedQueryParams(searchParams, objects);
150
- url.search = searchParams.toString();
151
- };
114
+ const searchParams = new URLSearchParams(url.search);
115
+ setFlattenedQueryParams(searchParams, objects);
116
+ url.search = searchParams.toString();
117
+ }
152
118
 
153
119
  /**
154
120
  *
155
121
  * @export
156
122
  */
157
- export const serializeDataIfNeeded = function (
158
- value: any,
159
- requestOptions: any,
160
- configuration?: Configuration,
161
- ) {
162
- const nonString = typeof value !== "string";
163
- const needsSerialization =
164
- nonString && configuration && configuration.isJsonMime
165
- ? configuration.isJsonMime(requestOptions.headers["Content-Type"])
166
- : nonString;
167
- return needsSerialization
168
- ? JSON.stringify(value !== undefined ? value : {})
169
- : value || "";
170
- };
123
+ export const serializeDataIfNeeded = function (value: any, requestOptions: any, configuration?: Configuration) {
124
+ const nonString = typeof value !== 'string';
125
+ const needsSerialization = nonString && configuration && configuration.isJsonMime
126
+ ? configuration.isJsonMime(requestOptions.headers['Content-Type'])
127
+ : nonString;
128
+ return needsSerialization
129
+ ? JSON.stringify(value !== undefined ? value : {})
130
+ : (value || "");
131
+ }
171
132
 
172
133
  /**
173
134
  *
174
135
  * @export
175
136
  */
176
137
  export const toPathString = function (url: URL) {
177
- return url.pathname + url.search + url.hash;
178
- };
138
+ return url.pathname + url.search + url.hash
139
+ }
179
140
 
180
141
  /**
181
142
  *
182
143
  * @export
183
144
  */
184
- export const createRequestFunction = function (
185
- axiosArgs: RequestArgs,
186
- globalAxios: AxiosInstance,
187
- BASE_PATH: string,
188
- configuration?: Configuration,
189
- ) {
190
- return <T = unknown, R = AxiosResponse<T>>(
191
- axios: AxiosInstance = globalAxios,
192
- basePath: string = BASE_PATH,
193
- ) => {
194
- const axiosRequestArgs = {
195
- ...axiosArgs.options,
196
- url:
197
- (axios.defaults.baseURL ? "" : (configuration?.basePath ?? basePath)) +
198
- axiosArgs.url,
145
+ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
146
+ return <T = unknown, R = AxiosResponse<T>>(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
147
+ const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url};
148
+ return axios.request<T, R>(axiosRequestArgs);
199
149
  };
200
- return axios.request<T, R>(axiosRequestArgs);
201
- };
202
- };
150
+ }
@@ -5,133 +5,111 @@
5
5
  * A GEWIS Rooster maker
6
6
  *
7
7
  * The version of the OpenAPI document: 0.1
8
- *
8
+ *
9
9
  *
10
10
  * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11
11
  * https://openapi-generator.tech
12
12
  * Do not edit the class manually.
13
13
  */
14
14
 
15
+
15
16
  export interface ConfigurationParameters {
16
- apiKey?:
17
- | string
18
- | Promise<string>
19
- | ((name: string) => string)
20
- | ((name: string) => Promise<string>);
21
- username?: string;
22
- password?: string;
23
- accessToken?:
24
- | string
25
- | Promise<string>
26
- | ((name?: string, scopes?: string[]) => string)
27
- | ((name?: string, scopes?: string[]) => Promise<string>);
28
- basePath?: string;
29
- serverIndex?: number;
30
- baseOptions?: any;
31
- formDataCtor?: new () => any;
17
+ apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
18
+ username?: string;
19
+ password?: string;
20
+ accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
21
+ basePath?: string;
22
+ serverIndex?: number;
23
+ baseOptions?: any;
24
+ formDataCtor?: new () => any;
32
25
  }
33
26
 
34
27
  export class Configuration {
35
- /**
36
- * parameter for apiKey security
37
- * @param name security name
38
- * @memberof Configuration
39
- */
40
- apiKey?:
41
- | string
42
- | Promise<string>
43
- | ((name: string) => string)
44
- | ((name: string) => Promise<string>);
45
- /**
46
- * parameter for basic security
47
- *
48
- * @type {string}
49
- * @memberof Configuration
50
- */
51
- username?: string;
52
- /**
53
- * parameter for basic security
54
- *
55
- * @type {string}
56
- * @memberof Configuration
57
- */
58
- password?: string;
59
- /**
60
- * parameter for oauth2 security
61
- * @param name security name
62
- * @param scopes oauth2 scope
63
- * @memberof Configuration
64
- */
65
- accessToken?:
66
- | string
67
- | Promise<string>
68
- | ((name?: string, scopes?: string[]) => string)
69
- | ((name?: string, scopes?: string[]) => Promise<string>);
70
- /**
71
- * override base path
72
- *
73
- * @type {string}
74
- * @memberof Configuration
75
- */
76
- basePath?: string;
77
- /**
78
- * override server index
79
- *
80
- * @type {number}
81
- * @memberof Configuration
82
- */
83
- serverIndex?: number;
84
- /**
85
- * base options for axios calls
86
- *
87
- * @type {any}
88
- * @memberof Configuration
89
- */
90
- baseOptions?: any;
91
- /**
92
- * The FormData constructor that will be used to create multipart form data
93
- * requests. You can inject this here so that execution environments that
94
- * do not support the FormData class can still run the generated client.
95
- *
96
- * @type {new () => FormData}
97
- */
98
- formDataCtor?: new () => any;
28
+ /**
29
+ * parameter for apiKey security
30
+ * @param name security name
31
+ * @memberof Configuration
32
+ */
33
+ apiKey?: string | Promise<string> | ((name: string) => string) | ((name: string) => Promise<string>);
34
+ /**
35
+ * parameter for basic security
36
+ *
37
+ * @type {string}
38
+ * @memberof Configuration
39
+ */
40
+ username?: string;
41
+ /**
42
+ * parameter for basic security
43
+ *
44
+ * @type {string}
45
+ * @memberof Configuration
46
+ */
47
+ password?: string;
48
+ /**
49
+ * parameter for oauth2 security
50
+ * @param name security name
51
+ * @param scopes oauth2 scope
52
+ * @memberof Configuration
53
+ */
54
+ accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
55
+ /**
56
+ * override base path
57
+ *
58
+ * @type {string}
59
+ * @memberof Configuration
60
+ */
61
+ basePath?: string;
62
+ /**
63
+ * override server index
64
+ *
65
+ * @type {number}
66
+ * @memberof Configuration
67
+ */
68
+ serverIndex?: number;
69
+ /**
70
+ * base options for axios calls
71
+ *
72
+ * @type {any}
73
+ * @memberof Configuration
74
+ */
75
+ baseOptions?: any;
76
+ /**
77
+ * The FormData constructor that will be used to create multipart form data
78
+ * requests. You can inject this here so that execution environments that
79
+ * do not support the FormData class can still run the generated client.
80
+ *
81
+ * @type {new () => FormData}
82
+ */
83
+ formDataCtor?: new () => any;
99
84
 
100
- constructor(param: ConfigurationParameters = {}) {
101
- this.apiKey = param.apiKey;
102
- this.username = param.username;
103
- this.password = param.password;
104
- this.accessToken = param.accessToken;
105
- this.basePath = param.basePath;
106
- this.serverIndex = param.serverIndex;
107
- this.baseOptions = {
108
- ...param.baseOptions,
109
- headers: {
110
- ...param.baseOptions?.headers,
111
- },
112
- };
113
- this.formDataCtor = param.formDataCtor;
114
- }
85
+ constructor(param: ConfigurationParameters = {}) {
86
+ this.apiKey = param.apiKey;
87
+ this.username = param.username;
88
+ this.password = param.password;
89
+ this.accessToken = param.accessToken;
90
+ this.basePath = param.basePath;
91
+ this.serverIndex = param.serverIndex;
92
+ this.baseOptions = {
93
+ ...param.baseOptions,
94
+ headers: {
95
+ ...param.baseOptions?.headers,
96
+ },
97
+ };
98
+ this.formDataCtor = param.formDataCtor;
99
+ }
115
100
 
116
- /**
117
- * Check if the given MIME is a JSON MIME.
118
- * JSON MIME examples:
119
- * application/json
120
- * application/json; charset=UTF8
121
- * APPLICATION/JSON
122
- * application/vnd.company+json
123
- * @param mime - MIME (Multipurpose Internet Mail Extensions)
124
- * @return True if the given MIME is JSON, false otherwise.
125
- */
126
- public isJsonMime(mime: string): boolean {
127
- const jsonMime: RegExp = new RegExp(
128
- "^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$",
129
- "i",
130
- );
131
- return (
132
- mime !== null &&
133
- (jsonMime.test(mime) ||
134
- mime.toLowerCase() === "application/json-patch+json")
135
- );
136
- }
101
+ /**
102
+ * Check if the given MIME is a JSON MIME.
103
+ * JSON MIME examples:
104
+ * application/json
105
+ * application/json; charset=UTF8
106
+ * APPLICATION/JSON
107
+ * application/vnd.company+json
108
+ * @param mime - MIME (Multipurpose Internet Mail Extensions)
109
+ * @return True if the given MIME is JSON, false otherwise.
110
+ */
111
+ public isJsonMime(mime: string): boolean {
112
+ const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
113
+ return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
114
+ }
137
115
  }