Skip to content

Commit 04a7036

Browse files
authored
Merge pull request #1 from StefanoMarzo/use-api-hook
Use api hook
2 parents 259b931 + 0db8995 commit 04a7036

22 files changed

Lines changed: 8187 additions & 0 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
dist
3+
node_modules

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"arrowParens": "avoid",
3+
"printWidth": 120,
4+
"semi": false,
5+
"tabWidth": 2,
6+
"singleQuote": true,
7+
"endOfLine": "lf"
8+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# React OpenApi Hook
2+
Please find here an example of use: https://github.com/StefanoMarzo/react-openapi-generator-hook-demo

eslint.config.mjs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import react from 'eslint-plugin-react'
2+
import tsParser from '@typescript-eslint/parser'
3+
import path from 'node:path'
4+
import { fileURLToPath } from 'node:url'
5+
import js from '@eslint/js'
6+
import { FlatCompat } from '@eslint/eslintrc'
7+
8+
const __filename = fileURLToPath(import.meta.url)
9+
const __dirname = path.dirname(__filename)
10+
const compat = new FlatCompat({
11+
baseDirectory: __dirname,
12+
recommendedConfig: js.configs.recommended,
13+
allConfig: js.configs.all,
14+
})
15+
16+
export default [{
17+
ignores: [
18+
'**/node_modules/',
19+
'**/dist/',
20+
'**/.prettierrc',
21+
'**/*env*',
22+
'**/vite.config.ts',
23+
'**/generated/',
24+
'**/coverage/',
25+
],
26+
}, ...compat.extends(
27+
'eslint:recommended',
28+
'plugin:@typescript-eslint/eslint-recommended',
29+
'plugin:@typescript-eslint/recommended',
30+
'plugin:react/all',
31+
'google',
32+
), {
33+
plugins: {
34+
react,
35+
},
36+
37+
languageOptions: {
38+
parser: tsParser,
39+
ecmaVersion: 5,
40+
sourceType: 'module',
41+
parserOptions: {
42+
project: './tsconfig.json',
43+
},
44+
},
45+
46+
settings: {
47+
react: {
48+
version: 'detect',
49+
},
50+
51+
'import/resolver': {
52+
node: {
53+
paths: ['src'],
54+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
55+
},
56+
},
57+
},
58+
59+
rules: {
60+
semi: ['error', 'never'],
61+
62+
'max-len': ['error', {
63+
code: 120,
64+
ignorePattern: '^import .*',
65+
}],
66+
67+
'space-infix-ops': 'error',
68+
eqeqeq: ['error', 'always'],
69+
'object-curly-spacing': ['warn', 'always'],
70+
'require-jsdoc': 'off',
71+
'valid-jsdoc': 'off',
72+
'no-unused-vars': 'off',
73+
'react/jsx-no-comment-textnodes': 'off',
74+
'react/prop-types': 'off',
75+
76+
'react/jsx-indent': [2, 2, {
77+
checkAttributes: true,
78+
indentLogicalExpressions: true,
79+
}],
80+
81+
'react/jsx-max-depth': [2, {
82+
max: 7,
83+
}],
84+
85+
'react/jsx-indent-props': [2, 2],
86+
'react/require-default-props': 'off',
87+
88+
'react/jsx-max-props-per-line': [1, {
89+
when: 'multiline',
90+
}],
91+
92+
'react/jsx-filename-extension': ['error', {
93+
extensions: ['.tsx'],
94+
}],
95+
96+
indent: ['error', 2, {
97+
SwitchCase: 1,
98+
offsetTernaryExpressions: false,
99+
}],
100+
101+
'quote-props': 'off',
102+
'react/destructuring-assignment': 'off',
103+
'react/react-in-jsx-scope': 'off',
104+
'react/jsx-one-expression-per-line': 'off',
105+
'react/jsx-props-no-spreading': 'off',
106+
'react/forbid-component-props': 'off',
107+
'react/jsx-no-literals': 'off',
108+
109+
'react/function-component-definition': [2, {
110+
namedComponents: 'arrow-function',
111+
unnamedComponents: 'arrow-function',
112+
}],
113+
114+
'react/no-multi-comp': [2, {
115+
ignoreStateless: true,
116+
}],
117+
118+
'react/jsx-no-bind': 'off',
119+
'react/no-set-state': 'off',
120+
'react/jsx-no-leaked-render': 'off',
121+
'react/jsx-newline': 'off',
122+
'arrow-parens': 'off',
123+
'operator-linebreak': 'off',
124+
'@typescript-eslint/no-empty-function': 'off',
125+
'@typescript-eslint/no-unused-expressions': 'off',
126+
'react/no-unstable-nested-components': 'off',
127+
128+
'@typescript-eslint/no-unused-vars': ['error', {
129+
argsIgnorePattern: '^_',
130+
destructuredArrayIgnorePattern: '^_',
131+
varsIgnorePattern: '^_',
132+
}],
133+
134+
'comma-spacing': 'off',
135+
},
136+
}]

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+
}

0 commit comments

Comments
 (0)