@team-supercharge/oasg 14.0.0-remove-instant-mapping-634c95c0.0 → 14.1.0-feature-postman-target-44c6a50d.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/README.md +16 -0
- package/bin/oasg +1 -0
- package/config.schema.yml +15 -0
- package/package.json +8 -7
- package/targets/feign/generator-config.json +8 -0
- package/targets/feign-kotlin/generator-config.json +10 -0
- package/targets/nestjs/templates/package.mustache +3 -2
- package/targets/nestjs/templates/pipes.ts +1 -1
- package/targets/nestjs/templates/rewrite-path-parameters.js +1 -1
- package/targets/postman/generate.sh +17 -0
- package/targets/postman/generator-config.json +7 -0
- package/targets/postman/publish.sh +26 -0
- package/targets/react/generator-config.json +10 -0
- package/targets/react/templates/apis.index.mustache +18 -0
- package/targets/react/templates/hook.mustache +111 -0
- package/targets/react/templates/package.mustache +45 -0
- package/targets/react/templates/tsconfig.esm.mustache +8 -0
- package/targets/react/templates/tsconfig.mustache +26 -0
- package/targets/react/templates/use-api.hook.mustache +155 -0
- package/targets/spring/generator-config.json +6 -0
- package/targets/spring-kotlin/generator-config.json +4 -0
package/README.md
CHANGED
@@ -771,12 +771,28 @@ describe('Auth', function () {
|
|
771
771
|
|-|-|-|-|
|
772
772
|
| fileName | Name of the generated file | N | `openapi.yaml` |
|
773
773
|
|
774
|
+
#### `postman-collection`
|
775
|
+
|
776
|
+
```json
|
777
|
+
{
|
778
|
+
"id": "postman-collection",
|
779
|
+
"type": "postman-collection",
|
780
|
+
"source": "source-merged",
|
781
|
+
"repository": "git@gitlab.supercharge.io:example/openapi-generator-source.git",
|
782
|
+
"generatorCustomArgs": "--additional-properties=packageName=$packageName"
|
783
|
+
}
|
784
|
+
```
|
785
|
+
|
774
786
|
---
|
775
787
|
|
776
788
|
# Migration Guide
|
777
789
|
|
778
790
|
This section covers the breaking changes and their migrations across major version upgrades.
|
779
791
|
|
792
|
+
## From `13.x.x` to `14.0.0`
|
793
|
+
|
794
|
+
Several dependencies have been upgraded, and OASg now uses `node` version 20.15.0 and `npm` version 10 by default. If your project still uses `node@18`, you should upgrade first.
|
795
|
+
|
780
796
|
## From `12.x.x` to `13.0.1`
|
781
797
|
|
782
798
|
> ❗ Due to version `13.0.0` has been published before erroneously (then unpublished) to the NPM registry, this version of the artifact won't be available either as an NPM package or a Docker base image. Please use the `13.0.1` patch version instead.
|
package/bin/oasg
CHANGED
@@ -49,6 +49,7 @@ const DEFAULT_GENERATOR_MAPPING = {
|
|
49
49
|
"contract-testing": { version: '4.3.1', generator: 'typescript-node' },
|
50
50
|
"openapi": { version: undefined, generator: undefined },
|
51
51
|
"stubby": { version: '4.3.1', generator: 'stubby' },
|
52
|
+
"postman": { version: '7.0.1', generator: 'postman-collection' }
|
52
53
|
};
|
53
54
|
const DEFAULT_KTLINT_VERSION = '1.0.0';
|
54
55
|
const BIN_FOLDER = 'out/.bin';
|
package/config.schema.yml
CHANGED
@@ -24,6 +24,7 @@ properties:
|
|
24
24
|
- $ref: '#/targets/NestJS'
|
25
25
|
- $ref: '#/targets/OpenAPI'
|
26
26
|
- $ref: '#/targets/Flutter'
|
27
|
+
- $ref: '#/targets/Postman'
|
27
28
|
required:
|
28
29
|
- targets
|
29
30
|
additionalProperties: false
|
@@ -346,6 +347,20 @@ targets:
|
|
346
347
|
- packageName
|
347
348
|
- repository
|
348
349
|
|
350
|
+
Postman:
|
351
|
+
allOf:
|
352
|
+
- $ref: '#/targets/Base'
|
353
|
+
- properties:
|
354
|
+
type:
|
355
|
+
pattern: "^postman$"
|
356
|
+
packageName:
|
357
|
+
type: string
|
358
|
+
repository:
|
359
|
+
type: string
|
360
|
+
required:
|
361
|
+
- packageName
|
362
|
+
- repository
|
363
|
+
|
349
364
|
definitions:
|
350
365
|
# default
|
351
366
|
SourceOverrides:
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@team-supercharge/oasg",
|
3
|
-
"version": "14.
|
3
|
+
"version": "14.1.0-feature-postman-target-44c6a50d.0",
|
4
4
|
"description": "Node-based tool to lint OpenAPI documents and generate clients, servers and documentation from them",
|
5
5
|
"author": "Supercharge",
|
6
6
|
"license": "MIT",
|
@@ -15,8 +15,8 @@
|
|
15
15
|
"url": "git@gitlab.com:team-supercharge/oasg.git"
|
16
16
|
},
|
17
17
|
"engines": {
|
18
|
-
"node": "^
|
19
|
-
"npm": "^
|
18
|
+
"node": "^20.15",
|
19
|
+
"npm": "^10"
|
20
20
|
},
|
21
21
|
"files": [
|
22
22
|
"bin",
|
@@ -28,9 +28,9 @@
|
|
28
28
|
"dependencies": {
|
29
29
|
"@apidevtools/json-schema-ref-parser": "^10.1.0",
|
30
30
|
"@apidevtools/swagger-parser": "^10.1.0",
|
31
|
-
"@redocly/cli": "1.
|
32
|
-
"@stoplight/prism-cli": "
|
33
|
-
"@stoplight/spectral-cli": "6.
|
31
|
+
"@redocly/cli": "1.17.1",
|
32
|
+
"@stoplight/prism-cli": "5.8.2",
|
33
|
+
"@stoplight/spectral-cli": "6.11.1",
|
34
34
|
"ajv": "^8.12.0",
|
35
35
|
"command-exists": "^1.2.9",
|
36
36
|
"express": "^4.18.2",
|
@@ -39,11 +39,12 @@
|
|
39
39
|
"js-yaml": "^4.1.0",
|
40
40
|
"json-schema-merge-allof": "^0.8.1",
|
41
41
|
"openapi-typescript-validator-ext-ref": "^3.2.0-external-ref-support",
|
42
|
-
"swagger-ui-express": "^
|
42
|
+
"swagger-ui-express": "^5.0.1",
|
43
43
|
"yamljs": "^0.3.0",
|
44
44
|
"yargs": "^17.7.1"
|
45
45
|
},
|
46
46
|
"devDependencies": {
|
47
|
+
"@types/jest": "^29.5.12",
|
47
48
|
"execa": "^5.0.0",
|
48
49
|
"fs-extra": "^11.1.1",
|
49
50
|
"jest": "^29.5.0"
|
@@ -10,6 +10,14 @@
|
|
10
10
|
"documentationProvider": "none",
|
11
11
|
"annotationLibrary": "none",
|
12
12
|
"useSpringBoot3": true,
|
13
|
+
"typeMappings": {
|
14
|
+
"OffsetDateTime": "java.time.Instant",
|
15
|
+
"Date": "java.time.LocalDate"
|
16
|
+
},
|
17
|
+
"importMappings": {
|
18
|
+
"java.time.OffsetDateTime": "java.time.Instant",
|
19
|
+
"java.util.Date": "java.time.LocalDate"
|
20
|
+
},
|
13
21
|
"inlineSchemaOptions": {
|
14
22
|
"ARRAY_ITEM_SUFFIX": "",
|
15
23
|
"MAP_ITEM_SUFFIX": "",
|
@@ -8,6 +8,16 @@
|
|
8
8
|
"documentationProvider": "none",
|
9
9
|
"annotationLibrary": "none",
|
10
10
|
"useSpringBoot3": true,
|
11
|
+
"typeMappings": {
|
12
|
+
"DateTime": "java.time.Instant",
|
13
|
+
"java.time.OffsetDateTime": "java.time.Instant",
|
14
|
+
"java.util.Date": "java.time.LocalDate"
|
15
|
+
},
|
16
|
+
"importMappings": {
|
17
|
+
"DateTime": "java.time.Instant",
|
18
|
+
"java.time.OffsetDateTime": "java.time.Instant",
|
19
|
+
"java.util.Date": "java.time.LocalDate"
|
20
|
+
},
|
11
21
|
"inlineSchemaOptions": {
|
12
22
|
"ARRAY_ITEM_SUFFIX": "",
|
13
23
|
"MAP_ITEM_SUFFIX": "",
|
@@ -15,11 +15,12 @@
|
|
15
15
|
"peerDependencies": {
|
16
16
|
"@nestjs/common": "^9.0.0 || ^10.0.0",
|
17
17
|
"@nestjs/core": "^9.0.0 || ^10.0.0",
|
18
|
-
"@nestjs/platform-express": "^9.0.0 || ^10.0.0"
|
18
|
+
"@nestjs/platform-express": "^9.0.0 || ^10.0.0",
|
19
|
+
"@types/validator": "13.11.7"
|
19
20
|
},
|
20
21
|
"dependencies": {
|
21
22
|
"class-transformer": "^0.5.1",
|
22
|
-
"class-validator": "
|
23
|
+
"class-validator": "0.14.0"
|
23
24
|
},
|
24
25
|
"devDependencies": {
|
25
26
|
"@nestjs/common": "^9.0.0",
|
@@ -77,7 +77,7 @@ export class OptionalParseBoolPipe implements PipeTransform<string | boolean> {
|
|
77
77
|
}
|
78
78
|
}
|
79
79
|
|
80
|
-
export class OptionalParseEnumPipe<T = any> implements PipeTransform<T> {
|
80
|
+
export class OptionalParseEnumPipe<T extends { [key: string]: any } = any> implements PipeTransform<T> {
|
81
81
|
constructor(private readonly enumType: T) {
|
82
82
|
if (!enumType) {
|
83
83
|
throw new Error(
|
@@ -12,7 +12,7 @@ function rewritePathParameters(fileName) {
|
|
12
12
|
const contents = fs.readFileSync(file, 'utf-8');
|
13
13
|
|
14
14
|
var result = contents.replace(/\${this\.configuration\.encodeParam\({name:\s"/g, ':');
|
15
|
-
result = result.replace(/"
|
15
|
+
result = result.replace(/".*?}\)}/g, '');
|
16
16
|
|
17
17
|
var options = { flag : 'w', encoding: 'utf8' };
|
18
18
|
fs.writeFileSync(file, result, options);
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#/bin/bash
|
2
|
+
|
3
|
+
source $(dirname "$0")/../common.sh
|
4
|
+
|
5
|
+
rm -rf out/$targetId
|
6
|
+
mkdir -p out/$targetId
|
7
|
+
|
8
|
+
java -jar $binary generate \
|
9
|
+
-g $generatorId \
|
10
|
+
-i $openApiFile \
|
11
|
+
-t $templateDir \
|
12
|
+
-o out/$targetId \
|
13
|
+
-c $(dirname "$0")/generator-config.json \
|
14
|
+
-ppubLibrary=$packageName \
|
15
|
+
-ppubName=$packageName \
|
16
|
+
-ppubRepository=$repository \
|
17
|
+
-ppubVersion=$version $generatorCustomArgs
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#/bin/bash
|
2
|
+
|
3
|
+
source $(dirname "$0")/../common.sh
|
4
|
+
|
5
|
+
cd out
|
6
|
+
git clone $repository generator-source
|
7
|
+
rm -rf generator-source/$projectName
|
8
|
+
cp -rf $targetId/* generator-source
|
9
|
+
|
10
|
+
cd generator-source
|
11
|
+
if [ $(git status --porcelain | wc -l) -eq "0" ]; then
|
12
|
+
echo "🟢 No changes"
|
13
|
+
else
|
14
|
+
git add .
|
15
|
+
git commit -m "chore(release): $version"
|
16
|
+
|
17
|
+
if [ "$preRelease" == "false" ]; then git push; fi
|
18
|
+
|
19
|
+
tagVersion="v$version"
|
20
|
+
git tag -f $tagVersion
|
21
|
+
git push origin -f --tags
|
22
|
+
fi
|
23
|
+
|
24
|
+
cd ..
|
25
|
+
rm -rf generator-source
|
26
|
+
cd ../..
|
@@ -10,5 +10,15 @@
|
|
10
10
|
"ARRAY_ITEM_SUFFIX": "",
|
11
11
|
"MAP_ITEM_SUFFIX": "",
|
12
12
|
"SKIP_SCHEMA_REUSE": "true"
|
13
|
+
},
|
14
|
+
"files": {
|
15
|
+
"hook.mustache": {
|
16
|
+
"destinationFilename": ".hook.ts",
|
17
|
+
"templateType": "API"
|
18
|
+
},
|
19
|
+
"use-api.hook.mustache": {
|
20
|
+
"folder": "src/apis",
|
21
|
+
"destinationFilename": "use-api.hook.tsx"
|
22
|
+
}
|
13
23
|
}
|
14
24
|
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/* tslint:disable */
|
2
|
+
/* eslint-disable */
|
3
|
+
{{#useSagaAndRecords}}
|
4
|
+
export * from './SagaApiManager{{importFileExtension}}'
|
5
|
+
export * from './allSagas{{importFileExtension}}'
|
6
|
+
{{/useSagaAndRecords}}
|
7
|
+
export * from './use-api.hook{{importFileExtension}}';
|
8
|
+
{{#apiInfo}}
|
9
|
+
{{#apis}}
|
10
|
+
{{#operations}}
|
11
|
+
export * from './{{ classFilename }}{{importFileExtension}}';
|
12
|
+
export * from './{{ classFilename }}.hook{{importFileExtension}}';
|
13
|
+
{{#useSagaAndRecords}}
|
14
|
+
export * from './{{{ classFilename }}}Sagas{{importFileExtension}}';
|
15
|
+
{{/useSagaAndRecords}}
|
16
|
+
{{/operations}}
|
17
|
+
{{/apis}}
|
18
|
+
{{/apiInfo}}
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/* tslint:disable */
|
2
|
+
/* eslint-disable */
|
3
|
+
{{>licenseInfo}}
|
4
|
+
|
5
|
+
import { useMutation, UseMutationOptions, UseMutationResult, useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
6
|
+
import { useApi } from './use-api.hook';
|
7
|
+
{{#imports.0}}
|
8
|
+
import type {
|
9
|
+
{{#imports}}
|
10
|
+
{{className}},
|
11
|
+
{{/imports}}
|
12
|
+
} from '../models/index{{importFileExtension}}';
|
13
|
+
{{/imports.0}}
|
14
|
+
{{#operations}}
|
15
|
+
import {
|
16
|
+
{{classname}},
|
17
|
+
{{#operation}}
|
18
|
+
{{#allParams.0}}
|
19
|
+
{{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request,
|
20
|
+
{{/allParams.0}}
|
21
|
+
{{/operation}}
|
22
|
+
} from './{{ classFilename }}{{importFileExtension}}';
|
23
|
+
{{/operations}}
|
24
|
+
|
25
|
+
{{#operations}}
|
26
|
+
{{#operation}}
|
27
|
+
|
28
|
+
export type {{classname}}{{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Parameters =
|
29
|
+
{{^useSingleRequestParameter}}
|
30
|
+
{ parameters: Parameters<{{classname}}['{{nickname}}']>};
|
31
|
+
{{/useSingleRequestParameter}}
|
32
|
+
{{#useSingleRequestParameter}}
|
33
|
+
{{#allParams.0}}{{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request{{/allParams.0}}{{^allParams.0}}void{{/allParams.0}};
|
34
|
+
{{/useSingleRequestParameter}}
|
35
|
+
|
36
|
+
/**
|
37
|
+
{{#notes}}
|
38
|
+
* {{¬es}}
|
39
|
+
{{/notes}}
|
40
|
+
{{#summary}}
|
41
|
+
* {{&summary}}
|
42
|
+
{{/summary}}
|
43
|
+
{{#isDeprecated}}
|
44
|
+
* @deprecated
|
45
|
+
{{/isDeprecated}}
|
46
|
+
*/
|
47
|
+
export const use{{classname}}{{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Mutation = <TContext = unknown>(
|
48
|
+
{ onSuccess, ...options }: Omit<UseMutationOptions<{{{returnType}}}{{^returnType}}void{{/returnType}}, Error, {{classname}}{{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Parameters, TContext>, 'mutationFn'> = {}
|
49
|
+
): UseMutationResult<{{{returnType}}}{{^returnType}}void{{/returnType}}, Error, {{classname}}{{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Parameters, TContext> => {
|
50
|
+
const api = useApi({{classname}});
|
51
|
+
return useMutation<{{{returnType}}}{{^returnType}}void{{/returnType}}, Error, {{classname}}{{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Parameters, TContext>({
|
52
|
+
{{^useSingleRequestParameter}}
|
53
|
+
mutationFn: ({ parameters }) => api.{{nickname}}(...parameters),
|
54
|
+
{{/useSingleRequestParameter}}
|
55
|
+
{{#useSingleRequestParameter}}
|
56
|
+
{{#allParams.0}}
|
57
|
+
mutationFn: (parameters) => api.{{nickname}}(parameters),
|
58
|
+
{{/allParams.0}}
|
59
|
+
{{^allParams.0}}
|
60
|
+
mutationFn: () => api.{{nickname}}(),
|
61
|
+
{{/allParams.0}}
|
62
|
+
{{/useSingleRequestParameter}}
|
63
|
+
...options,
|
64
|
+
});
|
65
|
+
}
|
66
|
+
/**
|
67
|
+
{{#notes}}
|
68
|
+
* {{¬es}}
|
69
|
+
{{/notes}}
|
70
|
+
{{#summary}}
|
71
|
+
* {{&summary}}
|
72
|
+
{{/summary}}
|
73
|
+
{{#isDeprecated}}
|
74
|
+
* @deprecated
|
75
|
+
{{/isDeprecated}}
|
76
|
+
*/
|
77
|
+
export const use{{classname}}{{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Query = (
|
78
|
+
options: Partial<Omit<UseQueryOptions<{{{returnType}}}{{^returnType}}void{{/returnType}}>, 'queryFn'>> = {}
|
79
|
+
{{^useSingleRequestParameter}}
|
80
|
+
,{parameters}: Partial<{{classname}}{{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Parameters>
|
81
|
+
{{/useSingleRequestParameter}}
|
82
|
+
{{#useSingleRequestParameter}}
|
83
|
+
{{#allParams.0}}
|
84
|
+
,parameter: {{classname}}{{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Parameters | undefined
|
85
|
+
{{/allParams.0}}
|
86
|
+
{{/useSingleRequestParameter}}
|
87
|
+
): UseQueryResult<{{{returnType}}}{{^returnType}}void{{/returnType}}> => {
|
88
|
+
const api = useApi({{classname}});
|
89
|
+
return useQuery<{{{returnType}}}{{^returnType}}void{{/returnType}}>({
|
90
|
+
{{^useSingleRequestParameter}}
|
91
|
+
queryKey: ['{{classname}}','{{nickname}}', ...requestParameters],
|
92
|
+
queryFn: ({ signal }) => api.{{nickname}}(...requestParameters.slice(0, -1), { ...requestParameters[requestParameters.length - 1], signal }),
|
93
|
+
enabled: !!parameters,
|
94
|
+
{{/useSingleRequestParameter}}
|
95
|
+
{{#useSingleRequestParameter}}
|
96
|
+
{{#allParams.0}}
|
97
|
+
queryKey: ['{{classname}}','{{nickname}}', parameter],
|
98
|
+
queryFn: ({ signal }) => api.{{nickname}}(parameter, { signal }),
|
99
|
+
enabled: !!parameter,
|
100
|
+
{{/allParams.0}}
|
101
|
+
{{^allParams.0}}
|
102
|
+
queryKey: ['{{classname}}','{{nickname}}'],
|
103
|
+
queryFn: ({ signal }) => api.{{nickname}}({ signal }),
|
104
|
+
{{/allParams.0}}
|
105
|
+
{{/useSingleRequestParameter}}
|
106
|
+
...options,
|
107
|
+
});
|
108
|
+
}
|
109
|
+
{{/operation}}
|
110
|
+
|
111
|
+
{{/operations}}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
{
|
2
|
+
"name": "{{npmName}}",
|
3
|
+
"version": "{{npmVersion}}",
|
4
|
+
"description": "OpenAPI client for {{npmName}}",
|
5
|
+
"author": "OpenAPI-Generator",
|
6
|
+
"repository": {
|
7
|
+
"type": "git",
|
8
|
+
"url": "https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}.git"
|
9
|
+
},
|
10
|
+
{{#packageAsSourceOnlyLibrary}}
|
11
|
+
"main": "./index.ts",
|
12
|
+
{{/packageAsSourceOnlyLibrary}}
|
13
|
+
{{^packageAsSourceOnlyLibrary}}
|
14
|
+
"main": "./dist/index.js",
|
15
|
+
"typings": "./dist/index.d.ts",
|
16
|
+
{{#supportsES6}}
|
17
|
+
"module": "./dist/esm/index.js",
|
18
|
+
"sideEffects": false,
|
19
|
+
{{/supportsES6}}
|
20
|
+
"scripts": {
|
21
|
+
"build": "tsc{{#supportsES6}} && tsc -p tsconfig.esm.json{{/supportsES6}}"{{^sagasAndRecords}},
|
22
|
+
"prepare": "npm run build"{{/sagasAndRecords}}
|
23
|
+
},
|
24
|
+
{{/packageAsSourceOnlyLibrary}}
|
25
|
+
"devDependencies": {
|
26
|
+
{{#sagasAndRecords}}
|
27
|
+
"immutable": "^4.0.0-rc.12",
|
28
|
+
"normalizr": "^3.6.1",
|
29
|
+
"redux-saga": "^1.1.3",
|
30
|
+
"redux-ts-simple": "^3.2.0",
|
31
|
+
"reselect": "^4.0.0",
|
32
|
+
{{/sagasAndRecords}}
|
33
|
+
"typescript": "^4.0",
|
34
|
+
"@types/react": "^18.2.24"
|
35
|
+
},
|
36
|
+
"peerDependencies": {
|
37
|
+
"react": "^18.2.0",
|
38
|
+
"@tanstack/react-query": "^5.12.2"
|
39
|
+
}{{#npmRepository}},{{/npmRepository}}
|
40
|
+
{{#npmRepository}}
|
41
|
+
"publishConfig": {
|
42
|
+
"registry": "{{npmRepository}}"
|
43
|
+
}
|
44
|
+
{{/npmRepository}}
|
45
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"declaration": true,
|
4
|
+
"target": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}es5{{/supportsES6}}",
|
5
|
+
{{#sagasAndRecords}}
|
6
|
+
"strict": true,
|
7
|
+
{{/sagasAndRecords}}
|
8
|
+
"module": "commonjs",
|
9
|
+
"moduleResolution": "node",
|
10
|
+
"outDir": "dist",
|
11
|
+
{{^supportsES6}}
|
12
|
+
"lib": [
|
13
|
+
"es6",
|
14
|
+
"dom"
|
15
|
+
],
|
16
|
+
{{/supportsES6}}
|
17
|
+
"typeRoots": [
|
18
|
+
"node_modules/@types"
|
19
|
+
],
|
20
|
+
"jsx": "react-jsx",
|
21
|
+
},
|
22
|
+
"exclude": [
|
23
|
+
"dist",
|
24
|
+
"node_modules"
|
25
|
+
]
|
26
|
+
}
|
@@ -0,0 +1,155 @@
|
|
1
|
+
import {
|
2
|
+
createContext,
|
3
|
+
useContext,
|
4
|
+
useCallback,
|
5
|
+
useMemo,
|
6
|
+
FC,
|
7
|
+
PropsWithChildren,
|
8
|
+
} from "react";
|
9
|
+
import * as runtime from '../runtime';
|
10
|
+
{{#apiInfo}}
|
11
|
+
{{#apis}}
|
12
|
+
{{#operations}}
|
13
|
+
import { {{classname}} } from './{{ classFilename }}{{importFileExtension}}';
|
14
|
+
{{/operations}}
|
15
|
+
{{/apis}}
|
16
|
+
|
17
|
+
|
18
|
+
type APIS_IN_ORDER = [
|
19
|
+
{{#apis}}
|
20
|
+
{{#operations}}
|
21
|
+
{{classname}},
|
22
|
+
{{/operations}}
|
23
|
+
{{/apis}}
|
24
|
+
];
|
25
|
+
|
26
|
+
export type APIS = APIS_IN_ORDER[number];
|
27
|
+
|
28
|
+
export declare interface Type<T> extends Function {
|
29
|
+
new (...args: any[]): T;
|
30
|
+
}
|
31
|
+
|
32
|
+
export const ApiContext = createContext<{ getApi: <T extends APIS>(api: Type<T>) => T | undefined }>({
|
33
|
+
getApi: () => undefined,
|
34
|
+
});
|
35
|
+
|
36
|
+
export const getApiInstance = <TArray extends APIS[], T extends TArray[number]>(
|
37
|
+
api: Type<T>,
|
38
|
+
apis: TArray
|
39
|
+
): T => {
|
40
|
+
return apis.find((a) => a instanceof api) as T;
|
41
|
+
};
|
42
|
+
|
43
|
+
export const ApiProvider: FC<PropsWithChildren<{ apis: APIS[] }>> = ({
|
44
|
+
apis,
|
45
|
+
children,
|
46
|
+
}) => {
|
47
|
+
const parent = useContext(ApiContext);
|
48
|
+
const getApi = useCallback(<T extends APIS>(api: Type<T>): T => {
|
49
|
+
const apiInstance = (apis.find((a) => a instanceof api) ?? parent.getApi(api)) as T | undefined;
|
50
|
+
if (!apiInstance) {
|
51
|
+
throw new Error(`API instance for ${api.name} not found. Please provide it using ApiProvider from '{{npmName}}'`);
|
52
|
+
}
|
53
|
+
return apiInstance;
|
54
|
+
}, [apis, parent.getApi]);
|
55
|
+
const value = useMemo(() => ({ getApi }), [getApi]);
|
56
|
+
|
57
|
+
return (
|
58
|
+
<ApiContext.Provider value={value}>
|
59
|
+
{children}
|
60
|
+
</ApiContext.Provider>
|
61
|
+
);
|
62
|
+
};
|
63
|
+
|
64
|
+
export const useApi = <T extends APIS>(api: Type<T>): T => {
|
65
|
+
const { getApi } = useContext(ApiContext);
|
66
|
+
return getApi(api);
|
67
|
+
}
|
68
|
+
|
69
|
+
export const ApiConfigContext = createContext<runtime.ConfigurationParameters>({});
|
70
|
+
|
71
|
+
export const ApiConfigProvider: FC<PropsWithChildren<{ config: runtime.ConfigurationParameters }>> = ({
|
72
|
+
config,
|
73
|
+
children,
|
74
|
+
}) => {
|
75
|
+
return (
|
76
|
+
<ApiConfigContext.Provider value={config}>
|
77
|
+
{children}
|
78
|
+
</ApiConfigContext.Provider>
|
79
|
+
);
|
80
|
+
};
|
81
|
+
|
82
|
+
export const ApiConfigWithInheritProvider: FC<PropsWithChildren<{ config: runtime.ConfigurationParameters }>> = ({
|
83
|
+
config,
|
84
|
+
children,
|
85
|
+
}) => {
|
86
|
+
const parent = useContext(ApiConfigContext);
|
87
|
+
const value = useMemo(() => ({
|
88
|
+
...parent,
|
89
|
+
...config,
|
90
|
+
middleware: [...parent.middleware ?? [], ...config.middleware ?? []],
|
91
|
+
headers: { ...parent.headers, ...config.headers },
|
92
|
+
}), [parent, config]);
|
93
|
+
|
94
|
+
return (
|
95
|
+
<ApiConfigContext.Provider value={value}>
|
96
|
+
{children}
|
97
|
+
</ApiConfigContext.Provider>
|
98
|
+
);
|
99
|
+
};
|
100
|
+
|
101
|
+
export const useApiConfig = (): runtime.Configuration => {
|
102
|
+
const configParameters = useContext(ApiConfigContext);
|
103
|
+
const config = useMemo(() => new runtime.Configuration(configParameters), [configParameters]);
|
104
|
+
return config;
|
105
|
+
}
|
106
|
+
|
107
|
+
type ReadonlyApiConstructorToType<T> = T extends [
|
108
|
+
infer ARRAYFIRST,
|
109
|
+
...infer ARRAYREST
|
110
|
+
]
|
111
|
+
? ARRAYFIRST extends InstanceType<infer ARRAYFIRSTTYPE>
|
112
|
+
? [InstanceType<ARRAYFIRST>, ...ReadonlyApiConstructorToType<ARRAYREST>]
|
113
|
+
: []
|
114
|
+
: [];
|
115
|
+
|
116
|
+
type ApiConstructorToType<T extends Array<unknown>> = T[0] extends undefined
|
117
|
+
? APIS_IN_ORDER
|
118
|
+
: ReadonlyApiConstructorToType<T> extends []
|
119
|
+
? APIS[]
|
120
|
+
: ReadonlyApiConstructorToType<T>;
|
121
|
+
|
122
|
+
export const createApiInstances = <T extends Type<APIS>[]>(
|
123
|
+
config: runtime.Configuration,
|
124
|
+
apis: T = [] as unknown as T
|
125
|
+
): ApiConstructorToType<T> => {
|
126
|
+
if (apis.length > 0) {
|
127
|
+
return apis.map((api) => new api(config)) as ApiConstructorToType<T>;
|
128
|
+
}
|
129
|
+
return [
|
130
|
+
{{#apis}}
|
131
|
+
{{#operations}}
|
132
|
+
new {{classname}}(config),
|
133
|
+
{{/operations}}
|
134
|
+
{{/apis}}
|
135
|
+
] as unknown as ApiConstructorToType<T>;
|
136
|
+
};
|
137
|
+
|
138
|
+
export const useCreateApiInstances = <T extends Type<APIS>[]>(
|
139
|
+
apis: T = [] as unknown as T
|
140
|
+
): ApiConstructorToType<T> => {
|
141
|
+
const config = useApiConfig();
|
142
|
+
return useMemo(() => createApiInstances(config, apis), [apis, config]);
|
143
|
+
};
|
144
|
+
{{/apiInfo}}
|
145
|
+
|
146
|
+
export const ApiInstancesProvider: FC<PropsWithChildren<{ apis: Type<APIS>[] }>> = (
|
147
|
+
{ apis, children }
|
148
|
+
) => {
|
149
|
+
const apiInstances = useCreateApiInstances(apis);
|
150
|
+
return (
|
151
|
+
<ApiProvider apis={apiInstances}>
|
152
|
+
{children}
|
153
|
+
</ApiProvider>
|
154
|
+
);
|
155
|
+
};
|
@@ -12,6 +12,12 @@
|
|
12
12
|
"documentationProvider": "none",
|
13
13
|
"annotationLibrary": "none",
|
14
14
|
"useSpringBoot3": true,
|
15
|
+
"typeMappings": {
|
16
|
+
"OffsetDateTime": "java.time.Instant"
|
17
|
+
},
|
18
|
+
"importMappings": {
|
19
|
+
"java.time.OffsetDateTime": "java.time.Instant"
|
20
|
+
},
|
15
21
|
"inlineSchemaOptions": {
|
16
22
|
"ARRAY_ITEM_SUFFIX": "",
|
17
23
|
"MAP_ITEM_SUFFIX": "",
|
@@ -9,9 +9,13 @@
|
|
9
9
|
"documentationProvider": "none",
|
10
10
|
"useSpringBoot3": true,
|
11
11
|
"typeMappings": {
|
12
|
+
"DateTime": "java.time.Instant",
|
13
|
+
"OffsetDateTime": "java.time.Instant",
|
12
14
|
"org.springframework.core.io.Resource": "org.springframework.web.multipart.MultipartFile"
|
13
15
|
},
|
14
16
|
"importMappings": {
|
17
|
+
"DateTime": "java.time.Instant",
|
18
|
+
"java.time.OffsetDateTime": "java.time.Instant",
|
15
19
|
"org.springframework.core.io.Resource": "org.springframework.web.multipart.MultipartFile"
|
16
20
|
},
|
17
21
|
"inlineSchemaOptions": {
|