@goast/kotlin 0.4.18-springwebclient1 → 0.4.19
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/LICENSE +21 -21
- package/README.md +45 -45
- package/assets/client/okhttp3/ApiClient.kt +252 -252
- package/assets/client/spring-reactive-web-clients/ApiRequestFile.kt +33 -33
- package/esm/src/generators/models/model-generator.js +2 -2
- package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +28 -28
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.js +9 -9
- package/esm/src/generators/services/spring-reactive-web-clients/models.d.ts +1 -1
- package/esm/src/generators/services/spring-reactive-web-clients/models.d.ts.map +1 -1
- package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts.map +1 -1
- package/package.json +2 -2
- package/script/src/generators/models/model-generator.js +2 -2
- package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +28 -28
- package/script/src/generators/services/spring-controllers/spring-controller-generator.js +9 -9
- package/script/src/generators/services/spring-reactive-web-clients/models.d.ts +1 -1
- package/script/src/generators/services/spring-reactive-web-clients/models.d.ts.map +1 -1
- package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts.map +1 -1
- package/src/mod.ts +8 -0
- package/src/src/assets.ts +9 -0
- package/src/src/ast/_index.ts +66 -0
- package/src/src/ast/common.ts +1 -0
- package/src/src/ast/index.ts +1 -0
- package/src/src/ast/node.ts +10 -0
- package/src/src/ast/nodes/annotation.ts +79 -0
- package/src/src/ast/nodes/argument.ts +62 -0
- package/src/src/ast/nodes/call.ts +75 -0
- package/src/src/ast/nodes/class.ts +178 -0
- package/src/src/ast/nodes/collection-literal.ts +49 -0
- package/src/src/ast/nodes/constructor.ts +126 -0
- package/src/src/ast/nodes/doc-tag.ts +138 -0
- package/src/src/ast/nodes/doc.ts +111 -0
- package/src/src/ast/nodes/enum-value.ts +100 -0
- package/src/src/ast/nodes/enum.ts +163 -0
- package/src/src/ast/nodes/function.ts +178 -0
- package/src/src/ast/nodes/generic-parameter.ts +54 -0
- package/src/src/ast/nodes/init-block.ts +38 -0
- package/src/src/ast/nodes/interface.ts +133 -0
- package/src/src/ast/nodes/lambda-type.ts +73 -0
- package/src/src/ast/nodes/lambda.ts +74 -0
- package/src/src/ast/nodes/object.ts +102 -0
- package/src/src/ast/nodes/parameter.ts +118 -0
- package/src/src/ast/nodes/property.ts +225 -0
- package/src/src/ast/nodes/reference.ts +178 -0
- package/src/src/ast/nodes/string.ts +114 -0
- package/src/src/ast/nodes/types.ts +23 -0
- package/src/src/ast/references/index.ts +10 -0
- package/src/src/ast/references/jackson.ts +24 -0
- package/src/src/ast/references/jakarta.ts +14 -0
- package/src/src/ast/references/java.ts +20 -0
- package/src/src/ast/references/kotlin.ts +41 -0
- package/src/src/ast/references/kotlinx.ts +14 -0
- package/src/src/ast/references/okhttp3.ts +5 -0
- package/src/src/ast/references/reactor.ts +5 -0
- package/src/src/ast/references/spring-reactive.ts +33 -0
- package/src/src/ast/references/spring.ts +86 -0
- package/src/src/ast/references/swagger.ts +23 -0
- package/src/src/ast/utils/get-kotlin-builder-options.ts +19 -0
- package/src/src/ast/utils/to-kt-node.ts +31 -0
- package/src/src/ast/utils/write-kt-annotations.ts +15 -0
- package/src/src/ast/utils/write-kt-arguments.ts +45 -0
- package/src/src/ast/utils/write-kt-enum-values.ts +27 -0
- package/src/src/ast/utils/write-kt-generic-parameters.ts +12 -0
- package/src/src/ast/utils/write-kt-members.ts +25 -0
- package/src/src/ast/utils/write-kt-node.ts +37 -0
- package/src/src/ast/utils/write-kt-parameters.ts +25 -0
- package/src/src/common-results.ts +4 -0
- package/src/src/config.ts +41 -0
- package/src/src/file-builder.ts +108 -0
- package/src/src/generators/file-generator.ts +29 -0
- package/src/src/generators/index.ts +5 -0
- package/src/src/generators/models/args.ts +132 -0
- package/src/src/generators/models/index.ts +4 -0
- package/src/src/generators/models/model-generator.ts +691 -0
- package/src/src/generators/models/models-generator.ts +65 -0
- package/src/src/generators/models/models.ts +95 -0
- package/src/src/generators/services/okhttp3-clients/args.ts +88 -0
- package/src/src/generators/services/okhttp3-clients/index.ts +4 -0
- package/src/src/generators/services/okhttp3-clients/models.ts +62 -0
- package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +594 -0
- package/src/src/generators/services/okhttp3-clients/okhttp3-clients-generator.ts +130 -0
- package/src/src/generators/services/okhttp3-clients/refs.ts +55 -0
- package/src/src/generators/services/spring-controllers/args.ts +93 -0
- package/src/src/generators/services/spring-controllers/index.ts +4 -0
- package/src/src/generators/services/spring-controllers/models.ts +71 -0
- package/src/src/generators/services/spring-controllers/refs.ts +17 -0
- package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +814 -0
- package/src/src/generators/services/spring-controllers/spring-controllers-generator.ts +118 -0
- package/src/src/generators/services/spring-reactive-web-clients/args.ts +101 -0
- package/src/src/generators/services/spring-reactive-web-clients/index.ts +4 -0
- package/src/src/generators/services/spring-reactive-web-clients/models.ts +62 -0
- package/src/src/generators/services/spring-reactive-web-clients/refs.ts +11 -0
- package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.ts +572 -0
- package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.ts +128 -0
- package/src/src/import-collection.ts +98 -0
- package/src/src/types.ts +3 -0
- package/src/src/utils.ts +39 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ApiSchema,
|
|
3
|
+
Factory,
|
|
4
|
+
type MaybePromise,
|
|
5
|
+
type OpenApiGeneratorContext,
|
|
6
|
+
OpenApiSchemasGenerationProviderBase,
|
|
7
|
+
} from '@goast/core';
|
|
8
|
+
|
|
9
|
+
import { DefaultKotlinModelGenerator, type KotlinModelGenerator } from './model-generator.js';
|
|
10
|
+
import {
|
|
11
|
+
defaultKotlinModelsGeneratorConfig,
|
|
12
|
+
type KotlinModelGeneratorOutput,
|
|
13
|
+
type KotlinModelsGeneratorConfig,
|
|
14
|
+
type KotlinModelsGeneratorContext,
|
|
15
|
+
type KotlinModelsGeneratorInput,
|
|
16
|
+
type KotlinModelsGeneratorOutput,
|
|
17
|
+
} from './models.js';
|
|
18
|
+
|
|
19
|
+
type Input = KotlinModelsGeneratorInput;
|
|
20
|
+
type Output = KotlinModelsGeneratorOutput;
|
|
21
|
+
type Config = KotlinModelsGeneratorConfig;
|
|
22
|
+
type SchemaOutput = KotlinModelGeneratorOutput;
|
|
23
|
+
type Context = KotlinModelsGeneratorContext;
|
|
24
|
+
|
|
25
|
+
export class KotlinModelsGenerator extends OpenApiSchemasGenerationProviderBase<
|
|
26
|
+
Input,
|
|
27
|
+
Output,
|
|
28
|
+
Config,
|
|
29
|
+
SchemaOutput,
|
|
30
|
+
Context
|
|
31
|
+
> {
|
|
32
|
+
private readonly _modelGeneratorFactory: Factory<KotlinModelGenerator, []>;
|
|
33
|
+
|
|
34
|
+
constructor(modelGeneratorFactory?: Factory<KotlinModelGenerator, []>) {
|
|
35
|
+
super();
|
|
36
|
+
this._modelGeneratorFactory = modelGeneratorFactory ?? Factory.fromValue(new DefaultKotlinModelGenerator());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
protected override initResult(): Output {
|
|
40
|
+
return {
|
|
41
|
+
kotlin: {
|
|
42
|
+
models: {},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected override buildContext(
|
|
48
|
+
context: OpenApiGeneratorContext<KotlinModelsGeneratorInput>,
|
|
49
|
+
config?: Partial<Config> | undefined,
|
|
50
|
+
): Context {
|
|
51
|
+
return this.getProviderContext(context, config, defaultKotlinModelsGeneratorConfig);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
protected override generateSchema(ctx: Context, schema: ApiSchema): MaybePromise<SchemaOutput> {
|
|
55
|
+
const modelGenerator = this._modelGeneratorFactory.create();
|
|
56
|
+
return modelGenerator.generate({
|
|
57
|
+
...ctx,
|
|
58
|
+
schema,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected override addSchemaResult(ctx: Context, schema: ApiSchema, result: SchemaOutput): void {
|
|
63
|
+
ctx.output.kotlin.models[schema.id] = result;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ApiSchema,
|
|
3
|
+
DefaultGenerationProviderConfig,
|
|
4
|
+
OpenApiSchemasGenerationProviderContext,
|
|
5
|
+
SourceBuilder,
|
|
6
|
+
} from '@goast/core';
|
|
7
|
+
|
|
8
|
+
import type { kt } from '../../ast/index.js';
|
|
9
|
+
import { defaultKotlinGeneratorConfig, type KotlinGeneratorConfig } from '../../config.js';
|
|
10
|
+
|
|
11
|
+
export type KotlinModelsGeneratorConfig = KotlinGeneratorConfig & {
|
|
12
|
+
/**
|
|
13
|
+
* The package name for generated models.
|
|
14
|
+
* @default 'com.openapi.generated'
|
|
15
|
+
*/
|
|
16
|
+
packageName: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The suffix to append to the package name for generated models.
|
|
20
|
+
* @default '.model'
|
|
21
|
+
*/
|
|
22
|
+
packageSuffix: string | ((schema: ApiSchema) => string);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Determines how `oneOf` schemas should be treated.
|
|
26
|
+
* - `treat-as-any-of`: Treat `oneOf` schemas as `anyOf` schemas.
|
|
27
|
+
* - `treat-as-all-of`: Treat `oneOf` schemas as `allOf` schemas.
|
|
28
|
+
* @default 'treat-as-any-of'
|
|
29
|
+
*/
|
|
30
|
+
oneOfBehavior: 'treat-as-any-of' | 'treat-as-all-of';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Determines how schemas of type `object` without properties should be treated.
|
|
34
|
+
* - `use-any`: Generate `Any` type for empty object schemas.
|
|
35
|
+
* - `generate-empty-class`: Generate an empty class for empty object schemas.
|
|
36
|
+
* @default 'generate-empty-class'
|
|
37
|
+
*/
|
|
38
|
+
emptyObjectTypeBehavior: 'use-any' | 'generate-empty-class';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Whether to add Jackson annotations to generated models.
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
addJacksonAnnotations: boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Whether to add Jakarta Validation annotations to generated models.
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
addJakartaValidationAnnotations: boolean;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Whether to add Swagger annotations to generated models.
|
|
54
|
+
* @default true
|
|
55
|
+
*/
|
|
56
|
+
addSwaggerAnnotations: boolean;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const defaultKotlinModelsGeneratorConfig: DefaultGenerationProviderConfig<KotlinModelsGeneratorConfig> = {
|
|
60
|
+
...defaultKotlinGeneratorConfig,
|
|
61
|
+
|
|
62
|
+
packageName: 'com.openapi.generated',
|
|
63
|
+
packageSuffix: '.model',
|
|
64
|
+
oneOfBehavior: 'treat-as-any-of',
|
|
65
|
+
|
|
66
|
+
emptyObjectTypeBehavior: 'generate-empty-class',
|
|
67
|
+
|
|
68
|
+
addJacksonAnnotations: true,
|
|
69
|
+
addJakartaValidationAnnotations: true,
|
|
70
|
+
addSwaggerAnnotations: true,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// deno-lint-ignore ban-types
|
|
74
|
+
export type KotlinModelsGeneratorInput = {};
|
|
75
|
+
|
|
76
|
+
export type KotlinModelsGeneratorOutput = {
|
|
77
|
+
kotlin: {
|
|
78
|
+
models: {
|
|
79
|
+
[schemaId: string]: KotlinModelGeneratorOutput;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type KotlinModelGeneratorOutput = { type: kt.Reference<SourceBuilder> };
|
|
85
|
+
|
|
86
|
+
export type KotlinModelsGeneratorContext = OpenApiSchemasGenerationProviderContext<
|
|
87
|
+
KotlinModelsGeneratorInput,
|
|
88
|
+
KotlinModelsGeneratorOutput,
|
|
89
|
+
KotlinModelsGeneratorConfig,
|
|
90
|
+
KotlinModelGeneratorOutput
|
|
91
|
+
>;
|
|
92
|
+
|
|
93
|
+
export type KotlinModelGeneratorContext = KotlinModelsGeneratorContext & {
|
|
94
|
+
schema: ApiSchema;
|
|
95
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { ApiEndpoint, ApiParameter, ApiSchema, SourceBuilder } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import type { kt } from '../../../ast/index.js';
|
|
4
|
+
import type { ApiParameterWithMultipartInfo } from '../../../types.js';
|
|
5
|
+
|
|
6
|
+
export type GetClientFileContent = object;
|
|
7
|
+
|
|
8
|
+
export type GetClientClass = object;
|
|
9
|
+
|
|
10
|
+
export type GetClientCompanionObject = object;
|
|
11
|
+
|
|
12
|
+
export type GetEndpointClientMembers = { endpoint: ApiEndpoint; parameters: ApiParameter[] };
|
|
13
|
+
|
|
14
|
+
export type GetEndpointClientMethod = {
|
|
15
|
+
endpoint: ApiEndpoint;
|
|
16
|
+
parameters: ApiParameter[];
|
|
17
|
+
responseSchema: ApiSchema | undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type GetEndpointClientMethodBody = {
|
|
21
|
+
endpoint: ApiEndpoint;
|
|
22
|
+
parameters: ApiParameter[];
|
|
23
|
+
responseSchema: ApiSchema | undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type GetEndpointClientHttpInfoMethod = {
|
|
27
|
+
endpoint: ApiEndpoint;
|
|
28
|
+
parameters: ApiParameter[];
|
|
29
|
+
responseSchema: ApiSchema | undefined;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type GetEndpointClientHttpInfoMethodBody = {
|
|
33
|
+
endpoint: ApiEndpoint;
|
|
34
|
+
parameters: ApiParameter[];
|
|
35
|
+
responseSchema: ApiSchema | undefined;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type GetEndpointClientRequestConfigMethod = {
|
|
39
|
+
endpoint: ApiEndpoint;
|
|
40
|
+
parameters: ApiParameter[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type GetEndpointClientRequestConfigMethodBody = {
|
|
44
|
+
endpoint: ApiEndpoint;
|
|
45
|
+
parameters: ApiParameterWithMultipartInfo[];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type GetParameterToString = {
|
|
49
|
+
endpoint: ApiEndpoint;
|
|
50
|
+
parameter: ApiParameter;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type GetAdditionalClientMembers = object;
|
|
54
|
+
|
|
55
|
+
export type GetParameterType = { endpoint: ApiEndpoint; parameter: ApiParameterWithMultipartInfo };
|
|
56
|
+
|
|
57
|
+
export type GetRequestBodyType = { endpoint: ApiEndpoint };
|
|
58
|
+
|
|
59
|
+
export type GetParameterDefaultValue = {
|
|
60
|
+
endpoint: ApiEndpoint;
|
|
61
|
+
parameter: ApiParameter;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type GetTypeUsage<TBuilder extends SourceBuilder> = {
|
|
65
|
+
schema: ApiSchema | undefined;
|
|
66
|
+
nullable?: boolean;
|
|
67
|
+
fallback?: kt.Type<TBuilder>;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type GetPackageName = object;
|
|
71
|
+
|
|
72
|
+
export type GetPathWithInterpolation = { endpoint: ApiEndpoint };
|
|
73
|
+
|
|
74
|
+
export type GetResponseSchema = { endpoint: ApiEndpoint };
|
|
75
|
+
|
|
76
|
+
export type GetSchemaType = { schema: ApiSchema | undefined };
|
|
77
|
+
|
|
78
|
+
export type GetAllParameters = { endpoint: ApiEndpoint };
|
|
79
|
+
|
|
80
|
+
export type GetRequestBodyParamName = { endpoint: ApiEndpoint };
|
|
81
|
+
|
|
82
|
+
export type GetBasePath = object;
|
|
83
|
+
|
|
84
|
+
export type GetEndpointPath = { endpoint: ApiEndpoint };
|
|
85
|
+
|
|
86
|
+
export type GetFilePath = { packageName: string };
|
|
87
|
+
|
|
88
|
+
export type GetApiClientName = object;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ApiEndpoint,
|
|
3
|
+
ApiService,
|
|
4
|
+
DefaultGenerationProviderConfig,
|
|
5
|
+
OpenApiServicesGenerationProviderContext,
|
|
6
|
+
} from '@goast/core';
|
|
7
|
+
|
|
8
|
+
import type { KotlinImport } from '../../../common-results.js';
|
|
9
|
+
import { defaultKotlinGeneratorConfig, type KotlinGeneratorConfig } from '../../../config.js';
|
|
10
|
+
import type { KotlinModelsGeneratorOutput } from '../../models/index.js';
|
|
11
|
+
import type { getReferenceFactories } from './refs.js';
|
|
12
|
+
|
|
13
|
+
export type KotlinOkHttp3ClientsGeneratorConfig = KotlinGeneratorConfig & {
|
|
14
|
+
packageName: string;
|
|
15
|
+
packageSuffix: string | ((service?: ApiService) => string);
|
|
16
|
+
infrastructurePackageName:
|
|
17
|
+
| string
|
|
18
|
+
| { mode: 'append-package-name' | 'append-full-package-name' | 'replace'; value: string };
|
|
19
|
+
|
|
20
|
+
basePath?: string | RegExp | ((basePath: string, service: ApiService) => string);
|
|
21
|
+
pathModifier?: RegExp | ((path: string, endpoint: ApiEndpoint) => string);
|
|
22
|
+
serializerJsonInclude: 'always' | 'non-null' | 'non-absent' | 'non-default' | 'non-empty' | 'use-defaults';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const defaultKotlinOkHttp3ClientsGeneratorConfig: DefaultGenerationProviderConfig<
|
|
26
|
+
KotlinOkHttp3ClientsGeneratorConfig
|
|
27
|
+
> = {
|
|
28
|
+
...defaultKotlinGeneratorConfig,
|
|
29
|
+
|
|
30
|
+
packageName: 'com.openapi.generated',
|
|
31
|
+
packageSuffix: '.api.client',
|
|
32
|
+
infrastructurePackageName: { mode: 'append-full-package-name', value: '.infrastructure' },
|
|
33
|
+
serializerJsonInclude: 'non-absent',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type KotlinOkHttp3ClientsGeneratorInput = KotlinModelsGeneratorOutput;
|
|
37
|
+
|
|
38
|
+
export type KotlinOkHttp3ClientsGeneratorOutput = {
|
|
39
|
+
kotlin: {
|
|
40
|
+
clients: {
|
|
41
|
+
[serviceId: string]: KotlinOkHttp3ClientGeneratorOutput;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type KotlinOkHttp3ClientGeneratorOutput = KotlinImport;
|
|
47
|
+
|
|
48
|
+
export type KotlinOkHttp3ClientsGeneratorContext =
|
|
49
|
+
& OpenApiServicesGenerationProviderContext<
|
|
50
|
+
KotlinOkHttp3ClientsGeneratorInput,
|
|
51
|
+
KotlinOkHttp3ClientsGeneratorOutput,
|
|
52
|
+
KotlinOkHttp3ClientsGeneratorConfig,
|
|
53
|
+
KotlinOkHttp3ClientGeneratorOutput
|
|
54
|
+
>
|
|
55
|
+
& {
|
|
56
|
+
infrastructurePackageName: string;
|
|
57
|
+
refs: ReturnType<typeof getReferenceFactories>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type KotlinOkHttp3ClientGeneratorContext = KotlinOkHttp3ClientsGeneratorContext & {
|
|
61
|
+
service: ApiService;
|
|
62
|
+
};
|