@goast/kotlin 0.5.1-beta.1 → 0.5.1
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/assets/client/okhttp3/ApiAbstractions.kt +30 -30
- package/assets/client/okhttp3/ApiClient.kt +253 -253
- package/assets/client/okhttp3/ApiResponse.kt +43 -43
- package/assets/client/okhttp3/Errors.kt +21 -21
- package/assets/client/okhttp3/PartConfig.kt +11 -11
- package/assets/client/okhttp3/RequestConfig.kt +18 -18
- package/assets/client/okhttp3/RequestMethod.kt +8 -8
- package/assets/client/okhttp3/ResponseExtensions.kt +24 -24
- package/assets/client/spring-reactive-web-clients/ApiRequestFile.kt +33 -33
- package/esm/src/generators/models/model-generator.d.ts.map +1 -1
- package/esm/src/generators/models/model-generator.js +1 -0
- package/package.json +2 -2
- package/script/src/generators/models/model-generator.d.ts.map +1 -1
- package/script/src/generators/models/model-generator.js +1 -0
- 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 +44 -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 +112 -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 +703 -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 +73 -0
- package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +597 -0
- package/src/src/generators/services/okhttp3-clients/okhttp3-clients-generator.ts +169 -0
- package/src/src/generators/services/okhttp3-clients/refs.ts +59 -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 +76 -0
- package/src/src/generators/services/spring-controllers/refs.ts +17 -0
- package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +1084 -0
- package/src/src/generators/services/spring-controllers/spring-controllers-generator.ts +140 -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 +571 -0
- package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.ts +125 -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,31 @@
|
|
|
1
|
+
import type { BasicAppendValue, SourceBuilder } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { type KtCall, ktCall } from '../nodes/call.js';
|
|
4
|
+
import { type KtString, ktString } from '../nodes/string.js';
|
|
5
|
+
import { listOf, mapOf } from '../references/index.js';
|
|
6
|
+
|
|
7
|
+
export function toKtNode<TBuilder extends SourceBuilder>(object: Record<string | number, unknown>): KtCall<TBuilder>;
|
|
8
|
+
export function toKtNode<TBuilder extends SourceBuilder>(list: unknown[]): KtCall<TBuilder>;
|
|
9
|
+
export function toKtNode<TBuilder extends SourceBuilder>(string: string): KtString<TBuilder>;
|
|
10
|
+
export function toKtNode<TBuilder extends SourceBuilder>(value: unknown): BasicAppendValue<TBuilder>;
|
|
11
|
+
export function toKtNode<TBuilder extends SourceBuilder>(value: unknown): unknown {
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
return ktCall(
|
|
14
|
+
[listOf.infer()],
|
|
15
|
+
value.map((x) => toKtNode<TBuilder>(x)),
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === 'object' && value !== null) {
|
|
19
|
+
return ktCall(
|
|
20
|
+
[mapOf.infer()],
|
|
21
|
+
Object.entries(value).map(([k, v]) => ktCall([toKtNode(k), 'to'], [toKtNode(v)])),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
if (value === null || value === undefined) {
|
|
25
|
+
return 'null';
|
|
26
|
+
}
|
|
27
|
+
if (typeof value === 'boolean' || typeof value === 'number') {
|
|
28
|
+
return String(value);
|
|
29
|
+
}
|
|
30
|
+
return ktString(String(value));
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { notNullish, type Nullable, type SingleOrMultiple, type SourceBuilder, toArray } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { type KtAppendValue, writeKtNode } from './write-kt-node.js';
|
|
4
|
+
|
|
5
|
+
export function writeKtAnnotations<TBuilder extends SourceBuilder>(
|
|
6
|
+
builder: TBuilder,
|
|
7
|
+
nodes: SingleOrMultiple<Nullable<KtAppendValue<TBuilder>>>,
|
|
8
|
+
options?: { multiline: boolean },
|
|
9
|
+
) {
|
|
10
|
+
const filteredNodes = toArray(nodes).filter(notNullish);
|
|
11
|
+
builder.forEach(filteredNodes, (b, a) => {
|
|
12
|
+
writeKtNode(b, a);
|
|
13
|
+
b.append(options?.multiline ? '\n' : ' ');
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { notNullish, type Nullable, type SingleOrMultiple, type SourceBuilder, toArray } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { KtLambda } from '../nodes/lambda.js';
|
|
4
|
+
import { type KtAppendValue, writeKtNode, writeKtNodes } from './write-kt-node.js';
|
|
5
|
+
|
|
6
|
+
export function writeKtArguments<TBuilder extends SourceBuilder>(
|
|
7
|
+
builder: TBuilder,
|
|
8
|
+
nodes: SingleOrMultiple<Nullable<KtAppendValue<TBuilder>>>,
|
|
9
|
+
) {
|
|
10
|
+
const filteredNodes = toArray(nodes).filter(notNullish);
|
|
11
|
+
|
|
12
|
+
if (filteredNodes.length === 0) {
|
|
13
|
+
builder.append('()');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const lastNode = filteredNodes[filteredNodes.length - 1];
|
|
18
|
+
let lambda: KtAppendValue<TBuilder> | null = null;
|
|
19
|
+
if (lastNode instanceof KtLambda) {
|
|
20
|
+
lambda = lastNode;
|
|
21
|
+
filteredNodes.pop();
|
|
22
|
+
} else if (
|
|
23
|
+
typeof lastNode === 'object' &&
|
|
24
|
+
(!('name' in lastNode) || !lastNode.name) &&
|
|
25
|
+
'value' in lastNode &&
|
|
26
|
+
lastNode.value instanceof KtLambda
|
|
27
|
+
) {
|
|
28
|
+
lambda = lastNode.value;
|
|
29
|
+
filteredNodes.pop();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const multiline = filteredNodes.length > 3;
|
|
33
|
+
|
|
34
|
+
builder.parenthesizeIf(
|
|
35
|
+
filteredNodes.length > 0,
|
|
36
|
+
'()',
|
|
37
|
+
(b) => writeKtNodes(b, filteredNodes, { separator: multiline ? ',\n' : ', ' }),
|
|
38
|
+
{ multiline },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (lambda) {
|
|
42
|
+
builder.append(' ');
|
|
43
|
+
writeKtNode(builder, lambda);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { notNullish, type Nullable, type SingleOrMultiple, type SourceBuilder, toArray } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { type KtAppendValue, writeKtNode } from './write-kt-node.js';
|
|
4
|
+
|
|
5
|
+
export function writeKtEnumValues<TBuilder extends SourceBuilder>(
|
|
6
|
+
builder: TBuilder,
|
|
7
|
+
nodes: SingleOrMultiple<Nullable<KtAppendValue<TBuilder>>>,
|
|
8
|
+
) {
|
|
9
|
+
const filteredNodes = toArray(nodes).filter(notNullish);
|
|
10
|
+
const spacing = filteredNodes.some(
|
|
11
|
+
(v) =>
|
|
12
|
+
typeof v === 'object' &&
|
|
13
|
+
(('annotations' in v && Array.isArray(v.annotations) && v.annotations.length > 0) ||
|
|
14
|
+
('doc' in v && v.doc) ||
|
|
15
|
+
('members' in v && Array.isArray(v.members) && v.members.some(notNullish))),
|
|
16
|
+
);
|
|
17
|
+
const multiline = spacing ||
|
|
18
|
+
filteredNodes.length > 4 ||
|
|
19
|
+
filteredNodes.some(
|
|
20
|
+
(v) => typeof v === 'object' && 'arguments' in v && Array.isArray(v.arguments) && v.arguments.length > 0,
|
|
21
|
+
);
|
|
22
|
+
builder.forEach(
|
|
23
|
+
filteredNodes,
|
|
24
|
+
(b, v, i) => b.if(spacing && i > 0, (b) => b.ensurePreviousLineEmpty()).append((b) => writeKtNode(b, v)),
|
|
25
|
+
{ separator: multiline ? ',\n' : ', ' },
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { notNullish, type Nullable, type SingleOrMultiple, type SourceBuilder, toArray } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { type KtAppendValue, writeKtNode } from './write-kt-node.js';
|
|
4
|
+
|
|
5
|
+
export function writeKtGenericParameters<TBuilder extends SourceBuilder>(
|
|
6
|
+
builder: TBuilder,
|
|
7
|
+
nodes: SingleOrMultiple<Nullable<KtAppendValue<TBuilder>>>,
|
|
8
|
+
) {
|
|
9
|
+
const filteredNodes = toArray(nodes).filter(notNullish);
|
|
10
|
+
if (filteredNodes.length === 0) return;
|
|
11
|
+
builder.parenthesize('<>', (b) => b.forEach(filteredNodes, writeKtNode, { separator: ', ' }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isAppendValue, isAppendValueGroup, notNullish, type Nullable, type SourceBuilder } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { KtProperty } from '../nodes/property.js';
|
|
4
|
+
import { type KtAppendValue, writeKtNode } from './write-kt-node.js';
|
|
5
|
+
|
|
6
|
+
export function writeKtMembers<TBuilder extends SourceBuilder>(
|
|
7
|
+
builder: TBuilder,
|
|
8
|
+
members: Nullable<KtAppendValue<TBuilder>>[],
|
|
9
|
+
options?: { alreadyHasMembers?: boolean },
|
|
10
|
+
): void {
|
|
11
|
+
const filteredMembers = members.filter(notNullish);
|
|
12
|
+
builder.forEach(filteredMembers, (b, m, i) =>
|
|
13
|
+
b.if(
|
|
14
|
+
() =>
|
|
15
|
+
!(m instanceof KtProperty && !m.doc && m.annotations.length === 0) &&
|
|
16
|
+
!isAppendValue(m) &&
|
|
17
|
+
!isAppendValueGroup(m),
|
|
18
|
+
(b) =>
|
|
19
|
+
b
|
|
20
|
+
.if(i > 0 || !!options?.alreadyHasMembers, (b) => b.ensurePreviousLineEmpty())
|
|
21
|
+
.append((b) => writeKtNode(b, m))
|
|
22
|
+
.if(i < filteredMembers.length - 1, (b) => b.ensurePreviousLineEmpty()),
|
|
23
|
+
(b) => b.append((b) => writeKtNode(b, m)).ensureCurrentLineEmpty(),
|
|
24
|
+
));
|
|
25
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AppendValue,
|
|
3
|
+
notNullish,
|
|
4
|
+
type Nullable,
|
|
5
|
+
type Separator,
|
|
6
|
+
type SingleOrMultiple,
|
|
7
|
+
type SourceBuilder,
|
|
8
|
+
toArray,
|
|
9
|
+
} from '@goast/core';
|
|
10
|
+
|
|
11
|
+
import { KtNode } from '../node.js';
|
|
12
|
+
|
|
13
|
+
export type KtAppendValue<TBuilder extends SourceBuilder> = AppendValue<TBuilder> | KtNode<TBuilder>;
|
|
14
|
+
|
|
15
|
+
export function writeKtNode<TBuilder extends SourceBuilder>(
|
|
16
|
+
builder: TBuilder,
|
|
17
|
+
node: Nullable<KtAppendValue<TBuilder>>,
|
|
18
|
+
): void {
|
|
19
|
+
if (node instanceof KtNode) {
|
|
20
|
+
node.write(builder);
|
|
21
|
+
} else {
|
|
22
|
+
builder.append(node);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function writeKtNodes<TBuilder extends SourceBuilder>(
|
|
27
|
+
builder: TBuilder,
|
|
28
|
+
nodes: SingleOrMultiple<Nullable<KtAppendValue<TBuilder>>>,
|
|
29
|
+
options?: { separator?: Separator<TBuilder, KtAppendValue<TBuilder>> },
|
|
30
|
+
): void {
|
|
31
|
+
const filteredNodes = toArray(nodes).filter(notNullish);
|
|
32
|
+
if (filteredNodes.length === 1) {
|
|
33
|
+
writeKtNode(builder, filteredNodes[0]);
|
|
34
|
+
} else if (filteredNodes.length > 1) {
|
|
35
|
+
builder.forEach(filteredNodes, writeKtNode, { separator: options?.separator });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { notNullish, type Nullable, type SingleOrMultiple, type SourceBuilder, toArray } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { type KtAppendValue, writeKtNode } from './write-kt-node.js';
|
|
4
|
+
|
|
5
|
+
export function writeKtParameters<TBuilder extends SourceBuilder>(
|
|
6
|
+
builder: TBuilder,
|
|
7
|
+
nodes: SingleOrMultiple<Nullable<KtAppendValue<TBuilder>>>,
|
|
8
|
+
) {
|
|
9
|
+
const filteredNodes = toArray(nodes).filter(notNullish);
|
|
10
|
+
const hasAnnotations = filteredNodes.some(
|
|
11
|
+
(p) => typeof p === 'object' && 'annotations' in p && Array.isArray(p.annotations) && p.annotations.length > 0,
|
|
12
|
+
);
|
|
13
|
+
const multiline = filteredNodes.length > 2 || hasAnnotations;
|
|
14
|
+
const spacing = multiline && hasAnnotations;
|
|
15
|
+
builder.parenthesize(
|
|
16
|
+
'()',
|
|
17
|
+
(b) =>
|
|
18
|
+
b.forEach(
|
|
19
|
+
filteredNodes,
|
|
20
|
+
(b, p, i) => b.if(i > 0 && spacing, (b) => b.ensurePreviousLineEmpty()).append((b) => writeKtNode(b, p)),
|
|
21
|
+
{ separator: multiline ? ',\n' : ', ' },
|
|
22
|
+
),
|
|
23
|
+
{ multiline },
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DefaultGenerationProviderConfig,
|
|
3
|
+
OpenApiGeneratorConfig,
|
|
4
|
+
StringCasing,
|
|
5
|
+
StringCasingWithOptions,
|
|
6
|
+
} from '@goast/core';
|
|
7
|
+
|
|
8
|
+
export type KotlinGeneratorConfig = OpenApiGeneratorConfig & {
|
|
9
|
+
typeNameCasing: StringCasing | StringCasingWithOptions;
|
|
10
|
+
parameterNameCasing: StringCasing | StringCasingWithOptions;
|
|
11
|
+
functionNameCasing: StringCasing | StringCasingWithOptions;
|
|
12
|
+
propertyNameCasing: StringCasing | StringCasingWithOptions;
|
|
13
|
+
enumValueNameCasing: StringCasing | StringCasingWithOptions;
|
|
14
|
+
constantNameCasing: StringCasing | StringCasingWithOptions;
|
|
15
|
+
|
|
16
|
+
globalImports: string[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const defaultKotlinGeneratorConfig: DefaultGenerationProviderConfig<KotlinGeneratorConfig> = {
|
|
20
|
+
indent: { type: 'spaces', count: 4 },
|
|
21
|
+
|
|
22
|
+
typeNameCasing: 'pascal',
|
|
23
|
+
parameterNameCasing: 'camel',
|
|
24
|
+
functionNameCasing: 'camel',
|
|
25
|
+
propertyNameCasing: 'camel',
|
|
26
|
+
enumValueNameCasing: 'snake',
|
|
27
|
+
constantNameCasing: 'snake',
|
|
28
|
+
|
|
29
|
+
globalImports: [
|
|
30
|
+
'kotlin.*',
|
|
31
|
+
'kotlin.annotation.*',
|
|
32
|
+
'kotlin.collections.*',
|
|
33
|
+
'kotlin.comparisons.*',
|
|
34
|
+
'kotlin.io.*',
|
|
35
|
+
'kotlin.ranges.*',
|
|
36
|
+
'kotlin.sequences.*',
|
|
37
|
+
'kotlin.text.*',
|
|
38
|
+
'java.lang.*',
|
|
39
|
+
'kotlin.jvm.*',
|
|
40
|
+
],
|
|
41
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type AppendParam, type AppendValue, isAppendValue, SourceBuilder, writeGeneratedFile } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
import { KtNode } from './ast/node.js';
|
|
4
|
+
import { defaultKotlinGeneratorConfig, type KotlinGeneratorConfig } from './config.js';
|
|
5
|
+
import { ImportCollection } from './import-collection.js';
|
|
6
|
+
|
|
7
|
+
type AnnotationArgumentValue<T extends SourceBuilder> = string | ((builder: T) => void);
|
|
8
|
+
type AnnotationArgument<T extends SourceBuilder> =
|
|
9
|
+
| AnnotationArgumentValue<T>
|
|
10
|
+
| [key: string, value: AnnotationArgumentValue<T>]
|
|
11
|
+
| [value: AnnotationArgumentValue<T>, condition: boolean]
|
|
12
|
+
| [key: string, value: AnnotationArgumentValue<T>, condition: boolean];
|
|
13
|
+
|
|
14
|
+
export type KotlinAppends<TAdditionalAppends> = KtNode<KotlinFileBuilder> | TAdditionalAppends;
|
|
15
|
+
export type KotlinAppendParam<TBuilder extends KotlinFileBuilder, TAdditionalAppends> = AppendParam<
|
|
16
|
+
TBuilder,
|
|
17
|
+
KotlinAppends<TAdditionalAppends>
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export function isKotlinAppendValue<TBuilder extends KotlinFileBuilder>(
|
|
21
|
+
value: unknown,
|
|
22
|
+
): value is AppendValue<TBuilder> {
|
|
23
|
+
return isAppendValue(value) || value instanceof KtNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class KotlinFileBuilder<TAdditionalAppends = never> extends SourceBuilder<KotlinAppends<TAdditionalAppends>> {
|
|
27
|
+
public readonly packageName: string | undefined;
|
|
28
|
+
public readonly imports: ImportCollection = new ImportCollection();
|
|
29
|
+
|
|
30
|
+
public override get options(): KotlinGeneratorConfig {
|
|
31
|
+
return super.options as KotlinGeneratorConfig;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
constructor(packageName?: string, options?: KotlinGeneratorConfig) {
|
|
35
|
+
super(options ?? defaultKotlinGeneratorConfig);
|
|
36
|
+
this.packageName = packageName;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public addImport(name: string, packageName?: string): this {
|
|
40
|
+
if (packageName !== undefined && packageName !== this.packageName) {
|
|
41
|
+
this.imports.addImport(name, packageName);
|
|
42
|
+
}
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public appendAnnotation(name: string, packageName?: string, args?: AnnotationArgument<this>[]): this {
|
|
47
|
+
const allArgs: [key: string | undefined, value: AnnotationArgumentValue<this>][] = [];
|
|
48
|
+
if (args) {
|
|
49
|
+
for (const a of args) {
|
|
50
|
+
if (!Array.isArray(a)) {
|
|
51
|
+
allArgs.push([undefined, a]);
|
|
52
|
+
} else if (a.length === 2 && a[1] === true) {
|
|
53
|
+
allArgs.push([undefined, a[0]]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const a of args) {
|
|
57
|
+
if (Array.isArray(a) && typeof a[1] !== 'boolean' && a[2] !== false) {
|
|
58
|
+
allArgs.push(a.length === 2 ? a : [a[0], a[1]]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.append(`@${name}`).addImport(name, packageName);
|
|
64
|
+
|
|
65
|
+
if (allArgs.length > 0) {
|
|
66
|
+
const multiline = allArgs.some((x) => typeof x[1] !== 'string') ||
|
|
67
|
+
allArgs.reduce((c, [key, value]) => c + (key ? key.length + 3 : 0) + (value?.length ?? 0), 0) > 80;
|
|
68
|
+
this.parenthesize('()', (builder) =>
|
|
69
|
+
builder
|
|
70
|
+
.appendLineIf(multiline)
|
|
71
|
+
.forEach(
|
|
72
|
+
allArgs,
|
|
73
|
+
(builder, [name, value]) =>
|
|
74
|
+
builder
|
|
75
|
+
.append(name ? `${name} = ` : '')
|
|
76
|
+
.append((builder) => (typeof value === 'string' ? builder.append(value) : value(builder))),
|
|
77
|
+
{ separator: multiline ? ',\n' : ', ' },
|
|
78
|
+
)
|
|
79
|
+
.appendLineIf(multiline));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.appendLine();
|
|
83
|
+
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public override clear(): void {
|
|
88
|
+
super.clear();
|
|
89
|
+
this.imports.clear();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public override toString(addPadding: boolean = true): string {
|
|
93
|
+
return new SourceBuilder(this.options)
|
|
94
|
+
.if(this.packageName !== undefined, (builder) => builder.appendLine(`package ${this.packageName}`).appendLine())
|
|
95
|
+
.append((builder) => this.imports.writeTo(builder))
|
|
96
|
+
.if(addPadding, (builder) => builder.ensurePreviousLineEmpty())
|
|
97
|
+
.append(super.toString())
|
|
98
|
+
.if(addPadding, (builder) => builder.ensureCurrentLineEmpty())
|
|
99
|
+
.toString();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public writeToFile(filePath: string) {
|
|
103
|
+
writeGeneratedFile(this.options, filePath, this.toString());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
protected override appendSingle(value: KotlinAppendParam<this, TAdditionalAppends>): void {
|
|
107
|
+
super.appendSingle(value);
|
|
108
|
+
if (value instanceof KtNode) {
|
|
109
|
+
value.write(this);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type MaybePromise,
|
|
3
|
+
type Nullable,
|
|
4
|
+
type OpenApiGenerationProviderContext,
|
|
5
|
+
type OpenApiGeneratorInput,
|
|
6
|
+
toCasing,
|
|
7
|
+
} from '@goast/core';
|
|
8
|
+
|
|
9
|
+
import type { KotlinGeneratorConfig } from '../config.js';
|
|
10
|
+
import { toKotlinPropertyName, toKotlinStringLiteral } from '../utils.js';
|
|
11
|
+
|
|
12
|
+
export abstract class KotlinFileGenerator<
|
|
13
|
+
TContext extends OpenApiGenerationProviderContext<OpenApiGeneratorInput, KotlinGeneratorConfig>,
|
|
14
|
+
TOutput,
|
|
15
|
+
> {
|
|
16
|
+
public abstract generate(context: TContext): MaybePromise<TOutput>;
|
|
17
|
+
|
|
18
|
+
protected toPropertyName(context: TContext, name: string): string {
|
|
19
|
+
return toKotlinPropertyName(toCasing(name, context.config.propertyNameCasing));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected toEnumValueName(context: TContext, name: string): string {
|
|
23
|
+
return toKotlinPropertyName(toCasing(name, context.config.enumValueNameCasing));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected toStringLiteral(_context: TContext, text: Nullable<string>): string {
|
|
27
|
+
return toKotlinStringLiteral(text);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { ApiSchema, ApiSchemaProperty } from '@goast/core';
|
|
2
|
+
|
|
3
|
+
export type GetFileContent = object;
|
|
4
|
+
|
|
5
|
+
export type GetSchemaDeclaration = {
|
|
6
|
+
schema: ApiSchema;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type GetClass = {
|
|
10
|
+
schema: ApiSchema<'object'>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type GetInterface = {
|
|
14
|
+
schema: ApiSchema<'object'>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type GetEnum = {
|
|
18
|
+
schema: ApiSchema;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type GetType = {
|
|
22
|
+
schema: ApiSchema;
|
|
23
|
+
nullable?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type GetGeneratedType = {
|
|
27
|
+
schema: ApiSchema;
|
|
28
|
+
nullable?: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type GetAdditionalPropertiesType = {
|
|
32
|
+
schema: ApiSchema<'object'>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type GetDefaultValue = {
|
|
36
|
+
schema: ApiSchema;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type GetClassParameter = {
|
|
40
|
+
schema: ApiSchema<'object'>;
|
|
41
|
+
inheritedSchemas: ApiSchema[];
|
|
42
|
+
parameters: ApiSchemaProperty[];
|
|
43
|
+
property: ApiSchemaProperty;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type GetInterfaceProperty = {
|
|
47
|
+
schema: ApiSchema<'object'>;
|
|
48
|
+
property: ApiSchemaProperty;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type GetAdditionalPropertiesProperty = {
|
|
52
|
+
schema: ApiSchema<'object'>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type GetAdditionalPropertiesSetter = {
|
|
56
|
+
schema: ApiSchema<'object'>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type GetAdditionalPropertiesGetter = {
|
|
60
|
+
schema: ApiSchema<'object'>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type GetJacksonJsonTypeInfoAnnotation = {
|
|
64
|
+
schema: ApiSchema;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type GetJacksonJsonSubTypesAnnotation = {
|
|
68
|
+
schema: ApiSchema;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type GetJacksonJsonClassDescriptionAnnotation = {
|
|
72
|
+
schema: ApiSchema;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type GetJacksonJsonPropertyAnnotation = {
|
|
76
|
+
schema: ApiSchema;
|
|
77
|
+
property: ApiSchemaProperty;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type GetJacksonJsonPropertyDescriptionAnnotation = {
|
|
81
|
+
schema: ApiSchema;
|
|
82
|
+
property: ApiSchemaProperty;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export type GetJacksonJsonIncludeAnnotation = {
|
|
86
|
+
schema: ApiSchema;
|
|
87
|
+
property: ApiSchemaProperty;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type GetJakartaValidationAnnotations = {
|
|
91
|
+
schema: ApiSchema;
|
|
92
|
+
property: ApiSchemaProperty;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export type GetSwaggerSchemaAnnotation = {
|
|
96
|
+
schema: ApiSchema;
|
|
97
|
+
property: ApiSchemaProperty;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export type GetPackageName = {
|
|
101
|
+
schema: ApiSchema;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type ShouldGenerateTypeDeclaration = {
|
|
105
|
+
schema: ApiSchema;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export type GetDeclarationTypeName = {
|
|
109
|
+
schema: ApiSchema;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export type GetInheritedSchemas = {
|
|
113
|
+
schema: ApiSchema;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type GetClassProperties = {
|
|
117
|
+
schema: ApiSchema<'object'>;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type SortProperties = {
|
|
121
|
+
schema: ApiSchema;
|
|
122
|
+
properties: Iterable<ApiSchemaProperty>;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type NormalizeSchema = {
|
|
126
|
+
schema: ApiSchema;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export type HasProperty = {
|
|
130
|
+
schema: ApiSchema;
|
|
131
|
+
propertyName: string;
|
|
132
|
+
};
|