@team-supercharge/oasg 13.1.0-kmp-8a9ad834.0 → 13.1.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 +0 -27
- package/bin/oasg +3 -4
- package/config.schema.yml +0 -26
- package/package.json +1 -1
- 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/kmp/generate.sh +0 -21
- package/targets/kmp/generator-config.json +0 -12
- package/targets/kmp/publish.sh +0 -11
- package/targets/kmp/templates/build.gradle.kts.mustache +0 -121
- package/targets/kmp/templates/libraries/multiplatform/api.mustache +0 -136
package/README.md
CHANGED
@@ -637,33 +637,6 @@ TBD
|
|
637
637
|
| repository | URL of the generated client api code repository | Y | - |
|
638
638
|
| generatorCustomArgs | Custom arguments of the generator | N | - |
|
639
639
|
|
640
|
-
#### `kmp`
|
641
|
-
|
642
|
-
```json
|
643
|
-
{
|
644
|
-
"id": "client-kmp",
|
645
|
-
"type": "kmp",
|
646
|
-
"source": "source-merged",
|
647
|
-
"packageName": "io.supercharge.oasg.example",
|
648
|
-
"groupId": "io.supercharge.oasg.example",
|
649
|
-
"artifactId": "client",
|
650
|
-
"generatorCustomArgs": "--model-name-suffix=ApiModel",
|
651
|
-
"formatter": "1.0.0",
|
652
|
-
"formatterCustomArgs": "--disabled_rules=no-wildcard-imports,max-line-length,enum-entry-name-case",
|
653
|
-
"repository": "https://gitlab.supercharge.io/api/v4/projects/1226/packages/maven"
|
654
|
-
}
|
655
|
-
```
|
656
|
-
|
657
|
-
|Parameter| Description| Required | Default |
|
658
|
-
|-|-|-|-|
|
659
|
-
| packageName | Kotlin package name of the generated client | Y | - |
|
660
|
-
| groupId | Generated artifact package's organization | Y | - |
|
661
|
-
| artifactId | Generated artifact id | Y | - |
|
662
|
-
| generatorCustomArgs | Custom arguments of the generator | N | - |
|
663
|
-
| formatter | `ktlint`: it can be a released version or a http(s) url | N | 1.0.0 |
|
664
|
-
| formatterCustomArgs | Custom arguments of the `ktlint` formatter | N | --disabled_rules=no-wildcard-imports,max-line-length,enum-entry-name-case |
|
665
|
-
| repository | URL of the Maven Repository | N | - |
|
666
|
-
|
667
640
|
#### `python`
|
668
641
|
|
669
642
|
```json
|
package/bin/oasg
CHANGED
@@ -39,7 +39,6 @@ const DEFAULT_GENERATOR_MAPPING = {
|
|
39
39
|
"feign-kotlin": { version: '7.0.1', generator: 'kotlin-spring' },
|
40
40
|
"flutter": { version: '7.0.1', generator: 'dart-dio' },
|
41
41
|
"ios": { version: '7.0.1', generator: 'swift5' },
|
42
|
-
"kmp": { version: 'https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.2.0-SNAPSHOT/openapi-generator-cli-7.2.0-20231208.144106-84.jar', generator: 'kotlin' },
|
43
42
|
"python": { version: '7.0.1', generator: 'python' },
|
44
43
|
"react": { version: '7.0.1', generator: 'typescript-fetch' },
|
45
44
|
// server targets
|
@@ -248,10 +247,10 @@ async function parseConfig() {
|
|
248
247
|
}
|
249
248
|
})
|
250
249
|
|
251
|
-
// set default ktlint to android
|
250
|
+
// set default ktlint to android targets with undefined
|
252
251
|
config.targets.forEach(t => {
|
253
252
|
//TODO: handle different types of platform
|
254
|
-
if (t.type === 'android'
|
253
|
+
if (t.type === 'android') {
|
255
254
|
if (!t.formatter) {
|
256
255
|
t.formatter = DEFAULT_KTLINT_VERSION;
|
257
256
|
}
|
@@ -483,7 +482,7 @@ async function generate(argv) {
|
|
483
482
|
let formatter;
|
484
483
|
|
485
484
|
//TODO: handle different types of platforms
|
486
|
-
if (target.type === 'android'
|
485
|
+
if (target.type === 'android') {
|
487
486
|
formatter = fetchFormatter(target);
|
488
487
|
}
|
489
488
|
|
package/config.schema.yml
CHANGED
@@ -24,7 +24,6 @@ properties:
|
|
24
24
|
- $ref: '#/targets/NestJS'
|
25
25
|
- $ref: '#/targets/OpenAPI'
|
26
26
|
- $ref: '#/targets/Flutter'
|
27
|
-
- $ref: '#/targets/Kmp'
|
28
27
|
required:
|
29
28
|
- targets
|
30
29
|
additionalProperties: false
|
@@ -347,31 +346,6 @@ targets:
|
|
347
346
|
- packageName
|
348
347
|
- repository
|
349
348
|
|
350
|
-
Kmp:
|
351
|
-
allOf:
|
352
|
-
- $ref: '#/targets/Base'
|
353
|
-
- properties:
|
354
|
-
type:
|
355
|
-
pattern: "^kmp$"
|
356
|
-
packageName:
|
357
|
-
type: string
|
358
|
-
groupId:
|
359
|
-
type: string
|
360
|
-
artifactId:
|
361
|
-
type: string
|
362
|
-
formatter:
|
363
|
-
type: string
|
364
|
-
pattern: '^(\d+\.\d+\.\d+(-.+)?)|(^http(s)?:\/\/.+$)$' # matches: 0.0.0(-pre) and http(s)://XXX
|
365
|
-
formatterCustomArgs:
|
366
|
-
type: string
|
367
|
-
repository:
|
368
|
-
type: string
|
369
|
-
required:
|
370
|
-
- packageName
|
371
|
-
- groupId
|
372
|
-
- artifactId
|
373
|
-
- repository
|
374
|
-
|
375
349
|
definitions:
|
376
350
|
# default
|
377
351
|
SourceOverrides:
|
package/package.json
CHANGED
@@ -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
|
+
};
|
package/targets/kmp/generate.sh
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
#/bin/bash
|
2
|
-
|
3
|
-
source $(dirname "$0")/../common.sh
|
4
|
-
|
5
|
-
rm -rf out/$targetId
|
6
|
-
mkdir -p out/$targetId
|
7
|
-
|
8
|
-
if [ -z "$formatterCustomArgs" ]
|
9
|
-
then
|
10
|
-
formatterCustomArgs="--disabled_rules=no-wildcard-imports,max-line-length,enum-entry-name-case"
|
11
|
-
fi
|
12
|
-
|
13
|
-
java -jar $binary generate \
|
14
|
-
-g $generatorId \
|
15
|
-
-i $openApiFile \
|
16
|
-
-t $templateDir \
|
17
|
-
-o out/$targetId \
|
18
|
-
-c $(dirname "$0")/generator-config.json \
|
19
|
-
-p "artifactId=${artifactId},groupId=${groupId},packageName=${packageName},artifactVersion=${version}" $generatorCustomArgs
|
20
|
-
|
21
|
-
$formatterBinary -F "out/$targetId/src/**/*.kt" $formatterCustomArgs
|
@@ -1,12 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"library": "multiplatform",
|
3
|
-
"enumPropertyNaming": "original",
|
4
|
-
"dateLibrary": "kotlinx-datetime",
|
5
|
-
"useCoroutines": true,
|
6
|
-
"omitGradleWrapper": false,
|
7
|
-
"inlineSchemaOptions": {
|
8
|
-
"ARRAY_ITEM_SUFFIX": "",
|
9
|
-
"MAP_ITEM_SUFFIX": "",
|
10
|
-
"SKIP_SCHEMA_REUSE": "true"
|
11
|
-
}
|
12
|
-
}
|
package/targets/kmp/publish.sh
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
2
|
-
|
3
|
-
plugins {
|
4
|
-
kotlin("multiplatform"){{^omitGradlePluginVersions}} version "1.9.20" // kotlin_version{{/omitGradlePluginVersions}}
|
5
|
-
kotlin("plugin.serialization"){{^omitGradlePluginVersions}} version "1.9.20" // kotlin_version{{/omitGradlePluginVersions}}
|
6
|
-
id("maven-publish") // OASg added for publication
|
7
|
-
}
|
8
|
-
|
9
|
-
group = "{{groupId}}"
|
10
|
-
version = "{{artifactVersion}}"
|
11
|
-
|
12
|
-
val kotlin_version = "1.9.20"
|
13
|
-
val coroutines_version = "1.7.3"
|
14
|
-
val serialization_version = "1.6.1"
|
15
|
-
val ktor_version = "2.3.6"
|
16
|
-
|
17
|
-
repositories {
|
18
|
-
mavenCentral()
|
19
|
-
}
|
20
|
-
|
21
|
-
kotlin {
|
22
|
-
jvm()
|
23
|
-
iosX64()
|
24
|
-
iosArm64()
|
25
|
-
iosSimulatorArm64()
|
26
|
-
js {
|
27
|
-
browser()
|
28
|
-
nodejs()
|
29
|
-
}
|
30
|
-
|
31
|
-
sourceSets {
|
32
|
-
commonMain {
|
33
|
-
dependencies {
|
34
|
-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
|
35
|
-
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serialization_version")
|
36
|
-
|
37
|
-
api("io.ktor:ktor-client-core:$ktor_version")
|
38
|
-
api("io.ktor:ktor-client-serialization:$ktor_version")
|
39
|
-
api("io.ktor:ktor-client-content-negotiation:$ktor_version")
|
40
|
-
api("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
|
41
|
-
|
42
|
-
{{#kotlinx-datetime}}
|
43
|
-
api("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")
|
44
|
-
{{/kotlinx-datetime}}
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
commonTest {
|
49
|
-
dependencies {
|
50
|
-
implementation(kotlin("test"))
|
51
|
-
implementation("io.ktor:ktor-client-mock:$ktor_version")
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
jvmMain {
|
56
|
-
dependencies {
|
57
|
-
implementation(kotlin("stdlib-jdk7"))
|
58
|
-
implementation("io.ktor:ktor-client-cio-jvm:$ktor_version")
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
jvmTest {
|
63
|
-
dependencies {
|
64
|
-
implementation(kotlin("test-junit"))
|
65
|
-
}
|
66
|
-
}
|
67
|
-
|
68
|
-
iosMain {
|
69
|
-
dependencies {
|
70
|
-
api("io.ktor:ktor-client-ios:$ktor_version")
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
jsMain {
|
75
|
-
dependencies {
|
76
|
-
api("io.ktor:ktor-client-js:$ktor_version")
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
all {
|
81
|
-
languageSettings.apply {
|
82
|
-
optIn("kotlin.Experimental")
|
83
|
-
}
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
tasks {
|
89
|
-
register("iosTest") {
|
90
|
-
val device = project.findProperty("device")?.toString() ?: "iPhone 8"
|
91
|
-
dependsOn("linkDebugTestIosX64")
|
92
|
-
group = JavaBasePlugin.VERIFICATION_GROUP
|
93
|
-
description = "Execute unit tests on ${device} simulator"
|
94
|
-
doLast {
|
95
|
-
val binary = kotlin.targets.getByName<KotlinNativeTarget>("iosX64").binaries.getTest("DEBUG")
|
96
|
-
exec {
|
97
|
-
commandLine("xcrun", "simctl", "spawn", device, binary.outputFile)
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
101
|
-
register("test") {
|
102
|
-
dependsOn("allTests")
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
// OASg added for publication
|
107
|
-
publishing {
|
108
|
-
repositories {
|
109
|
-
maven {
|
110
|
-
name = "Gitlab"
|
111
|
-
url = uri(project.property("repoUrl")!!)
|
112
|
-
credentials(HttpHeaderCredentials::class) {
|
113
|
-
name = "Job-Token"
|
114
|
-
value = System.getenv("CI_JOB_TOKEN")
|
115
|
-
}
|
116
|
-
authentication {
|
117
|
-
create<HttpHeaderAuthentication>("header")
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
}
|
@@ -1,136 +0,0 @@
|
|
1
|
-
{{>licenseInfo}}
|
2
|
-
package {{apiPackage}}
|
3
|
-
|
4
|
-
{{#imports}}import {{import}}
|
5
|
-
{{/imports}}
|
6
|
-
|
7
|
-
import {{packageName}}.infrastructure.*
|
8
|
-
import io.ktor.client.HttpClient
|
9
|
-
import io.ktor.client.HttpClientConfig
|
10
|
-
import io.ktor.client.call.body
|
11
|
-
import io.ktor.client.request.forms.formData
|
12
|
-
import io.ktor.client.engine.HttpClientEngine
|
13
|
-
import kotlinx.serialization.json.Json
|
14
|
-
import io.ktor.http.ParametersBuilder
|
15
|
-
import kotlinx.serialization.*
|
16
|
-
import kotlinx.serialization.descriptors.*
|
17
|
-
import kotlinx.serialization.encoding.*
|
18
|
-
|
19
|
-
{{#operations}}
|
20
|
-
{{#nonPublicApi}}internal {{/nonPublicApi}}open class {{classname}} : ApiClient {
|
21
|
-
|
22
|
-
constructor(
|
23
|
-
baseUrl: String = ApiClient.BASE_URL,
|
24
|
-
httpClientEngine: HttpClientEngine? = null,
|
25
|
-
httpClientConfig: ((HttpClientConfig<*>) -> Unit)? = null,
|
26
|
-
jsonSerializer: Json = ApiClient.JSON_DEFAULT
|
27
|
-
) : super(baseUrl = baseUrl, httpClientEngine = httpClientEngine, httpClientConfig = httpClientConfig, jsonBlock = jsonSerializer)
|
28
|
-
|
29
|
-
constructor(
|
30
|
-
baseUrl: String,
|
31
|
-
httpClient: HttpClient
|
32
|
-
): super(baseUrl = baseUrl, httpClient = httpClient)
|
33
|
-
|
34
|
-
{{#operation}}
|
35
|
-
{{#allParams}}
|
36
|
-
{{#isEnum}}
|
37
|
-
|
38
|
-
/**
|
39
|
-
* enum for parameter {{paramName}}
|
40
|
-
*/
|
41
|
-
@Serializable
|
42
|
-
{{#nonPublicApi}}internal {{/nonPublicApi}}enum class {{enumName}}{{operationIdCamelCase}}(val value: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}kotlin.String{{/isContainer}}) {
|
43
|
-
{{^enumUnknownDefaultCase}}
|
44
|
-
{{#allowableValues}}{{#enumVars}}
|
45
|
-
@SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}})
|
46
|
-
{{&name}}({{{value}}}){{^-last}},{{/-last}}
|
47
|
-
{{/enumVars}}{{/allowableValues}}
|
48
|
-
{{/enumUnknownDefaultCase}}
|
49
|
-
{{#enumUnknownDefaultCase}}
|
50
|
-
{{#allowableValues}}{{#enumVars}}{{^-last}}
|
51
|
-
@SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}})
|
52
|
-
{{&name}}({{{value}}}),
|
53
|
-
{{/-last}}{{/enumVars}}{{/allowableValues}}
|
54
|
-
{{/enumUnknownDefaultCase}}
|
55
|
-
}
|
56
|
-
|
57
|
-
{{/isEnum}}
|
58
|
-
{{/allParams}}
|
59
|
-
/**
|
60
|
-
* {{summary}}
|
61
|
-
* {{notes}}
|
62
|
-
{{#allParams}} * @param {{{paramName}}} {{description}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}{{/required}}
|
63
|
-
{{/allParams}} * @return {{{returnType}}}{{^returnType}}void{{/returnType}}
|
64
|
-
*/
|
65
|
-
{{#returnType}}
|
66
|
-
@Suppress("UNCHECKED_CAST")
|
67
|
-
{{/returnType}}
|
68
|
-
open suspend fun {{operationId}}({{#allParams}}{{{paramName}}}: {{#isEnum}}{{#isContainer}}kotlin.collections.List<{{enumName}}{{operationIdCamelCase}}>{{/isContainer}}{{^isContainer}}{{enumName}}{{operationIdCamelCase}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#required}}{{#defaultValue}} = {{^isNumber}}{{#isEnum}}{{enumName}}{{operationIdCamelCase}}.{{enumDefaultValue}}{{/isEnum}}{{^isEnum}}{{{defaultValue}}}{{/isEnum}}{{/isNumber}}{{#isNumber}}{{{defaultValue}}}.toDouble(){{/isNumber}}{{/defaultValue}}{{/required}}{{^required}}?{{#defaultValue}} = {{^isNumber}}{{#isEnum}}{{enumName}}{{operationIdCamelCase}}.{{enumDefaultValue}}{{/isEnum}}{{^isEnum}}{{{defaultValue}}}{{/isEnum}}{{/isNumber}}{{#isNumber}}{{{defaultValue}}}.toDouble(){{/isNumber}}{{/defaultValue}}{{^defaultValue}} = null{{/defaultValue}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}): {{{returnType}}}{{^returnType}}Unit{{/returnType}} {
|
69
|
-
|
70
|
-
val localVariableAuthNames = listOf<String>({{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}})
|
71
|
-
|
72
|
-
val localVariableBody = {{#hasBodyParam}}{{#bodyParam}}{{#isArray}}{{operationIdCamelCase}}Request({{{paramName}}}{{^isList}}.asList(){{/isList}}){{/isArray}}{{^isArray}}{{#isMap}}{{operationIdCamelCase}}Request({{{paramName}}}){{/isMap}}{{^isMap}}{{{paramName}}}{{/isMap}}{{/isArray}}{{/bodyParam}}{{/hasBodyParam}}
|
73
|
-
{{^hasBodyParam}}
|
74
|
-
{{#hasFormParams}}
|
75
|
-
{{#isMultipart}}
|
76
|
-
formData {
|
77
|
-
{{#formParams}}
|
78
|
-
{{#isArray}}
|
79
|
-
{{{paramName}}}?.onEach {
|
80
|
-
append("{{{baseName}}}[]", it)
|
81
|
-
}
|
82
|
-
{{/isArray}}
|
83
|
-
{{^isArray}}
|
84
|
-
{{{paramName}}}?.apply { append("{{{baseName}}}", {{{paramName}}}) }
|
85
|
-
{{/isArray}}
|
86
|
-
{{/formParams}}
|
87
|
-
}
|
88
|
-
{{/isMultipart}}
|
89
|
-
{{^isMultipart}}
|
90
|
-
ParametersBuilder().also {
|
91
|
-
{{#formParams}}
|
92
|
-
{{{paramName}}}?.apply { it.append("{{{baseName}}}", {{{paramName}}}.toString()) }
|
93
|
-
{{/formParams}}
|
94
|
-
}.build()
|
95
|
-
{{/isMultipart}}
|
96
|
-
{{/hasFormParams}}
|
97
|
-
{{^hasFormParams}}
|
98
|
-
io.ktor.client.utils.EmptyContent
|
99
|
-
{{/hasFormParams}}
|
100
|
-
{{/hasBodyParam}}
|
101
|
-
|
102
|
-
val localVariableQuery = mutableMapOf<String, List<String>>(){{#queryParams}}
|
103
|
-
{{{paramName}}}?.apply { localVariableQuery["{{baseName}}"] = {{#isContainer}}toMultiValue(this, "{{collectionFormat}}"){{/isContainer}}{{^isContainer}}listOf("${{{paramName}}}"){{/isContainer}} }{{/queryParams}}
|
104
|
-
val localVariableHeaders = mutableMapOf<String, String>(){{#headerParams}}
|
105
|
-
{{{paramName}}}?.apply { localVariableHeaders["{{baseName}}"] = {{#isContainer}}this.joinToString(separator = collectionDelimiter("{{collectionFormat}}")){{/isContainer}}{{^isContainer}}this.toString(){{/isContainer}} }{{/headerParams}}
|
106
|
-
|
107
|
-
val localVariableConfig = RequestConfig<kotlin.Any?>(
|
108
|
-
RequestMethod.{{httpMethod}},
|
109
|
-
"{{path}}"{{#pathParams}}.replace("{" + "{{baseName}}" + "}", {{#isContainer}}{{paramName}}.joinToString(","){{/isContainer}}{{^isContainer}}"${{{paramName}}}"{{/isContainer}}){{/pathParams}},
|
110
|
-
query = localVariableQuery,
|
111
|
-
headers = localVariableHeaders,
|
112
|
-
requiresAuthentication = {{#hasAuthMethods}}true{{/hasAuthMethods}}{{^hasAuthMethods}}false{{/hasAuthMethods}},
|
113
|
-
)
|
114
|
-
|
115
|
-
return {{#hasBodyParam}}jsonRequest{{/hasBodyParam}}{{^hasBodyParam}}{{#hasFormParams}}{{#isMultipart}}multipartFormRequest{{/isMultipart}}{{^isMultipart}}urlEncodedFormRequest{{/isMultipart}}{{/hasFormParams}}{{^hasFormParams}}request{{/hasFormParams}}{{/hasBodyParam}}(
|
116
|
-
localVariableConfig,
|
117
|
-
localVariableBody,
|
118
|
-
localVariableAuthNames
|
119
|
-
).body()
|
120
|
-
}
|
121
|
-
|
122
|
-
{{#hasBodyParam}}
|
123
|
-
{{#bodyParam}}
|
124
|
-
{{#isArray}}{{>serial_wrapper_request_list}}{{/isArray}}{{#isMap}}{{>serial_wrapper_request_map}}{{/isMap}}
|
125
|
-
{{/bodyParam}}
|
126
|
-
{{/hasBodyParam}}
|
127
|
-
{{#isArray}}
|
128
|
-
{{>serial_wrapper_response_list}}
|
129
|
-
{{/isArray}}
|
130
|
-
{{#isMap}}
|
131
|
-
{{>serial_wrapper_response_map}}
|
132
|
-
{{/isMap}}
|
133
|
-
|
134
|
-
{{/operation}}
|
135
|
-
}
|
136
|
-
{{/operations}}
|