@goast/kotlin 0.5.7 → 0.5.9-beta.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.
Files changed (118) hide show
  1. package/LICENSE +21 -21
  2. package/assets/client/okhttp3/ApiAbstractions.kt +30 -30
  3. package/assets/client/okhttp3/ApiClient.kt +253 -253
  4. package/assets/client/okhttp3/ApiResponse.kt +43 -43
  5. package/assets/client/okhttp3/Errors.kt +21 -21
  6. package/assets/client/okhttp3/PartConfig.kt +11 -11
  7. package/assets/client/okhttp3/RequestConfig.kt +18 -18
  8. package/assets/client/okhttp3/RequestMethod.kt +8 -8
  9. package/assets/client/okhttp3/ResponseExtensions.kt +24 -24
  10. package/assets/client/spring-reactive-web-clients/ApiRequestFile.kt +33 -33
  11. package/esm/src/ast/references/jackson.d.ts +8 -5
  12. package/esm/src/ast/references/jackson.d.ts.map +1 -1
  13. package/esm/src/ast/references/jackson.js +14 -6
  14. package/esm/src/config.d.ts +10 -0
  15. package/esm/src/config.d.ts.map +1 -1
  16. package/esm/src/config.js +1 -0
  17. package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts.map +1 -1
  18. package/esm/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +36 -32
  19. package/esm/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts.map +1 -1
  20. package/esm/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +22 -6
  21. package/esm/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
  22. package/esm/src/generators/services/spring-controllers/spring-controller-generator.js +23 -13
  23. package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts.map +1 -1
  24. package/esm/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +4 -1
  25. package/package.json +3 -3
  26. package/script/src/ast/references/jackson.d.ts +8 -5
  27. package/script/src/ast/references/jackson.d.ts.map +1 -1
  28. package/script/src/ast/references/jackson.js +20 -7
  29. package/script/src/config.d.ts +10 -0
  30. package/script/src/config.d.ts.map +1 -1
  31. package/script/src/config.js +1 -0
  32. package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts.map +1 -1
  33. package/script/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +36 -32
  34. package/script/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts.map +1 -1
  35. package/script/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +22 -6
  36. package/script/src/generators/services/spring-controllers/spring-controller-generator.d.ts.map +1 -1
  37. package/script/src/generators/services/spring-controllers/spring-controller-generator.js +23 -13
  38. package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts.map +1 -1
  39. package/script/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +4 -1
  40. package/src/mod.ts +0 -8
  41. package/src/src/assets.ts +0 -9
  42. package/src/src/ast/_index.ts +0 -66
  43. package/src/src/ast/common.ts +0 -1
  44. package/src/src/ast/index.ts +0 -1
  45. package/src/src/ast/node.ts +0 -10
  46. package/src/src/ast/nodes/annotation.ts +0 -79
  47. package/src/src/ast/nodes/argument.ts +0 -62
  48. package/src/src/ast/nodes/call.ts +0 -75
  49. package/src/src/ast/nodes/class.ts +0 -178
  50. package/src/src/ast/nodes/collection-literal.ts +0 -49
  51. package/src/src/ast/nodes/constructor.ts +0 -126
  52. package/src/src/ast/nodes/doc-tag.ts +0 -138
  53. package/src/src/ast/nodes/doc.ts +0 -111
  54. package/src/src/ast/nodes/enum-value.ts +0 -100
  55. package/src/src/ast/nodes/enum.ts +0 -163
  56. package/src/src/ast/nodes/function.ts +0 -178
  57. package/src/src/ast/nodes/generic-parameter.ts +0 -54
  58. package/src/src/ast/nodes/init-block.ts +0 -38
  59. package/src/src/ast/nodes/interface.ts +0 -133
  60. package/src/src/ast/nodes/lambda-type.ts +0 -73
  61. package/src/src/ast/nodes/lambda.ts +0 -74
  62. package/src/src/ast/nodes/object.ts +0 -102
  63. package/src/src/ast/nodes/parameter.ts +0 -118
  64. package/src/src/ast/nodes/property.ts +0 -225
  65. package/src/src/ast/nodes/reference.ts +0 -178
  66. package/src/src/ast/nodes/string.ts +0 -114
  67. package/src/src/ast/nodes/types.ts +0 -23
  68. package/src/src/ast/references/index.ts +0 -10
  69. package/src/src/ast/references/jackson.ts +0 -44
  70. package/src/src/ast/references/jakarta.ts +0 -14
  71. package/src/src/ast/references/java.ts +0 -27
  72. package/src/src/ast/references/kotlin.ts +0 -41
  73. package/src/src/ast/references/kotlinx.ts +0 -14
  74. package/src/src/ast/references/okhttp3.ts +0 -5
  75. package/src/src/ast/references/reactor.ts +0 -5
  76. package/src/src/ast/references/spring-reactive.ts +0 -33
  77. package/src/src/ast/references/spring.ts +0 -86
  78. package/src/src/ast/references/swagger.ts +0 -23
  79. package/src/src/ast/utils/get-kotlin-builder-options.ts +0 -19
  80. package/src/src/ast/utils/to-kt-node.ts +0 -31
  81. package/src/src/ast/utils/write-kt-annotations.ts +0 -15
  82. package/src/src/ast/utils/write-kt-arguments.ts +0 -45
  83. package/src/src/ast/utils/write-kt-enum-values.ts +0 -27
  84. package/src/src/ast/utils/write-kt-generic-parameters.ts +0 -12
  85. package/src/src/ast/utils/write-kt-members.ts +0 -25
  86. package/src/src/ast/utils/write-kt-node.ts +0 -37
  87. package/src/src/ast/utils/write-kt-parameters.ts +0 -25
  88. package/src/src/common-results.ts +0 -4
  89. package/src/src/config.ts +0 -48
  90. package/src/src/file-builder.ts +0 -112
  91. package/src/src/generators/file-generator.ts +0 -29
  92. package/src/src/generators/index.ts +0 -5
  93. package/src/src/generators/models/args.ts +0 -136
  94. package/src/src/generators/models/index.ts +0 -4
  95. package/src/src/generators/models/model-generator.ts +0 -725
  96. package/src/src/generators/models/models-generator.ts +0 -65
  97. package/src/src/generators/models/models.ts +0 -95
  98. package/src/src/generators/services/okhttp3-clients/args.ts +0 -90
  99. package/src/src/generators/services/okhttp3-clients/index.ts +0 -4
  100. package/src/src/generators/services/okhttp3-clients/models.ts +0 -73
  101. package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +0 -609
  102. package/src/src/generators/services/okhttp3-clients/okhttp3-clients-generator.ts +0 -169
  103. package/src/src/generators/services/okhttp3-clients/refs.ts +0 -59
  104. package/src/src/generators/services/spring-controllers/args.ts +0 -95
  105. package/src/src/generators/services/spring-controllers/index.ts +0 -4
  106. package/src/src/generators/services/spring-controllers/models.ts +0 -76
  107. package/src/src/generators/services/spring-controllers/refs.ts +0 -17
  108. package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +0 -1097
  109. package/src/src/generators/services/spring-controllers/spring-controllers-generator.ts +0 -140
  110. package/src/src/generators/services/spring-reactive-web-clients/args.ts +0 -103
  111. package/src/src/generators/services/spring-reactive-web-clients/index.ts +0 -4
  112. package/src/src/generators/services/spring-reactive-web-clients/models.ts +0 -62
  113. package/src/src/generators/services/spring-reactive-web-clients/refs.ts +0 -11
  114. package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.ts +0 -583
  115. package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.ts +0 -125
  116. package/src/src/import-collection.ts +0 -98
  117. package/src/src/types.ts +0 -3
  118. package/src/src/utils.ts +0 -47
