@goast/kotlin 0.5.1-beta.1 → 0.5.2

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 (94) 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/generators/models/model-generator.d.ts.map +1 -1
  12. package/esm/src/generators/models/model-generator.js +1 -0
  13. package/package.json +2 -2
  14. package/script/src/generators/models/model-generator.d.ts.map +1 -1
  15. package/script/src/generators/models/model-generator.js +1 -0
  16. package/src/mod.ts +8 -0
  17. package/src/src/assets.ts +9 -0
  18. package/src/src/ast/_index.ts +66 -0
  19. package/src/src/ast/common.ts +1 -0
  20. package/src/src/ast/index.ts +1 -0
  21. package/src/src/ast/node.ts +10 -0
  22. package/src/src/ast/nodes/annotation.ts +79 -0
  23. package/src/src/ast/nodes/argument.ts +62 -0
  24. package/src/src/ast/nodes/call.ts +75 -0
  25. package/src/src/ast/nodes/class.ts +178 -0
  26. package/src/src/ast/nodes/collection-literal.ts +49 -0
  27. package/src/src/ast/nodes/constructor.ts +126 -0
  28. package/src/src/ast/nodes/doc-tag.ts +138 -0
  29. package/src/src/ast/nodes/doc.ts +111 -0
  30. package/src/src/ast/nodes/enum-value.ts +100 -0
  31. package/src/src/ast/nodes/enum.ts +163 -0
  32. package/src/src/ast/nodes/function.ts +178 -0
  33. package/src/src/ast/nodes/generic-parameter.ts +54 -0
  34. package/src/src/ast/nodes/init-block.ts +38 -0
  35. package/src/src/ast/nodes/interface.ts +133 -0
  36. package/src/src/ast/nodes/lambda-type.ts +73 -0
  37. package/src/src/ast/nodes/lambda.ts +74 -0
  38. package/src/src/ast/nodes/object.ts +102 -0
  39. package/src/src/ast/nodes/parameter.ts +118 -0
  40. package/src/src/ast/nodes/property.ts +225 -0
  41. package/src/src/ast/nodes/reference.ts +178 -0
  42. package/src/src/ast/nodes/string.ts +114 -0
  43. package/src/src/ast/nodes/types.ts +23 -0
  44. package/src/src/ast/references/index.ts +10 -0
  45. package/src/src/ast/references/jackson.ts +44 -0
  46. package/src/src/ast/references/jakarta.ts +14 -0
  47. package/src/src/ast/references/java.ts +20 -0
  48. package/src/src/ast/references/kotlin.ts +41 -0
  49. package/src/src/ast/references/kotlinx.ts +14 -0
  50. package/src/src/ast/references/okhttp3.ts +5 -0
  51. package/src/src/ast/references/reactor.ts +5 -0
  52. package/src/src/ast/references/spring-reactive.ts +33 -0
  53. package/src/src/ast/references/spring.ts +86 -0
  54. package/src/src/ast/references/swagger.ts +23 -0
  55. package/src/src/ast/utils/get-kotlin-builder-options.ts +19 -0
  56. package/src/src/ast/utils/to-kt-node.ts +31 -0
  57. package/src/src/ast/utils/write-kt-annotations.ts +15 -0
  58. package/src/src/ast/utils/write-kt-arguments.ts +45 -0
  59. package/src/src/ast/utils/write-kt-enum-values.ts +27 -0
  60. package/src/src/ast/utils/write-kt-generic-parameters.ts +12 -0
  61. package/src/src/ast/utils/write-kt-members.ts +25 -0
  62. package/src/src/ast/utils/write-kt-node.ts +37 -0
  63. package/src/src/ast/utils/write-kt-parameters.ts +25 -0
  64. package/src/src/common-results.ts +4 -0
  65. package/src/src/config.ts +41 -0
  66. package/src/src/file-builder.ts +112 -0
  67. package/src/src/generators/file-generator.ts +29 -0
  68. package/src/src/generators/index.ts +5 -0
  69. package/src/src/generators/models/args.ts +132 -0
  70. package/src/src/generators/models/index.ts +4 -0
  71. package/src/src/generators/models/model-generator.ts +703 -0
  72. package/src/src/generators/models/models-generator.ts +65 -0
  73. package/src/src/generators/models/models.ts +95 -0
  74. package/src/src/generators/services/okhttp3-clients/args.ts +88 -0
  75. package/src/src/generators/services/okhttp3-clients/index.ts +4 -0
  76. package/src/src/generators/services/okhttp3-clients/models.ts +73 -0
  77. package/src/src/generators/services/okhttp3-clients/okhttp3-client-generator.ts +597 -0
  78. package/src/src/generators/services/okhttp3-clients/okhttp3-clients-generator.ts +169 -0
  79. package/src/src/generators/services/okhttp3-clients/refs.ts +59 -0
  80. package/src/src/generators/services/spring-controllers/args.ts +93 -0
  81. package/src/src/generators/services/spring-controllers/index.ts +4 -0
  82. package/src/src/generators/services/spring-controllers/models.ts +76 -0
  83. package/src/src/generators/services/spring-controllers/refs.ts +17 -0
  84. package/src/src/generators/services/spring-controllers/spring-controller-generator.ts +1084 -0
  85. package/src/src/generators/services/spring-controllers/spring-controllers-generator.ts +140 -0
  86. package/src/src/generators/services/spring-reactive-web-clients/args.ts +101 -0
  87. package/src/src/generators/services/spring-reactive-web-clients/index.ts +4 -0
  88. package/src/src/generators/services/spring-reactive-web-clients/models.ts +62 -0
  89. package/src/src/generators/services/spring-reactive-web-clients/refs.ts +11 -0
  90. package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.ts +571 -0
  91. package/src/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.ts +125 -0
  92. package/src/src/import-collection.ts +98 -0
  93. package/src/src/types.ts +3 -0
  94. package/src/src/utils.ts +39 -0
@@ -0,0 +1,98 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ import type { ApiParameter } from '@goast/core';
2
+
3
+ export type ApiParameterWithMultipartInfo = ApiParameter & { multipart?: { name: string; isFile: boolean } };
@@ -0,0 +1,39 @@
1
+ import type { Nullable } from '@goast/core';
2
+
3
+ export function toKotlinStringLiteral(value: Nullable<string>): string {
4
+ if (!value) {
5
+ return '""';
6
+ }
7
+
8
+ const escaped = value
9
+ .replace(/(["\\$])/g, '\\$1')
10
+ .replace(/\n/g, '\\n')
11
+ .replace(/\r/g, '\\r')
12
+ .replace(/\t/g, '\\t');
13
+ return `"${escaped}"`;
14
+ }
15
+
16
+ export function toKotlinPropertyName(value: string): string {
17
+ if (value.match(/^[a-zA-Z_$][a-zA-Z_$0-9]*$/)) {
18
+ return value;
19
+ }
20
+ return `\`${value}\``;
21
+ }
22
+
23
+ export function modifyString<TArgs extends unknown[]>(
24
+ value: string,
25
+ modifier: string | RegExp | ((value: string, ...args: TArgs) => string) | undefined,
26
+ ...args: TArgs
27
+ ): string {
28
+ if (typeof modifier === 'string') {
29
+ return modifier;
30
+ }
31
+ if (modifier instanceof RegExp) {
32
+ const match = value.match(modifier);
33
+ return match?.[0] ?? value;
34
+ }
35
+ if (typeof modifier === 'function') {
36
+ return modifier(value, ...args);
37
+ }
38
+ return value;
39
+ }