Skip to content

Commit 0310f8b

Browse files
committed
- offering a record of configurations to handle multiple back-ends
- passing config, axios instance, and baseUrl directly to openApi provider - enhanced openapi generator configuration to avoid generating unnecessary files - useApi hook improvement in memoized request options and parameters - restrict allowed Configuration to the generated one - supporting generated configuration and peer dependencies - make configuration generic - make the hook depending on the context provider
1 parent cc44911 commit 0310f8b

18 files changed

Lines changed: 1816 additions & 182 deletions

generated/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
wwwroot/*.js
2+
node_modules
3+
typings
4+
dist

generated/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# OpenAPI Generator Ignore
2+
## Avoid generating every file except configuration.ts
3+
api.ts
4+
base.ts
5+
common.ts
6+
index.ts

generated/.openapi-generator/FILES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gitignore
2+
.npmignore
3+
configuration.ts
4+
git_push.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.12.0

generated/configuration.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* API Generation
5+
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
6+
*
7+
* The version of the OpenAPI document: 1.0.0
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+
export interface ConfigurationParameters {
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;
25+
}
26+
27+
export class Configuration {
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;
84+
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+
}
100+
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+
}
115+
}

generated/git_push.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/sh
2+
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3+
#
4+
# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
5+
6+
git_user_id=$1
7+
git_repo_id=$2
8+
release_note=$3
9+
git_host=$4
10+
11+
if [ "$git_host" = "" ]; then
12+
git_host="github.com"
13+
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
14+
fi
15+
16+
if [ "$git_user_id" = "" ]; then
17+
git_user_id="GIT_USER_ID"
18+
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
19+
fi
20+
21+
if [ "$git_repo_id" = "" ]; then
22+
git_repo_id="GIT_REPO_ID"
23+
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
24+
fi
25+
26+
if [ "$release_note" = "" ]; then
27+
release_note="Minor update"
28+
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
29+
fi
30+
31+
# Initialize the local directory as a Git repository
32+
git init
33+
34+
# Adds the files in the local repository and stages them for commit.
35+
git add .
36+
37+
# Commits the tracked changes and prepares them to be pushed to a remote repository.
38+
git commit -m "$release_note"
39+
40+
# Sets the new remote
41+
git_remote=$(git remote)
42+
if [ "$git_remote" = "" ]; then # git remote not defined
43+
44+
if [ "$GIT_TOKEN" = "" ]; then
45+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
46+
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
47+
else
48+
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
49+
fi
50+
51+
fi
52+
53+
git pull origin master
54+
55+
# Pushes (Forces) the changes in the local repository up to the remote repository
56+
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
57+
git push origin master 2>&1 | grep -v 'To https'

index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
export { OpenApiGeneratorConfigurationProvider, useOpenApiGenerator } from './src/context/OpenApiContextProvider'
1+
export * from './src/type/openApiConfigurationTypes'
2+
export { useOpenApiGenerator, OpenApiProvider } from './src/context/OpenApiContextProvider'
23
export { useApi } from './src/hook/useApi'
3-
export * from './src/types/configuration'
4+
export { Configuration } from './generated/configuration'

openapi-specs.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
openapi: 3.0.0
2+
info:
3+
title: API Generation
4+
version: 1.0.0
5+
paths: {}

openapitools.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
3+
"spaces": 2,
4+
"generator-cli": {
5+
"version": "7.12.0"
6+
}
7+
}

0 commit comments

Comments
 (0)