@goast/kotlin 0.3.14 → 0.3.15
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/cjs/lib/ast/references/swagger.js +3 -1
- package/cjs/lib/generators/services/spring-controllers/spring-controller-generator.js +37 -14
- package/esm/lib/ast/references/swagger.js +2 -0
- package/esm/lib/generators/services/spring-controllers/spring-controller-generator.js +37 -14
- package/package.json +1 -1
- package/types/lib/ast/references/swagger.d.ts +26 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.apiResponse = exports.schema = exports.operation = exports.parameter = void 0;
|
|
3
|
+
exports.apiResponses = exports.apiResponse = exports.content = exports.schema = exports.operation = exports.parameter = void 0;
|
|
4
4
|
const reference_1 = require("../nodes/reference");
|
|
5
5
|
// io.swagger.v3.oas.annotations
|
|
6
6
|
exports.parameter = reference_1.ktReference.factory('Parameter', 'io.swagger.v3.oas.annotations');
|
|
7
7
|
exports.operation = reference_1.ktReference.factory('Operation', 'io.swagger.v3.oas.annotations');
|
|
8
8
|
// io.swagger.v3.oas.annotations.media
|
|
9
9
|
exports.schema = reference_1.ktReference.factory('Schema', 'io.swagger.v3.oas.annotations.media');
|
|
10
|
+
exports.content = reference_1.ktReference.factory('Content', 'io.swagger.v3.oas.annotations.media');
|
|
10
11
|
// io.swagger.v3.oas.annotations.responses
|
|
11
12
|
exports.apiResponse = reference_1.ktReference.factory('ApiResponse', 'io.swagger.v3.oas.annotations.responses');
|
|
13
|
+
exports.apiResponses = reference_1.ktReference.factory('ApiResponses', 'io.swagger.v3.oas.annotations.responses');
|
|
@@ -80,19 +80,41 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
|
|
|
80
80
|
}
|
|
81
81
|
getApiInterfaceEndpointMethodAnnnotations(ctx, endpoint) {
|
|
82
82
|
var _a, _b, _c;
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
ast_1.kt.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
83
|
+
const annotations = [];
|
|
84
|
+
if (ctx.config.addSwaggerAnnotations) {
|
|
85
|
+
annotations.push(ast_1.kt.annotation(ast_1.kt.refs.swagger.operation(), [
|
|
86
|
+
endpoint.summary ? ast_1.kt.argument.named('summary', ast_1.kt.string((_a = endpoint.summary) === null || _a === void 0 ? void 0 : _a.trim())) : null,
|
|
87
|
+
ast_1.kt.argument.named('operationId', ast_1.kt.string(endpoint.name)),
|
|
88
|
+
endpoint.description ? ast_1.kt.argument.named('description', ast_1.kt.string((_b = endpoint.description) === null || _b === void 0 ? void 0 : _b.trim())) : null,
|
|
89
|
+
endpoint.deprecated !== undefined ? ast_1.kt.argument.named('deprecated', ast_1.kt.toNode(endpoint.deprecated)) : null,
|
|
90
|
+
]));
|
|
91
|
+
if (endpoint.responses.length > 0) {
|
|
92
|
+
annotations.push(ast_1.kt.annotation(ast_1.kt.refs.swagger.apiResponses(), [
|
|
93
|
+
ast_1.kt.argument.named('value', ast_1.kt.collectionLiteral(endpoint.responses.map((response) => {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
return ast_1.kt.call(ast_1.kt.refs.swagger.apiResponse(), [
|
|
96
|
+
ast_1.kt.argument.named('responseCode', ast_1.kt.string((_a = response.statusCode) === null || _a === void 0 ? void 0 : _a.toString())),
|
|
97
|
+
response.description
|
|
98
|
+
? ast_1.kt.argument.named('description', ast_1.kt.string((_b = response.description) === null || _b === void 0 ? void 0 : _b.trim()))
|
|
99
|
+
: null,
|
|
100
|
+
ast_1.kt.argument.named('content', ast_1.kt.collectionLiteral((response.contentOptions.length === 0
|
|
101
|
+
? [{ schema: undefined, type: undefined }]
|
|
102
|
+
: response.contentOptions).map((content) => {
|
|
103
|
+
var _a;
|
|
104
|
+
return ast_1.kt.call(ast_1.kt.refs.swagger.content(), [
|
|
105
|
+
content.type ? ast_1.kt.argument.named('mediaType', ast_1.kt.string(content.type)) : null,
|
|
106
|
+
content.schema
|
|
107
|
+
? ast_1.kt.argument.named('schema', ast_1.kt.call(ast_1.kt.refs.swagger.schema(), [
|
|
108
|
+
ast_1.kt.argument.named('implementation', (0, core_1.builderTemplate) `${(_a = this.getSchemaType(ctx, { schema: content.schema })) !== null && _a !== void 0 ? _a : ast_1.kt.refs.any()}::class`),
|
|
109
|
+
]))
|
|
110
|
+
: null,
|
|
111
|
+
]);
|
|
112
|
+
}))),
|
|
113
|
+
]);
|
|
114
|
+
}))),
|
|
115
|
+
]));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
96
118
|
const requestMapping = ast_1.kt.annotation(ast_1.kt.refs.spring.requestMapping(), [
|
|
97
119
|
ast_1.kt.argument.named('method', ast_1.kt.collectionLiteral([ast_1.kt.call([ast_1.kt.refs.spring.requestMethod(), endpoint.method.toUpperCase()])])),
|
|
98
120
|
ast_1.kt.argument.named('value', ast_1.kt.collectionLiteral([ast_1.kt.string(this.getEndpointPath(ctx, { endpoint }))])),
|
|
@@ -100,7 +122,8 @@ class DefaultKotlinSpringControllerGenerator extends file_generator_1.KotlinFile
|
|
|
100
122
|
if (endpoint.requestBody && endpoint.requestBody.content.length > 0) {
|
|
101
123
|
requestMapping.arguments.push(ast_1.kt.argument.named('consumes', ast_1.kt.collectionLiteral((_c = endpoint.requestBody) === null || _c === void 0 ? void 0 : _c.content.map((x) => ast_1.kt.string(x.type)))));
|
|
102
124
|
}
|
|
103
|
-
|
|
125
|
+
annotations.push(requestMapping);
|
|
126
|
+
return annotations;
|
|
104
127
|
}
|
|
105
128
|
getApiInterfaceEndpointMethodParameter(ctx, endpoint, parameter) {
|
|
106
129
|
var _a, _b, _c, _d, _e;
|
|
@@ -4,5 +4,7 @@ export const parameter = ktReference.factory('Parameter', 'io.swagger.v3.oas.ann
|
|
|
4
4
|
export const operation = ktReference.factory('Operation', 'io.swagger.v3.oas.annotations');
|
|
5
5
|
// io.swagger.v3.oas.annotations.media
|
|
6
6
|
export const schema = ktReference.factory('Schema', 'io.swagger.v3.oas.annotations.media');
|
|
7
|
+
export const content = ktReference.factory('Content', 'io.swagger.v3.oas.annotations.media');
|
|
7
8
|
// io.swagger.v3.oas.annotations.responses
|
|
8
9
|
export const apiResponse = ktReference.factory('ApiResponse', 'io.swagger.v3.oas.annotations.responses');
|
|
10
|
+
export const apiResponses = ktReference.factory('ApiResponses', 'io.swagger.v3.oas.annotations.responses');
|
|
@@ -75,19 +75,41 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
|
|
|
75
75
|
}
|
|
76
76
|
getApiInterfaceEndpointMethodAnnnotations(ctx, endpoint) {
|
|
77
77
|
var _a, _b, _c;
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
kt.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
const annotations = [];
|
|
79
|
+
if (ctx.config.addSwaggerAnnotations) {
|
|
80
|
+
annotations.push(kt.annotation(kt.refs.swagger.operation(), [
|
|
81
|
+
endpoint.summary ? kt.argument.named('summary', kt.string((_a = endpoint.summary) === null || _a === void 0 ? void 0 : _a.trim())) : null,
|
|
82
|
+
kt.argument.named('operationId', kt.string(endpoint.name)),
|
|
83
|
+
endpoint.description ? kt.argument.named('description', kt.string((_b = endpoint.description) === null || _b === void 0 ? void 0 : _b.trim())) : null,
|
|
84
|
+
endpoint.deprecated !== undefined ? kt.argument.named('deprecated', kt.toNode(endpoint.deprecated)) : null,
|
|
85
|
+
]));
|
|
86
|
+
if (endpoint.responses.length > 0) {
|
|
87
|
+
annotations.push(kt.annotation(kt.refs.swagger.apiResponses(), [
|
|
88
|
+
kt.argument.named('value', kt.collectionLiteral(endpoint.responses.map((response) => {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
return kt.call(kt.refs.swagger.apiResponse(), [
|
|
91
|
+
kt.argument.named('responseCode', kt.string((_a = response.statusCode) === null || _a === void 0 ? void 0 : _a.toString())),
|
|
92
|
+
response.description
|
|
93
|
+
? kt.argument.named('description', kt.string((_b = response.description) === null || _b === void 0 ? void 0 : _b.trim()))
|
|
94
|
+
: null,
|
|
95
|
+
kt.argument.named('content', kt.collectionLiteral((response.contentOptions.length === 0
|
|
96
|
+
? [{ schema: undefined, type: undefined }]
|
|
97
|
+
: response.contentOptions).map((content) => {
|
|
98
|
+
var _a;
|
|
99
|
+
return kt.call(kt.refs.swagger.content(), [
|
|
100
|
+
content.type ? kt.argument.named('mediaType', kt.string(content.type)) : null,
|
|
101
|
+
content.schema
|
|
102
|
+
? kt.argument.named('schema', kt.call(kt.refs.swagger.schema(), [
|
|
103
|
+
kt.argument.named('implementation', s `${(_a = this.getSchemaType(ctx, { schema: content.schema })) !== null && _a !== void 0 ? _a : kt.refs.any()}::class`),
|
|
104
|
+
]))
|
|
105
|
+
: null,
|
|
106
|
+
]);
|
|
107
|
+
}))),
|
|
108
|
+
]);
|
|
109
|
+
}))),
|
|
110
|
+
]));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
91
113
|
const requestMapping = kt.annotation(kt.refs.spring.requestMapping(), [
|
|
92
114
|
kt.argument.named('method', kt.collectionLiteral([kt.call([kt.refs.spring.requestMethod(), endpoint.method.toUpperCase()])])),
|
|
93
115
|
kt.argument.named('value', kt.collectionLiteral([kt.string(this.getEndpointPath(ctx, { endpoint }))])),
|
|
@@ -95,7 +117,8 @@ export class DefaultKotlinSpringControllerGenerator extends KotlinFileGenerator
|
|
|
95
117
|
if (endpoint.requestBody && endpoint.requestBody.content.length > 0) {
|
|
96
118
|
requestMapping.arguments.push(kt.argument.named('consumes', kt.collectionLiteral((_c = endpoint.requestBody) === null || _c === void 0 ? void 0 : _c.content.map((x) => kt.string(x.type)))));
|
|
97
119
|
}
|
|
98
|
-
|
|
120
|
+
annotations.push(requestMapping);
|
|
121
|
+
return annotations;
|
|
99
122
|
}
|
|
100
123
|
getApiInterfaceEndpointMethodParameter(ctx, endpoint, parameter) {
|
|
101
124
|
var _a, _b, _c, _d, _e;
|
package/package.json
CHANGED
|
@@ -37,6 +37,19 @@ export declare const schema: (<TBuilder extends import("@goast/core").SourceBuil
|
|
|
37
37
|
packageName: import("@goast/core").Nullable<string>;
|
|
38
38
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
39
39
|
};
|
|
40
|
+
export declare const content: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
41
|
+
name: string;
|
|
42
|
+
packageName?: import("@goast/core").Nullable<string>;
|
|
43
|
+
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
44
|
+
nullable?: import("@goast/core").Nullable<boolean>;
|
|
45
|
+
classReference?: import("@goast/core").Nullable<boolean>;
|
|
46
|
+
subReference?: import("@goast/core").Nullable<import("../nodes/reference").KtReference<TBuilder, never> | import("../_index").Call<TBuilder, never>>;
|
|
47
|
+
inject?: import("@goast/core").AstNodeInject<TBuilder, ""> | undefined;
|
|
48
|
+
}, "name" | "packageName">>) => import("../nodes/reference").KtReference<TBuilder, never>) & {
|
|
49
|
+
refName: string;
|
|
50
|
+
packageName: import("@goast/core").Nullable<string>;
|
|
51
|
+
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
52
|
+
};
|
|
40
53
|
export declare const apiResponse: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
41
54
|
name: string;
|
|
42
55
|
packageName?: import("@goast/core").Nullable<string>;
|
|
@@ -50,3 +63,16 @@ export declare const apiResponse: (<TBuilder extends import("@goast/core").Sourc
|
|
|
50
63
|
packageName: import("@goast/core").Nullable<string>;
|
|
51
64
|
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
52
65
|
};
|
|
66
|
+
export declare const apiResponses: (<TBuilder extends import("@goast/core").SourceBuilder>(options?: import("@goast/core").Prettify<Omit<{
|
|
67
|
+
name: string;
|
|
68
|
+
packageName?: import("@goast/core").Nullable<string>;
|
|
69
|
+
generics?: import("@goast/core").Nullable<import("@goast/core").Nullable<import("../_index").Type<TBuilder>>[]>;
|
|
70
|
+
nullable?: import("@goast/core").Nullable<boolean>;
|
|
71
|
+
classReference?: import("@goast/core").Nullable<boolean>;
|
|
72
|
+
subReference?: import("@goast/core").Nullable<import("../nodes/reference").KtReference<TBuilder, never> | import("../_index").Call<TBuilder, never>>;
|
|
73
|
+
inject?: import("@goast/core").AstNodeInject<TBuilder, ""> | undefined;
|
|
74
|
+
}, "name" | "packageName">>) => import("../nodes/reference").KtReference<TBuilder, never>) & {
|
|
75
|
+
refName: string;
|
|
76
|
+
packageName: import("@goast/core").Nullable<string>;
|
|
77
|
+
matches: (value: unknown) => value is import("../nodes/reference").KtReference<never>;
|
|
78
|
+
};
|