@@ -1,125 +0,0 @@
1
- import { resolve } from 'node:path';
2
-
3
- import {
4
- type ApiService,
5
- Factory,
6
- type MaybePromise,
7
- type OpenApiGeneratorContext,
8
- OpenApiServicesGenerationProviderBase,
9
- writeGeneratedFile,
10
- } from '@goast/core';
11
-
12
- import { getAssetFileContent } from '../../../assets.js';
13
- import type { KotlinServicesGeneratorInput } from '../spring-controllers/index.js';
14
- import {
15
- defaultKotlinSpringReactiveWebClientsGeneratorConfig,
16
- type KotlinSpringReactiveWebClientGeneratorOutput,
17
- type KotlinSpringReactiveWebClientsGeneratorConfig,
18
- type KotlinSpringReactiveWebClientsGeneratorContext,
19
- type KotlinSpringReactiveWebClientsGeneratorInput,
20
- type KotlinSpringReactiveWebClientsGeneratorOutput,
21
- } from './models.js';
22
- import { getReferenceFactories } from './refs.js';
23
- import {
24
- DefaultKotlinSpringReactiveWebClientGenerator,
25
- type KotlinSpringReactiveWebClientGenerator,
26
- } from './spring-reactive-web-client-generator.js';
27
-
28
- type Input = KotlinSpringReactiveWebClientsGeneratorInput;
29
- type Output = KotlinSpringReactiveWebClientsGeneratorOutput;
30
- type Config = KotlinSpringReactiveWebClientsGeneratorConfig;
31
- type ServiceOutput = KotlinSpringReactiveWebClientGeneratorOutput;
32
- type Context = KotlinSpringReactiveWebClientsGeneratorContext;
33
-
34
- export class KotlinSpringReactiveWebClientsGenerator extends OpenApiServicesGenerationProviderBase<
35
- Input,
36
- Output,
37
- Config,
38
- ServiceOutput,
39
- Context
40
- > {
41
- private readonly _serviceGeneratorFactory: Factory<KotlinSpringReactiveWebClientGenerator, []>;
42
-
43
- constructor(serviceGeneratorFactory?: Factory<KotlinSpringReactiveWebClientGenerator, []>) {
44
- super();
45
- this._serviceGeneratorFactory = serviceGeneratorFactory ??
46
- Factory.fromValue(new DefaultKotlinSpringReactiveWebClientGenerator());
47
- }
48
-
49
- protected override async generateAdditionalFiles(ctx: Context): Promise<void> {
50
- await this.copyInfrastructureFiles(ctx);
51
- }
52
-
53
- protected initResult(): Output {
54
- return {
55
- kotlin: {
56
- clients: {},
57
- },
58
- };
59
- }
60
-
61
- protected generateService(ctx: Context, service: ApiService): MaybePromise<ServiceOutput> {
62
- const serviceGenerator = this._serviceGeneratorFactory.create();
63
- return serviceGenerator.generate({
64
- ...ctx,
65
- service,
66
- });
67
- }
68
-
69
- protected addServiceResult(ctx: Context, service: ApiService, result: ServiceOutput): void {
70
- ctx.output.kotlin.clients[service.id] = result;
71
- }
72
-
73
- protected buildContext(
74
- context: OpenApiGeneratorContext<KotlinServicesGeneratorInput>,
75
- config?: Partial<Config> | undefined,
76
- ): Context {
77
- context.data.services = context.data.services.filter((x) => x.name !== 'exclude-from-generation');
78
- const providerContext = this.getProviderContext(
79
- context,
80
- config,
81
- defaultKotlinSpringReactiveWebClientsGeneratorConfig,
82
- );
83
- const infrastructurePackageName = this.getInfrastructurePackageName(providerContext.config);
84
- return Object.assign(providerContext, {
85
- infrastructurePackageName,
86
- refs: getReferenceFactories(infrastructurePackageName),
87
- });
88
- }
89
-
90
- protected getInfrastructurePackageName(config: Config): string {
91
- if (typeof config.infrastructurePackageName === 'string') {
92
- return config.infrastructurePackageName;
93
- }
94
- if (config.infrastructurePackageName.mode === 'append-package-name') {
95
- return config.packageName + config.infrastructurePackageName.value;
96
- }
97
- if (config.infrastructurePackageName.mode === 'append-full-package-name') {
98
- return this.getPackageName(config) + config.infrastructurePackageName.value;
99
- }
100
-
101
- return config.infrastructurePackageName.value;
102
- }
103
-
104
- protected getPackageName(config: Config): string {
105
- const packageSuffix = typeof config.packageSuffix === 'string' ? config.packageSuffix : config.packageSuffix();
106
- return config.packageName + packageSuffix;
107
- }
108
-
109
- private async copyInfrastructureFiles(ctx: Context): Promise<void> {
110
- const targetDir = resolve(ctx.config.outputDir, ctx.infrastructurePackageName.replace(/\./g, '/'));
111
-
112
- const files = [
113
- 'ApiRequestFile.kt',
114
- ];
115
-
116
- for (const file of files) {
117
- const sourcePath = `client/spring-reactive-web-clients/${file}`;
118
- const targetPath = resolve(targetDir, file);
119
- console.log(`Copying asset file "${sourcePath}" to "${targetPath}"`);
120
- const fileContent = (await getAssetFileContent(sourcePath))
121
- .replace(/@PACKAGE_NAME@/g, ctx.infrastructurePackageName);
122
- writeGeneratedFile(ctx.config, targetPath, fileContent);
123
- }
124
- }
125
- }
@@ -1,98 +0,0 @@
1
- import { type SourceBuilderOptions, StringBuilder } from '@goast/core';
2
-
3
- import type { KotlinImport } from './common-results.js';
4
- import { defaultKotlinGeneratorConfig } from './config.js';
5
-
6
- export type ImportCollectionOptions = {
7
- globalImports: string[];
8
- };
9
-
10
- export const defaultImportCollectionOptions: ImportCollectionOptions = {
11
- globalImports: defaultKotlinGeneratorConfig.globalImports,
12
- };
13
-
14
- export class ImportCollection {
15
- private readonly _imports: Map<string, Set<string>> = new Map();
16
- private readonly _options: ImportCollectionOptions;
17
-
18
- constructor(options: Partial<ImportCollectionOptions> = {}) {
19
- this._options = { ...defaultImportCollectionOptions, ...options };
20
- }
21
-
22
- public get hasImports(): boolean {
23
- return this._imports.size > 0;
24
- }
25
-
26
- public get imports(): KotlinImport[] {
27
- return Array.from(this._imports.entries())
28
- .map(([fromPackage, importNames]) =>
29
- Array.from(importNames).map((importName) => ({
30
- packageName: fromPackage,
31
- typeName: importName,
32
- }))
33
- )
34
- .flat();
35
- }
36
-
37
- public addImport(importName: string, fromModule: string): void;
38
- public addImport(importObj: KotlinImport): void;
39
- public addImport(importOrImportName: KotlinImport | string, fromModule?: string): void {
40
- const importName = typeof importOrImportName === 'string' ? importOrImportName : importOrImportName.typeName;
41
- fromModule = typeof importOrImportName === 'string' ? fromModule : importOrImportName.packageName;
42
-
43
- if (!fromModule) {
44
- return;
45
- }
46
-
47
- const existingImport = this._imports.get(fromModule);
48
- if (existingImport) {
49
- existingImport.add(importName);
50
- } else {
51
- this._imports.set(fromModule!, new Set([importName]));
52
- }
53
- }
54
-
55
- public addImports(imports: KotlinImport[]): void {
56
- for (const importObj of imports) {
57
- this.addImport(importObj);
58
- }
59
- }
60
-
61
- public clear(): void {
62
- this._imports.clear();
63
- }
64
-
65
- public toString(options?: Partial<SourceBuilderOptions>): string {
66
- const builder = new StringBuilder(options);
67
- this.writeTo(builder);
68
- return builder.toString();
69
- }
70
-
71
- public writeTo(builder: StringBuilder) {
72
- if (this._imports.size > 0) {
73
- const globalPackages = this._options.globalImports
74
- .filter((g) => g.endsWith('.*'))
75
- .map((g) => g.substring(0, g.length - 2));
76
- const globalImports = this._options.globalImports.filter((g) => !g.endsWith('.*'));
77
-
78
- Array.from(this._imports.entries())
79
- .filter(([packageName]) => !globalPackages.includes(packageName))
80
- .flatMap(([packageName, importNames]) => Array.from(importNames).map((importName) => [packageName, importName]))
81
- .map(([packageName, importName]) => `${packageName}.${importName}`)
82
- .filter((importPath) => !globalImports.includes(importPath))
83
- .sort((a, b) => {
84
- if (isCoreImport(a) && !isCoreImport(b)) {
85
- return 1;
86
- } else if (!isCoreImport(a) && isCoreImport(b)) {
87
- return -1;
88
- }
89
- return a.localeCompare(b);
90
- })
91
- .forEach((importPath) => builder.appendLine(`import ${importPath}`));
92
- }
93
- }
94
- }
95
-
96
- function isCoreImport(importPath: string): boolean {
97
- return importPath.startsWith('kotlin.') || importPath.startsWith('java.') || importPath.startsWith('javax.');
98
- }
package/src/src/types.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { ApiParameter } from '@goast/core';
2
-
3
- export type ApiParameterWithMultipartInfo = ApiParameter & { multipart?: { name: string; isFile: boolean } };
package/src/src/utils.ts DELETED
@@ -1,47 +0,0 @@
1
- import type { ApiComponent, Nullable } from '@goast/core';
2
- import path from 'node:path';
3
- import process from 'node:process';
4
-
5
- export function toKotlinStringLiteral(value: Nullable<string>): string {
6
- if (!value) {
7
- return '""';
8
- }
9
-
10
- const escaped = value
11
- .replace(/(["\\$])/g, '\\$1')
12
- .replace(/\n/g, '\\n')
13
- .replace(/\r/g, '\\r')
14
- .replace(/\t/g, '\\t');
15
- return `"${escaped}"`;
16
- }
17
-
18
- export function toKotlinPropertyName(value: string): string {
19
- if (value.match(/^[a-zA-Z_$][a-zA-Z_$0-9]*$/)) {
20
- return value;
21
- }
22
- return `\`${value}\``;
23
- }
24
-
25
- export function modifyString<TArgs extends unknown[]>(
26
- value: string,
27
- modifier: string | RegExp | ((value: string, ...args: TArgs) => string) | undefined,
28
- ...args: TArgs
29
- ): string {
30
- if (typeof modifier === 'string') {
31
- return modifier;
32
- }
33
- if (modifier instanceof RegExp) {
34
- const match = value.match(modifier);
35
- return match?.[0] ?? value;
36
- }
37
- if (typeof modifier === 'function') {
38
- return modifier(value, ...args);
39
- }
40
- return value;
41
- }
42
-
43
- export function getSourceDocLine<T>(component: ApiComponent<T>): string {
44
- const file = path.relative(process.cwd(), component.$src.file).replace(/\\/g, '/');
45
- const { line, col } = component.$src.pos;
46
- return `Source: ${file}:${line}:${col} (${component.$src.path})`;
47
- }