@goast/kotlin 0.7.0 → 0.7.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/dist/src/assets.d.ts +17 -0
- package/dist/src/assets.js +17 -0
- package/dist/src/ast/common.d.ts +4 -0
- package/dist/src/ast/node.d.ts +11 -0
- package/dist/src/ast/node.js +11 -0
- package/dist/src/ast/nodes/annotation.d.ts +44 -0
- package/dist/src/ast/nodes/annotation.js +40 -0
- package/dist/src/ast/nodes/argument.d.ts +33 -0
- package/dist/src/ast/nodes/argument.js +33 -0
- package/dist/src/ast/nodes/call.d.ts +42 -0
- package/dist/src/ast/nodes/call.js +42 -0
- package/dist/src/ast/nodes/class.d.ts +96 -0
- package/dist/src/ast/nodes/class.js +90 -0
- package/dist/src/ast/nodes/collection-literal.d.ts +35 -0
- package/dist/src/ast/nodes/collection-literal.js +35 -0
- package/dist/src/ast/nodes/constructor.d.ts +65 -0
- package/dist/src/ast/nodes/constructor.js +62 -0
- package/dist/src/ast/nodes/doc-tag.d.ts +41 -0
- package/dist/src/ast/nodes/doc-tag.js +41 -0
- package/dist/src/ast/nodes/doc.d.ts +44 -0
- package/dist/src/ast/nodes/doc.js +44 -0
- package/dist/src/ast/nodes/enum-value.d.ts +50 -0
- package/dist/src/ast/nodes/enum-value.js +47 -0
- package/dist/src/ast/nodes/enum.d.ts +67 -0
- package/dist/src/ast/nodes/enum.js +64 -0
- package/dist/src/ast/nodes/function.d.ts +105 -0
- package/dist/src/ast/nodes/function.js +105 -0
- package/dist/src/ast/nodes/generic-parameter.d.ts +37 -0
- package/dist/src/ast/nodes/generic-parameter.js +37 -0
- package/dist/src/ast/nodes/init-block.d.ts +32 -0
- package/dist/src/ast/nodes/init-block.js +32 -0
- package/dist/src/ast/nodes/interface.d.ts +73 -0
- package/dist/src/ast/nodes/interface.js +68 -0
- package/dist/src/ast/nodes/lambda-type.d.ts +42 -0
- package/dist/src/ast/nodes/lambda-type.js +42 -0
- package/dist/src/ast/nodes/lambda.d.ts +41 -0
- package/dist/src/ast/nodes/lambda.js +41 -0
- package/dist/src/ast/nodes/object.d.ts +66 -0
- package/dist/src/ast/nodes/object.js +62 -0
- package/dist/src/ast/nodes/parameter.d.ts +68 -0
- package/dist/src/ast/nodes/parameter.js +68 -0
- package/dist/src/ast/nodes/property.d.ts +152 -0
- package/dist/src/ast/nodes/property.js +148 -0
- package/dist/src/ast/nodes/reference.d.ts +107 -0
- package/dist/src/ast/nodes/reference.js +75 -0
- package/dist/src/ast/nodes/string.d.ts +57 -0
- package/dist/src/ast/nodes/string.js +57 -0
- package/dist/src/ast/nodes/types.d.ts +9 -0
- package/dist/src/ast/references/jackson.d.ts +67 -0
- package/dist/src/ast/references/jackson.js +59 -0
- package/dist/src/ast/references/jakarta.d.ts +13 -0
- package/dist/src/ast/references/jakarta.js +13 -0
- package/dist/src/ast/references/java.d.ts +19 -0
- package/dist/src/ast/references/java.js +19 -0
- package/dist/src/ast/references/kotlin.d.ts +28 -0
- package/dist/src/ast/references/kotlin.js +28 -0
- package/dist/src/ast/references/kotlinx.d.ts +8 -0
- package/dist/src/ast/references/kotlinx.js +8 -0
- package/dist/src/ast/references/okhttp3.d.ts +8 -0
- package/dist/src/ast/references/okhttp3.js +8 -0
- package/dist/src/ast/references/reactor.d.ts +8 -0
- package/dist/src/ast/references/reactor.js +8 -0
- package/dist/src/ast/references/spring-reactive.d.ts +18 -0
- package/dist/src/ast/references/spring-reactive.js +18 -0
- package/dist/src/ast/references/spring.d.ts +27 -0
- package/dist/src/ast/references/spring.js +27 -0
- package/dist/src/ast/references/swagger.d.ts +13 -0
- package/dist/src/ast/references/swagger.js +13 -0
- package/dist/src/ast/utils/get-kotlin-builder-options.d.ts +10 -0
- package/dist/src/ast/utils/get-kotlin-builder-options.js +10 -0
- package/dist/src/ast/utils/to-kt-node.d.ts +40 -0
- package/dist/src/ast/utils/write-kt-annotations.d.ts +13 -0
- package/dist/src/ast/utils/write-kt-annotations.js +13 -0
- package/dist/src/ast/utils/write-kt-arguments.d.ts +15 -0
- package/dist/src/ast/utils/write-kt-arguments.js +15 -0
- package/dist/src/ast/utils/write-kt-enum-values.d.ts +13 -0
- package/dist/src/ast/utils/write-kt-enum-values.js +13 -0
- package/dist/src/ast/utils/write-kt-generic-parameters.d.ts +10 -0
- package/dist/src/ast/utils/write-kt-generic-parameters.js +10 -0
- package/dist/src/ast/utils/write-kt-members.d.ts +16 -0
- package/dist/src/ast/utils/write-kt-members.js +16 -0
- package/dist/src/ast/utils/write-kt-node.d.ts +29 -0
- package/dist/src/ast/utils/write-kt-node.js +24 -0
- package/dist/src/ast/utils/write-kt-parameters.d.ts +13 -0
- package/dist/src/ast/utils/write-kt-parameters.js +13 -0
- package/dist/src/common-results.d.ts +9 -0
- package/dist/src/config.d.ts +72 -0
- package/dist/src/config.js +5 -0
- package/dist/src/file-builder.d.ts +91 -0
- package/dist/src/file-builder.js +81 -0
- package/dist/src/generators/file-generator.d.ts +12 -0
- package/dist/src/generators/file-generator.js +7 -0
- package/dist/src/generators/models/args.d.ts +233 -0
- package/dist/src/generators/models/model-generator.d.ts +25 -0
- package/dist/src/generators/models/model-generator.js +14 -0
- package/dist/src/generators/models/models-generator.d.ts +15 -0
- package/dist/src/generators/models/models-generator.js +15 -0
- package/dist/src/generators/models/models.d.ts +93 -2
- package/dist/src/generators/models/models.js +5 -0
- package/dist/src/generators/services/okhttp3-clients/args.d.ts +138 -0
- package/dist/src/generators/services/okhttp3-clients/models.d.ts +83 -0
- package/dist/src/generators/services/okhttp3-clients/models.js +5 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-client-generator.d.ts +33 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-client-generator.js +20 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-clients-generator.d.ts +21 -0
- package/dist/src/generators/services/okhttp3-clients/okhttp3-clients-generator.js +21 -0
- package/dist/src/generators/services/okhttp3-clients/refs.d.ts +25 -0
- package/dist/src/generators/services/okhttp3-clients/refs.js +7 -0
- package/dist/src/generators/services/spring-controllers/args.d.ts +169 -0
- package/dist/src/generators/services/spring-controllers/models.d.ts +120 -0
- package/dist/src/generators/services/spring-controllers/models.js +4 -0
- package/dist/src/generators/services/spring-controllers/refs.d.ts +9 -0
- package/dist/src/generators/services/spring-controllers/refs.js +9 -0
- package/dist/src/generators/services/spring-controllers/spring-controller-generator.d.ts +29 -0
- package/dist/src/generators/services/spring-controllers/spring-controller-generator.js +19 -0
- package/dist/src/generators/services/spring-controllers/spring-controllers-generator.d.ts +22 -0
- package/dist/src/generators/services/spring-controllers/spring-controllers-generator.js +22 -0
- package/dist/src/generators/services/spring-reactive-web-clients/args.d.ts +224 -0
- package/dist/src/generators/services/spring-reactive-web-clients/models.d.ts +86 -0
- package/dist/src/generators/services/spring-reactive-web-clients/models.js +4 -0
- package/dist/src/generators/services/spring-reactive-web-clients/refs.d.ts +7 -0
- package/dist/src/generators/services/spring-reactive-web-clients/refs.js +7 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.d.ts +36 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-client-generator.js +25 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.d.ts +20 -0
- package/dist/src/generators/services/spring-reactive-web-clients/spring-reactive-web-clients-generator.js +20 -0
- package/dist/src/import-collection.d.ts +64 -0
- package/dist/src/import-collection.js +46 -0
- package/dist/src/types.d.ts +4 -0
- package/dist/src/utils.d.ts +52 -0
- package/dist/src/utils.js +52 -0
- package/package.json +2 -2
|
@@ -1,19 +1,83 @@
|
|
|
1
1
|
import { type SourceBuilderOptions, StringBuilder } from '@goast/core';
|
|
2
2
|
import type { KotlinImport } from './common-results.ts';
|
|
3
|
+
/**
|
|
4
|
+
* The options of an `ImportCollection`.
|
|
5
|
+
*/
|
|
3
6
|
export type ImportCollectionOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The imports to leave out when the collection is written. An entry ending in `.*` excludes a whole package, and any
|
|
9
|
+
* other entry excludes a single type by its fully qualified name.
|
|
10
|
+
* @default defaultKotlinGeneratorConfig.globalImports
|
|
11
|
+
* @see KotlinGeneratorConfig.globalImports
|
|
12
|
+
*/
|
|
4
13
|
globalImports: string[];
|
|
5
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* The options that an `ImportCollection` falls back to for any option that is not given. Its `globalImports` is the
|
|
17
|
+
* default of `defaultKotlinGeneratorConfig`.
|
|
18
|
+
* @see defaultKotlinGeneratorConfig
|
|
19
|
+
*/
|
|
6
20
|
export declare const defaultImportCollectionOptions: ImportCollectionOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Collects the types that a generated Kotlin file imports and writes them as `import` statements.
|
|
23
|
+
*
|
|
24
|
+
* Each type is stored once per package. When written, the imports are sorted by their full path, ignoring case, and
|
|
25
|
+
* imports whose path starts with `kotlin.`, `java.` or `javax.` come after all others. Imports that match
|
|
26
|
+
* `globalImports` are not written, but the `imports` getter still returns them.
|
|
27
|
+
* @see ImportCollectionOptions
|
|
28
|
+
* @see KotlinFileBuilder
|
|
29
|
+
*/
|
|
7
30
|
export declare class ImportCollection {
|
|
8
31
|
private readonly _imports;
|
|
9
32
|
private readonly _options;
|
|
33
|
+
/**
|
|
34
|
+
* Initializes a new instance of the ImportCollection class.
|
|
35
|
+
* @param options The options to use for this instance. Options that are not given keep their defaults.
|
|
36
|
+
*/
|
|
10
37
|
constructor(options?: Partial<ImportCollectionOptions>);
|
|
38
|
+
/**
|
|
39
|
+
* Gets a value indicating whether any import has been added. This includes imports that `globalImports` leaves out
|
|
40
|
+
* when the collection is written.
|
|
41
|
+
*/
|
|
11
42
|
get hasImports(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Gets all added imports, one entry per type with its package. Unlike `writeTo`, this does not apply `globalImports`.
|
|
45
|
+
* @returns The added imports, grouped by package in the order in which the first import of each package was added.
|
|
46
|
+
*/
|
|
12
47
|
get imports(): KotlinImport[];
|
|
48
|
+
/**
|
|
49
|
+
* Adds the import of a type from a package. Nothing is added when `fromModule` is empty.
|
|
50
|
+
* @param importName The name of the type, such as `List`.
|
|
51
|
+
* @param fromModule The package the type is declared in, such as `kotlin.collections`.
|
|
52
|
+
*/
|
|
13
53
|
addImport(importName: string, fromModule: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Adds the import described by a `KotlinImport`. Nothing is added when its `packageName` is missing.
|
|
56
|
+
* @param importObj The import to add.
|
|
57
|
+
*/
|
|
14
58
|
addImport(importObj: KotlinImport): void;
|
|
59
|
+
/**
|
|
60
|
+
* Adds several imports, one after the other, as `addImport` does for each of them.
|
|
61
|
+
* @param imports The imports to add.
|
|
62
|
+
*/
|
|
15
63
|
addImports(imports: KotlinImport[]): void;
|
|
64
|
+
/**
|
|
65
|
+
* Removes all added imports.
|
|
66
|
+
*/
|
|
16
67
|
clear(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Gets the import statements as text. This is the same text that `writeTo` appends.
|
|
70
|
+
* @param options The options of the string builder that builds the text, such as the line break characters.
|
|
71
|
+
* @returns The import statements, one per line. Empty when no import is left to write.
|
|
72
|
+
*/
|
|
17
73
|
toString(options?: Partial<SourceBuilderOptions>): string;
|
|
74
|
+
/**
|
|
75
|
+
* Appends one `import` statement per line to the builder, in the order described on `ImportCollection`. Writes
|
|
76
|
+
* nothing when no import is left after filtering.
|
|
77
|
+
*
|
|
78
|
+
* An import is left out when its package is listed in `globalImports` as an entry ending in `.*`, or when its full
|
|
79
|
+
* path (`package.Type`) is listed as an entry without that suffix.
|
|
80
|
+
* @param builder The builder to append the import statements to.
|
|
81
|
+
*/
|
|
18
82
|
writeTo(builder: StringBuilder): void;
|
|
19
83
|
}
|
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
import { compareString, StringBuilder } from '@goast/core';
|
|
2
2
|
import { defaultKotlinGeneratorConfig } from './config.js';
|
|
3
|
+
/**
|
|
4
|
+
* The options that an `ImportCollection` falls back to for any option that is not given. Its `globalImports` is the
|
|
5
|
+
* default of `defaultKotlinGeneratorConfig`.
|
|
6
|
+
* @see defaultKotlinGeneratorConfig
|
|
7
|
+
*/
|
|
3
8
|
export const defaultImportCollectionOptions = {
|
|
4
9
|
globalImports: defaultKotlinGeneratorConfig.globalImports,
|
|
5
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Collects the types that a generated Kotlin file imports and writes them as `import` statements.
|
|
13
|
+
*
|
|
14
|
+
* Each type is stored once per package. When written, the imports are sorted by their full path, ignoring case, and
|
|
15
|
+
* imports whose path starts with `kotlin.`, `java.` or `javax.` come after all others. Imports that match
|
|
16
|
+
* `globalImports` are not written, but the `imports` getter still returns them.
|
|
17
|
+
* @see ImportCollectionOptions
|
|
18
|
+
* @see KotlinFileBuilder
|
|
19
|
+
*/
|
|
6
20
|
export class ImportCollection {
|
|
7
21
|
_imports = new Map();
|
|
8
22
|
_options;
|
|
23
|
+
/**
|
|
24
|
+
* Initializes a new instance of the ImportCollection class.
|
|
25
|
+
* @param options The options to use for this instance. Options that are not given keep their defaults.
|
|
26
|
+
*/
|
|
9
27
|
constructor(options = {}) {
|
|
10
28
|
this._options = { ...defaultImportCollectionOptions, ...options };
|
|
11
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets a value indicating whether any import has been added. This includes imports that `globalImports` leaves out
|
|
32
|
+
* when the collection is written.
|
|
33
|
+
*/
|
|
12
34
|
get hasImports() {
|
|
13
35
|
return this._imports.size > 0;
|
|
14
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets all added imports, one entry per type with its package. Unlike `writeTo`, this does not apply `globalImports`.
|
|
39
|
+
* @returns The added imports, grouped by package in the order in which the first import of each package was added.
|
|
40
|
+
*/
|
|
15
41
|
get imports() {
|
|
16
42
|
return Array.from(this._imports.entries())
|
|
17
43
|
.map(([fromPackage, importNames]) => Array.from(importNames).map((importName) => ({
|
|
@@ -34,19 +60,39 @@ export class ImportCollection {
|
|
|
34
60
|
this._imports.set(fromModule, new Set([importName]));
|
|
35
61
|
}
|
|
36
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Adds several imports, one after the other, as `addImport` does for each of them.
|
|
65
|
+
* @param imports The imports to add.
|
|
66
|
+
*/
|
|
37
67
|
addImports(imports) {
|
|
38
68
|
for (const importObj of imports) {
|
|
39
69
|
this.addImport(importObj);
|
|
40
70
|
}
|
|
41
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Removes all added imports.
|
|
74
|
+
*/
|
|
42
75
|
clear() {
|
|
43
76
|
this._imports.clear();
|
|
44
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets the import statements as text. This is the same text that `writeTo` appends.
|
|
80
|
+
* @param options The options of the string builder that builds the text, such as the line break characters.
|
|
81
|
+
* @returns The import statements, one per line. Empty when no import is left to write.
|
|
82
|
+
*/
|
|
45
83
|
toString(options) {
|
|
46
84
|
const builder = new StringBuilder(options);
|
|
47
85
|
this.writeTo(builder);
|
|
48
86
|
return builder.toString();
|
|
49
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Appends one `import` statement per line to the builder, in the order described on `ImportCollection`. Writes
|
|
90
|
+
* nothing when no import is left after filtering.
|
|
91
|
+
*
|
|
92
|
+
* An import is left out when its package is listed in `globalImports` as an entry ending in `.*`, or when its full
|
|
93
|
+
* path (`package.Type`) is listed as an entry without that suffix.
|
|
94
|
+
* @param builder The builder to append the import statements to.
|
|
95
|
+
*/
|
|
50
96
|
writeTo(builder) {
|
|
51
97
|
if (this._imports.size > 0) {
|
|
52
98
|
const globalPackages = this._options.globalImports
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { ApiParameter } from '@goast/core';
|
|
2
|
+
/**
|
|
3
|
+
* An API parameter that can carry the form part it is sent as in a `multipart/form-data` request body.
|
|
4
|
+
* @see ApiParameter
|
|
5
|
+
*/
|
|
2
6
|
export type ApiParameterWithMultipartInfo = ApiParameter & {
|
|
3
7
|
multipart?: {
|
|
4
8
|
name: string;
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,7 +1,59 @@
|
|
|
1
1
|
import type { ApiComponent, ApiSchema, Nullable } from '@goast/core';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a string to a Kotlin string literal. Double quotes, backslashes and dollar signs are escaped, and line
|
|
4
|
+
* breaks and tabs are written as escape sequences. A nullish or empty value becomes `""`.
|
|
5
|
+
* @param value The string to convert.
|
|
6
|
+
* @returns The string literal, including its surrounding double quotes.
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* toKotlinStringLiteral('say "hi" $x'); // => "say \"hi\" \$x"
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
2
12
|
export declare function toKotlinStringLiteral(value: Nullable<string>): string;
|
|
13
|
+
/**
|
|
14
|
+
* Gets a name that can be used as a Kotlin property name. A name that consists only of letters, digits, `_` and `$`,
|
|
15
|
+
* and does not start with a digit, is returned unchanged. Any other name is wrapped in backticks. Reserved words are
|
|
16
|
+
* not detected.
|
|
17
|
+
* @param value The name to convert.
|
|
18
|
+
* @returns The name, wrapped in backticks if it contains other characters.
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* toKotlinPropertyName('firstName'); // => firstName
|
|
22
|
+
* toKotlinPropertyName('first-name'); // => `first-name`
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
3
25
|
export declare function toKotlinPropertyName(value: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Modifies a string with a modifier. A string modifier replaces the value. A regular expression replaces the value with
|
|
28
|
+
* its first match, or keeps the value when nothing matches. A function returns the new value. Without a modifier, the
|
|
29
|
+
* value is returned unchanged.
|
|
30
|
+
* @template TArgs The types of the extra arguments that are passed to a modifier function.
|
|
31
|
+
* @param value The value to modify.
|
|
32
|
+
* @param modifier The replacement string, the regular expression, or the function that computes the new value.
|
|
33
|
+
* @param args The extra arguments that are passed to a modifier function.
|
|
34
|
+
* @returns The modified string.
|
|
35
|
+
*/
|
|
4
36
|
export declare function modifyString<TArgs extends unknown[]>(value: string, modifier: string | RegExp | ((value: string, ...args: TArgs) => string) | undefined, ...args: TArgs): string;
|
|
37
|
+
/**
|
|
38
|
+
* Gets a documentation line that names the OpenAPI source of a component, such as
|
|
39
|
+
* `Source: openapi/pet.yaml:12:3 (#/components/schemas/Pet)`. The file path is relative to the working directory and
|
|
40
|
+
* uses forward slashes.
|
|
41
|
+
* @template T The OpenAPI object type the component was transformed from.
|
|
42
|
+
* @param component The component whose source is named.
|
|
43
|
+
* @returns The source line.
|
|
44
|
+
*/
|
|
5
45
|
export declare function getSourceDocLine<T>(component: ApiComponent<T>): string;
|
|
46
|
+
/**
|
|
47
|
+
* Gets a schema if it is a string schema with at least one enum value.
|
|
48
|
+
* @param schema The schema to check.
|
|
49
|
+
* @returns The schema, or `undefined` if it is not a string schema with enum values.
|
|
50
|
+
*/
|
|
6
51
|
export declare function getStringEnumSchema(schema: Nullable<ApiSchema>): ApiSchema<'string'> | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the string enum schema of the items of an array schema.
|
|
54
|
+
* @param schema The schema to check.
|
|
55
|
+
* @returns The enum schema of the array items, or `undefined` if the schema is not an array whose items are a string
|
|
56
|
+
* enum.
|
|
57
|
+
* @see getStringEnumSchema
|
|
58
|
+
*/
|
|
7
59
|
export declare function getArrayItemStringEnumSchema(schema: Nullable<ApiSchema>): ApiSchema<'string'> | undefined;
|
package/dist/src/utils.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import process from 'node:process';
|
|
3
|
+
/**
|
|
4
|
+
* Converts a string to a Kotlin string literal. Double quotes, backslashes and dollar signs are escaped, and line
|
|
5
|
+
* breaks and tabs are written as escape sequences. A nullish or empty value becomes `""`.
|
|
6
|
+
* @param value The string to convert.
|
|
7
|
+
* @returns The string literal, including its surrounding double quotes.
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* toKotlinStringLiteral('say "hi" $x'); // => "say \"hi\" \$x"
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
3
13
|
export function toKotlinStringLiteral(value) {
|
|
4
14
|
if (!value) {
|
|
5
15
|
return '""';
|
|
@@ -11,12 +21,34 @@ export function toKotlinStringLiteral(value) {
|
|
|
11
21
|
.replace(/\t/g, '\\t');
|
|
12
22
|
return `"${escaped}"`;
|
|
13
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Gets a name that can be used as a Kotlin property name. A name that consists only of letters, digits, `_` and `$`,
|
|
26
|
+
* and does not start with a digit, is returned unchanged. Any other name is wrapped in backticks. Reserved words are
|
|
27
|
+
* not detected.
|
|
28
|
+
* @param value The name to convert.
|
|
29
|
+
* @returns The name, wrapped in backticks if it contains other characters.
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* toKotlinPropertyName('firstName'); // => firstName
|
|
33
|
+
* toKotlinPropertyName('first-name'); // => `first-name`
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
14
36
|
export function toKotlinPropertyName(value) {
|
|
15
37
|
if (value.match(/^[a-zA-Z_$][a-zA-Z_$0-9]*$/)) {
|
|
16
38
|
return value;
|
|
17
39
|
}
|
|
18
40
|
return `\`${value}\``;
|
|
19
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Modifies a string with a modifier. A string modifier replaces the value. A regular expression replaces the value with
|
|
44
|
+
* its first match, or keeps the value when nothing matches. A function returns the new value. Without a modifier, the
|
|
45
|
+
* value is returned unchanged.
|
|
46
|
+
* @template TArgs The types of the extra arguments that are passed to a modifier function.
|
|
47
|
+
* @param value The value to modify.
|
|
48
|
+
* @param modifier The replacement string, the regular expression, or the function that computes the new value.
|
|
49
|
+
* @param args The extra arguments that are passed to a modifier function.
|
|
50
|
+
* @returns The modified string.
|
|
51
|
+
*/
|
|
20
52
|
export function modifyString(value, modifier, ...args) {
|
|
21
53
|
if (typeof modifier === 'string') {
|
|
22
54
|
return modifier;
|
|
@@ -30,14 +62,34 @@ export function modifyString(value, modifier, ...args) {
|
|
|
30
62
|
}
|
|
31
63
|
return value;
|
|
32
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets a documentation line that names the OpenAPI source of a component, such as
|
|
67
|
+
* `Source: openapi/pet.yaml:12:3 (#/components/schemas/Pet)`. The file path is relative to the working directory and
|
|
68
|
+
* uses forward slashes.
|
|
69
|
+
* @template T The OpenAPI object type the component was transformed from.
|
|
70
|
+
* @param component The component whose source is named.
|
|
71
|
+
* @returns The source line.
|
|
72
|
+
*/
|
|
33
73
|
export function getSourceDocLine(component) {
|
|
34
74
|
const file = path.relative(process.cwd(), component.$src.file).replace(/\\/g, '/');
|
|
35
75
|
const { line, col } = component.$src.pos;
|
|
36
76
|
return `Source: ${file}:${line}:${col} (${component.$src.path})`;
|
|
37
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets a schema if it is a string schema with at least one enum value.
|
|
80
|
+
* @param schema The schema to check.
|
|
81
|
+
* @returns The schema, or `undefined` if it is not a string schema with enum values.
|
|
82
|
+
*/
|
|
38
83
|
export function getStringEnumSchema(schema) {
|
|
39
84
|
return schema?.kind === 'string' && schema.enum?.length ? schema : undefined;
|
|
40
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Gets the string enum schema of the items of an array schema.
|
|
88
|
+
* @param schema The schema to check.
|
|
89
|
+
* @returns The enum schema of the array items, or `undefined` if the schema is not an array whose items are a string
|
|
90
|
+
* enum.
|
|
91
|
+
* @see getStringEnumSchema
|
|
92
|
+
*/
|
|
41
93
|
export function getArrayItemStringEnumSchema(schema) {
|
|
42
94
|
return schema?.kind === 'array' ? getStringEnumSchema(schema.items) : undefined;
|
|
43
95
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goast/kotlin",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Provides gOAst generators for generating Kotlin code from OpenAPI specifications.",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/MaSch0212/goast/issues"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"http-status-codes": "^2.3.0",
|
|
35
|
-
"@goast/core": "^0.7.
|
|
35
|
+
"@goast/core": "^0.7.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@goast/test-harness": "0.0.0"
|