@goast/kotlin 0.5.4 → 0.5.6
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/esm/src/config.d.ts +5 -0
- package/esm/src/config.d.ts.map +1 -1
- package/esm/src/config.js +1 -0
- package/esm/src/generators/models/args.d.ts +3 -0
- package/esm/src/generators/models/args.d.ts.map +1 -1
- package/esm/src/generators/models/model-generator.d.ts +2 -1
- package/esm/src/generators/models/model-generator.d.ts.map +1 -1
- package/esm/src/generators/models/model-generator.js +15 -9
- package/esm/src/generators/services/okhttp3-clients/args.d.ts +3 -0
- package/esm/src/generators/services/okhttp3-clients/args.d.ts.map +1 -1
- package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +2 -1
- package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts.map +1 -1
- package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +12 -4
- package/esm/src/generators/services/spring-controllers/args.d.ts +3 -0
- package/esm/src/generators/services/spring-controllers/args.d.ts.map +1 -1
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts +2 -1
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
- package/esm/src/generators/services/spring-controllers/spring-controller-generator.js +11 -1
- package/esm/src/generators/services/spring-reactive-web-clients/args.d.ts +3 -0
- package/esm/src/generators/services/spring-reactive-web-clients/args.d.ts.map +1 -1
- package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts +2 -1
- package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts.map +1 -1
- package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +13 -5
- package/esm/src/utils.d.ts +2 -1
- package/esm/src/utils.d.ts.map +1 -1
- package/esm/src/utils.js +7 -0
- package/package.json +2 -2
- package/script/src/config.d.ts +5 -0
- package/script/src/config.d.ts.map +1 -1
- package/script/src/config.js +1 -0
- package/script/src/generators/models/args.d.ts +3 -0
- package/script/src/generators/models/args.d.ts.map +1 -1
- package/script/src/generators/models/model-generator.d.ts +2 -1
- package/script/src/generators/models/model-generator.d.ts.map +1 -1
- package/script/src/generators/models/model-generator.js +15 -9
- package/script/src/generators/services/okhttp3-clients/args.d.ts +3 -0
- package/script/src/generators/services/okhttp3-clients/args.d.ts.map +1 -1
- package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +2 -1
- package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts.map +1 -1
- package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +10 -2
- package/script/src/generators/services/spring-controllers/args.d.ts +3 -0
- package/script/src/generators/services/spring-controllers/args.d.ts.map +1 -1
- package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts +2 -1
- package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
- package/script/src/generators/services/spring-controllers/spring-controller-generator.js +10 -0
- package/script/src/generators/services/spring-reactive-web-clients/args.d.ts +3 -0
- package/script/src/generators/services/spring-reactive-web-clients/args.d.ts.map +1 -1
- package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts +2 -1
- package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts.map +1 -1
- package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +11 -3
- package/script/src/utils.d.ts +2 -1
- package/script/src/utils.d.ts.map +1 -1
- package/script/src/utils.js +9 -0
- package/src/src/config.ts +7 -0
- package/src/src/generators/models/args.ts +4 -0
- package/src/src/generators/models/model-generator.ts +16 -4
- package/src/src/generators/services/okhttp3-clients/args.ts +2 -0
- package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +15 -3
- package/src/src/generators/services/spring-controllers/args.ts +2 -0
- package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +14 -1
- package/src/src/generators/services/spring-reactive-web-clients/args.ts +2 -0
- package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.ts +16 -4
- package/src/src/utils.ts +9 -1
|
@@ -3,10 +3,12 @@ import {
|
|
|
3
3
|
type ApiSchema,
|
|
4
4
|
type AppendValueGroup,
|
|
5
5
|
appendValueGroup,
|
|
6
|
+
type BasicAppendValue,
|
|
6
7
|
builderTemplate as s,
|
|
7
8
|
createOverwriteProxy,
|
|
8
9
|
getSourceDisplayName,
|
|
9
10
|
type MaybePromise,
|
|
11
|
+
notNullish,
|
|
10
12
|
resolveAnyOfAndAllOf,
|
|
11
13
|
SourceBuilder,
|
|
12
14
|
toCasing,
|
|
@@ -16,7 +18,7 @@ import { kt } from '../../../ast/index.js';
|
|
|
16
18
|
import type { KtValue } from '../../../ast/nodes/types.js';
|
|
17
19
|
import { KotlinFileBuilder } from '../../../file-builder.js';
|
|
18
20
|
import type { ApiParameterWithMultipartInfo } from '../../../types.js';
|
|
19
|
-
import { modifyString } from '../../../utils.js';
|
|
21
|
+
import { getSourceDocLine, modifyString } from '../../../utils.js';
|
|
20
22
|
import { KotlinFileGenerator } from '../../file-generator.js';
|
|
21
23
|
import type { DefaultKotlinOkHttp3GeneratorArgs as Args } from './index.js';
|
|
22
24
|
import type { KotlinOkHttp3ClientGeneratorContext, KotlinOkHttp3ClientGeneratorOutput } from './models.js';
|
|
@@ -126,7 +128,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<Context,
|
|
|
126
128
|
const { endpoint, parameters, responseSchema } = args;
|
|
127
129
|
|
|
128
130
|
return kt.function(toCasing(endpoint.name, ctx.config.functionNameCasing), {
|
|
129
|
-
doc: kt.doc(
|
|
131
|
+
doc: kt.doc(this.getEndpointDocDescription(ctx, { endpoint }), [
|
|
130
132
|
kt.docTag('throws', 'IllegalStateException', 'If the request is not correctly configured'),
|
|
131
133
|
kt.docTag('throws', 'IOException', 'Rethrows the OkHttp execute method exception'),
|
|
132
134
|
kt.docTag(
|
|
@@ -219,7 +221,7 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<Context,
|
|
|
219
221
|
const { endpoint, parameters, responseSchema } = args;
|
|
220
222
|
|
|
221
223
|
return kt.function(toCasing(args.endpoint.name, ctx.config.functionNameCasing) + 'WithHttpInfo', {
|
|
222
|
-
doc: kt.doc(
|
|
224
|
+
doc: kt.doc(this.getEndpointDocDescription(ctx, { endpoint }), [
|
|
223
225
|
kt.docTag('throws', 'IllegalStateException', 'If the request is not correctly configured'),
|
|
224
226
|
kt.docTag('throws', 'IOException', 'Rethrows the OkHttp execute method exception'),
|
|
225
227
|
]),
|
|
@@ -556,6 +558,16 @@ export class DefaultKotlinOkHttp3Generator extends KotlinFileGenerator<Context,
|
|
|
556
558
|
);
|
|
557
559
|
}
|
|
558
560
|
|
|
561
|
+
protected getEndpointDocDescription(ctx: Context, args: Args.GetEndpointDocDescription): BasicAppendValue<Builder> {
|
|
562
|
+
const docSegments = [args.endpoint.description?.trim()];
|
|
563
|
+
|
|
564
|
+
if (ctx.config.includeSourceInDocs) {
|
|
565
|
+
docSegments.push(getSourceDocLine(args.endpoint));
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
return docSegments.filter(notNullish).join('\n\n');
|
|
569
|
+
}
|
|
570
|
+
|
|
559
571
|
protected getBasePath(ctx: Context, _args: Args.GetBasePath): string {
|
|
560
572
|
return modifyString(
|
|
561
573
|
(ctx.service.$src ?? ctx.service.endpoints[0]?.$src)?.document.servers?.[0]?.url ?? '/',
|
|
@@ -68,6 +68,8 @@ export type GetTypeUsage<TBuilder extends SourceBuilder> = {
|
|
|
68
68
|
type?: kt.Reference<TBuilder>;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
+
export type GetEndpointDocDescription = { endpoint: ApiEndpoint };
|
|
72
|
+
|
|
71
73
|
export type GetSchemaType = { schema: ApiSchema | undefined };
|
|
72
74
|
|
|
73
75
|
export type GetControllerRequestMapping = { prefix?: string };
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type ApiParameter,
|
|
4
4
|
type AppendValueGroup,
|
|
5
5
|
appendValueGroup,
|
|
6
|
+
type BasicAppendValue,
|
|
6
7
|
builderTemplate as s,
|
|
7
8
|
createOverwriteProxy,
|
|
8
9
|
getSourceDisplayName,
|
|
@@ -18,7 +19,7 @@ import { kt } from '../../../ast/index.js';
|
|
|
18
19
|
import type { KotlinImport } from '../../../common-results.js';
|
|
19
20
|
import { KotlinFileBuilder } from '../../../file-builder.js';
|
|
20
21
|
import type { ApiParameterWithMultipartInfo } from '../../../types.js';
|
|
21
|
-
import { modifyString } from '../../../utils.js';
|
|
22
|
+
import { getSourceDocLine, modifyString } from '../../../utils.js';
|
|
22
23
|
import { KotlinFileGenerator } from '../../file-generator.js';
|
|
23
24
|
import type { DefaultKotlinSpringControllerGeneratorArgs as Args } from './index.js';
|
|
24
25
|
import type { KotlinServiceGeneratorContext, KotlinServiceGeneratorOutput } from './models.js';
|
|
@@ -163,6 +164,7 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator<
|
|
|
163
164
|
const parameters = this.getAllParameters(ctx, { endpoint });
|
|
164
165
|
|
|
165
166
|
return kt.function(toCasing(endpoint.name, ctx.config.functionNameCasing), {
|
|
167
|
+
doc: kt.doc(this.getEndpointDocDescription(ctx, { endpoint })),
|
|
166
168
|
suspend: ctx.config.suspendingFunctions,
|
|
167
169
|
annotations: this.getApiInterfaceEndpointMethodAnnnotations(
|
|
168
170
|
ctx,
|
|
@@ -789,6 +791,7 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator<
|
|
|
789
791
|
const fn = kt.function<Builder>(
|
|
790
792
|
toCasing(endpoint.name, ctx.config.functionNameCasing),
|
|
791
793
|
{
|
|
794
|
+
doc: kt.doc(this.getEndpointDocDescription(ctx, { endpoint })),
|
|
792
795
|
suspend: ctx.config.suspendingFunctions,
|
|
793
796
|
parameters: parameters.map((parameter) => {
|
|
794
797
|
return kt.parameter(
|
|
@@ -906,6 +909,16 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator<
|
|
|
906
909
|
return schema && ctx.input.kotlin.models[schema.id].type;
|
|
907
910
|
}
|
|
908
911
|
|
|
912
|
+
protected getEndpointDocDescription(ctx: Context, args: Args.GetEndpointDocDescription): BasicAppendValue<Builder> {
|
|
913
|
+
const docSegments = [args.endpoint.description?.trim()];
|
|
914
|
+
|
|
915
|
+
if (ctx.config.includeSourceInDocs) {
|
|
916
|
+
docSegments.push(getSourceDocLine(args.endpoint));
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
return docSegments.filter(notNullish).join('\n\n');
|
|
920
|
+
}
|
|
921
|
+
|
|
909
922
|
protected getControllerRequestMapping(
|
|
910
923
|
ctx: Context,
|
|
911
924
|
args: Args.GetControllerRequestMapping,
|
|
@@ -92,6 +92,8 @@ export type GetAllParameters = { endpoint: ApiEndpoint };
|
|
|
92
92
|
|
|
93
93
|
export type GetRequestBodyParamName = { endpoint: ApiEndpoint };
|
|
94
94
|
|
|
95
|
+
export type GetEndpointDocDescription = { endpoint: ApiEndpoint };
|
|
96
|
+
|
|
95
97
|
export type GetBasePath = object;
|
|
96
98
|
|
|
97
99
|
export type GetEndpointPath = { endpoint: ApiEndpoint };
|
|
@@ -3,10 +3,12 @@ import {
|
|
|
3
3
|
type ApiSchema,
|
|
4
4
|
type AppendValueGroup,
|
|
5
5
|
appendValueGroup,
|
|
6
|
+
type BasicAppendValue,
|
|
6
7
|
builderTemplate as s,
|
|
7
8
|
createOverwriteProxy,
|
|
8
9
|
getSourceDisplayName,
|
|
9
10
|
type MaybePromise,
|
|
11
|
+
notNullish,
|
|
10
12
|
resolveAnyOfAndAllOf,
|
|
11
13
|
SourceBuilder,
|
|
12
14
|
toCasing,
|
|
@@ -16,7 +18,7 @@ import { kt } from '../../../ast/index.js';
|
|
|
16
18
|
import type { KtValue } from '../../../ast/nodes/types.js';
|
|
17
19
|
import { KotlinFileBuilder } from '../../../file-builder.js';
|
|
18
20
|
import type { ApiParameterWithMultipartInfo } from '../../../types.js';
|
|
19
|
-
import { modifyString } from '../../../utils.js';
|
|
21
|
+
import { getSourceDocLine, modifyString } from '../../../utils.js';
|
|
20
22
|
import { KotlinFileGenerator } from '../../file-generator.js';
|
|
21
23
|
import type { DefaultKotlinSpringReactiveWebClientGeneratorArgs as Args } from './index.js';
|
|
22
24
|
import type {
|
|
@@ -90,7 +92,7 @@ export class DefaultKotlinSpringReactiveWebClientGenerator extends KotlinFileGen
|
|
|
90
92
|
const functionName = this.getEndpointFunctionName(ctx, { endpoint });
|
|
91
93
|
|
|
92
94
|
return kt.function(functionName, {
|
|
93
|
-
doc: kt.doc(endpoint
|
|
95
|
+
doc: kt.doc(this.getEndpointDocDescription(ctx, { endpoint })),
|
|
94
96
|
suspend: true,
|
|
95
97
|
receiverType: kt.refs.springReactive.webClient(),
|
|
96
98
|
parameters: parameters.map((parameter) =>
|
|
@@ -142,7 +144,7 @@ export class DefaultKotlinSpringReactiveWebClientGenerator extends KotlinFileGen
|
|
|
142
144
|
const functionName = this.getEndpointFunctionName(ctx, { endpoint });
|
|
143
145
|
|
|
144
146
|
return kt.function(functionName, {
|
|
145
|
-
doc: kt.doc(endpoint
|
|
147
|
+
doc: kt.doc(this.getEndpointDocDescription(ctx, { endpoint })),
|
|
146
148
|
suspend: true,
|
|
147
149
|
generics: [kt.genericParameter('T')],
|
|
148
150
|
receiverType: kt.refs.springReactive.webClient(),
|
|
@@ -201,7 +203,7 @@ export class DefaultKotlinSpringReactiveWebClientGenerator extends KotlinFileGen
|
|
|
201
203
|
const functionName = this.getEndpointRequestFunctionName(ctx, { endpoint });
|
|
202
204
|
|
|
203
205
|
return kt.function(functionName, {
|
|
204
|
-
doc: kt.doc(endpoint
|
|
206
|
+
doc: kt.doc(this.getEndpointDocDescription(ctx, { endpoint })),
|
|
205
207
|
receiverType: kt.refs.springReactive.webClient(),
|
|
206
208
|
parameters: parameters.map((parameter) =>
|
|
207
209
|
kt.parameter(
|
|
@@ -529,6 +531,16 @@ export class DefaultKotlinSpringReactiveWebClientGenerator extends KotlinFileGen
|
|
|
529
531
|
);
|
|
530
532
|
}
|
|
531
533
|
|
|
534
|
+
protected getEndpointDocDescription(ctx: Context, args: Args.GetEndpointDocDescription): BasicAppendValue<Builder> {
|
|
535
|
+
const docSegments = [args.endpoint.description?.trim()];
|
|
536
|
+
|
|
537
|
+
if (ctx.config.includeSourceInDocs) {
|
|
538
|
+
docSegments.push(getSourceDocLine(args.endpoint));
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
return docSegments.filter(notNullish).join('\n\n');
|
|
542
|
+
}
|
|
543
|
+
|
|
532
544
|
protected getBasePath(ctx: Context, _args: Args.GetBasePath): string {
|
|
533
545
|
return modifyString(
|
|
534
546
|
(ctx.service.$src ?? ctx.service.endpoints[0]?.$src)?.document.servers?.[0]?.url ?? '/',
|
package/src/src/utils.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { Nullable } from '@goast/core';
|
|
1
|
+
import type { ApiComponent, Nullable } from '@goast/core';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
2
4
|
|
|
3
5
|
export function toKotlinStringLiteral(value: Nullable<string>): string {
|
|
4
6
|
if (!value) {
|
|
@@ -37,3 +39,9 @@ export function modifyString<TArgs extends unknown[]>(
|
|
|
37
39
|
}
|
|
38
40
|
return value;
|
|
39
41
|
}
|
|
42
|
+
|
|
43
|
+
export function getSourceDocLine<T>(component: ApiComponent<T>): string {
|
|
44
|
+
const file = path.relative(process.cwd(), component.$src.file);
|
|
45
|
+
const { line, col } = component.$src.pos;
|
|
46
|
+
return `Source: ${file}:${line}:${col} (${component.$src.path})`;
|
|
47
|
+
}
|