@arrirpc/codegen-kotlin 0.58.0 → 0.59.0
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/index.cjs +40 -7
- package/dist/index.mjs +40 -7
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
@@ -102,6 +102,29 @@ function instanceDepth(context) {
|
|
102
102
|
function isNullable(schema, context) {
|
103
103
|
return schema.nullable === true || context.isOptional === true;
|
104
104
|
}
|
105
|
+
function getCodeComment(metadata, prefix, valueField) {
|
106
|
+
if (!metadata?.description && !metadata?.isDeprecated)
|
107
|
+
return "";
|
108
|
+
const descriptionPart = metadata.description?.split("\n").map((line) => `${prefix ?? ""}* ${line}`).join("\n");
|
109
|
+
const finalDescription = metadata.description ? `${prefix ?? ""}/**
|
110
|
+
${descriptionPart}${prefix ?? ""}
|
111
|
+
*/` : "";
|
112
|
+
const deprecationMessage = `@Deprecated(message = "This ${valueField ?? "item"} was marked as deprecated by the server")`;
|
113
|
+
if (metadata.description && metadata.isDeprecated) {
|
114
|
+
return `${finalDescription}
|
115
|
+
${deprecationMessage}
|
116
|
+
`;
|
117
|
+
}
|
118
|
+
if (metadata.isDeprecated) {
|
119
|
+
return `${deprecationMessage}
|
120
|
+
`;
|
121
|
+
}
|
122
|
+
if (metadata.description) {
|
123
|
+
return `${finalDescription}
|
124
|
+
`;
|
125
|
+
}
|
126
|
+
return "";
|
127
|
+
}
|
105
128
|
|
106
129
|
function kotlinAnyFromSchema(schema, context) {
|
107
130
|
const nullable = isNullable(schema, context);
|
@@ -237,7 +260,6 @@ function kotlinObjectFromSchema(schema, context) {
|
|
237
260
|
${input}!!,
|
238
261
|
"$instancePath/${key}",
|
239
262
|
)
|
240
|
-
|
241
263
|
else -> null
|
242
264
|
}`;
|
243
265
|
}
|
@@ -302,7 +324,7 @@ function kotlinObjectFromSchema(schema, context) {
|
|
302
324
|
subContent.push(type.content);
|
303
325
|
}
|
304
326
|
fieldParts.push(
|
305
|
-
|
327
|
+
`${getCodeComment(prop.metadata, " ", "field")} val ${kotlinKey}: ${type.typeName}${type.isNullable ? "?" : ""},`
|
306
328
|
);
|
307
329
|
if (i === 0 && !context.discriminatorKey) {
|
308
330
|
toJsonParts.push(`output += "\\"${key}\\":"`);
|
@@ -339,7 +361,9 @@ function kotlinObjectFromSchema(schema, context) {
|
|
339
361
|
const addCommaPart = isFirst ? "" : `
|
340
362
|
if (hasProperties) output += ","
|
341
363
|
`;
|
342
|
-
fieldParts.push(
|
364
|
+
fieldParts.push(
|
365
|
+
`${getCodeComment(schema.optionalProperties[key].metadata, " ", "field")} val ${kotlinKey}: ${type.typeName}? = null,`
|
366
|
+
);
|
343
367
|
if (hasKnownKeys) {
|
344
368
|
toJsonParts.push(`if (${kotlinKey} != null) {
|
345
369
|
output += ",\\"${key}\\":"
|
@@ -367,7 +391,7 @@ ${isLast ? "" : " hasProperties = true"}
|
|
367
391
|
override val ${kotlinIdentifier(context.discriminatorKey)} get() = "${context.discriminatorValue}"
|
368
392
|
`;
|
369
393
|
}
|
370
|
-
const content =
|
394
|
+
const content = `${getCodeComment(schema.metadata, "", "class")}data class ${className}(
|
371
395
|
${fieldParts.join("\n")}
|
372
396
|
) : ${implementedClass} {${discriminatorField}
|
373
397
|
override fun toJson(): String {
|
@@ -471,7 +495,8 @@ function kotlinDiscriminatorFromSchema(schema, context) {
|
|
471
495
|
if (context.existingTypeIds.includes(className)) {
|
472
496
|
return result;
|
473
497
|
}
|
474
|
-
const
|
498
|
+
const codeComment = getCodeComment(schema.metadata, "", "class");
|
499
|
+
const content = `${codeComment}sealed interface ${className} : ${context.clientName}Model {
|
475
500
|
val ${kotlinDiscriminatorKey}: String
|
476
501
|
|
477
502
|
companion object Factory : ${context.clientName}ModelFactory<${className}> {
|
@@ -1106,8 +1131,16 @@ function kotlinHttpRpcFromSchema(schema, context) {
|
|
1106
1131
|
const name = getProcedureName(context);
|
1107
1132
|
const params = schema.params ? kotlinClassName(`${context.modelPrefix}_${schema.params}`) : void 0;
|
1108
1133
|
const response = schema.response ? kotlinClassName(`${context.modelPrefix}_${schema.response}`) : void 0;
|
1134
|
+
const codeComment = getCodeComment(
|
1135
|
+
{
|
1136
|
+
description: schema.description,
|
1137
|
+
isDeprecated: schema.isDeprecated
|
1138
|
+
},
|
1139
|
+
"",
|
1140
|
+
"method"
|
1141
|
+
);
|
1109
1142
|
if (schema.isEventStream) {
|
1110
|
-
return
|
1143
|
+
return `${codeComment}fun ${name}(
|
1111
1144
|
scope: CoroutineScope,
|
1112
1145
|
${params ? `params: ${params},` : ""}
|
1113
1146
|
lastEventId: String? = null,
|
@@ -1151,7 +1184,7 @@ function kotlinHttpRpcFromSchema(schema, context) {
|
|
1151
1184
|
stack = null,
|
1152
1185
|
)
|
1153
1186
|
}`;
|
1154
|
-
return
|
1187
|
+
return `${codeComment}suspend fun ${name}(${params ? `params: ${params}` : ""}): ${response ?? "Unit"} {
|
1155
1188
|
val response = __prepareRequest(
|
1156
1189
|
client = httpClient,
|
1157
1190
|
url = "$baseUrl${schema.path}",
|
package/dist/index.mjs
CHANGED
@@ -96,6 +96,29 @@ function instanceDepth(context) {
|
|
96
96
|
function isNullable(schema, context) {
|
97
97
|
return schema.nullable === true || context.isOptional === true;
|
98
98
|
}
|
99
|
+
function getCodeComment(metadata, prefix, valueField) {
|
100
|
+
if (!metadata?.description && !metadata?.isDeprecated)
|
101
|
+
return "";
|
102
|
+
const descriptionPart = metadata.description?.split("\n").map((line) => `${prefix ?? ""}* ${line}`).join("\n");
|
103
|
+
const finalDescription = metadata.description ? `${prefix ?? ""}/**
|
104
|
+
${descriptionPart}${prefix ?? ""}
|
105
|
+
*/` : "";
|
106
|
+
const deprecationMessage = `@Deprecated(message = "This ${valueField ?? "item"} was marked as deprecated by the server")`;
|
107
|
+
if (metadata.description && metadata.isDeprecated) {
|
108
|
+
return `${finalDescription}
|
109
|
+
${deprecationMessage}
|
110
|
+
`;
|
111
|
+
}
|
112
|
+
if (metadata.isDeprecated) {
|
113
|
+
return `${deprecationMessage}
|
114
|
+
`;
|
115
|
+
}
|
116
|
+
if (metadata.description) {
|
117
|
+
return `${finalDescription}
|
118
|
+
`;
|
119
|
+
}
|
120
|
+
return "";
|
121
|
+
}
|
99
122
|
|
100
123
|
function kotlinAnyFromSchema(schema, context) {
|
101
124
|
const nullable = isNullable(schema, context);
|
@@ -231,7 +254,6 @@ function kotlinObjectFromSchema(schema, context) {
|
|
231
254
|
${input}!!,
|
232
255
|
"$instancePath/${key}",
|
233
256
|
)
|
234
|
-
|
235
257
|
else -> null
|
236
258
|
}`;
|
237
259
|
}
|
@@ -296,7 +318,7 @@ function kotlinObjectFromSchema(schema, context) {
|
|
296
318
|
subContent.push(type.content);
|
297
319
|
}
|
298
320
|
fieldParts.push(
|
299
|
-
|
321
|
+
`${getCodeComment(prop.metadata, " ", "field")} val ${kotlinKey}: ${type.typeName}${type.isNullable ? "?" : ""},`
|
300
322
|
);
|
301
323
|
if (i === 0 && !context.discriminatorKey) {
|
302
324
|
toJsonParts.push(`output += "\\"${key}\\":"`);
|
@@ -333,7 +355,9 @@ function kotlinObjectFromSchema(schema, context) {
|
|
333
355
|
const addCommaPart = isFirst ? "" : `
|
334
356
|
if (hasProperties) output += ","
|
335
357
|
`;
|
336
|
-
fieldParts.push(
|
358
|
+
fieldParts.push(
|
359
|
+
`${getCodeComment(schema.optionalProperties[key].metadata, " ", "field")} val ${kotlinKey}: ${type.typeName}? = null,`
|
360
|
+
);
|
337
361
|
if (hasKnownKeys) {
|
338
362
|
toJsonParts.push(`if (${kotlinKey} != null) {
|
339
363
|
output += ",\\"${key}\\":"
|
@@ -361,7 +385,7 @@ ${isLast ? "" : " hasProperties = true"}
|
|
361
385
|
override val ${kotlinIdentifier(context.discriminatorKey)} get() = "${context.discriminatorValue}"
|
362
386
|
`;
|
363
387
|
}
|
364
|
-
const content =
|
388
|
+
const content = `${getCodeComment(schema.metadata, "", "class")}data class ${className}(
|
365
389
|
${fieldParts.join("\n")}
|
366
390
|
) : ${implementedClass} {${discriminatorField}
|
367
391
|
override fun toJson(): String {
|
@@ -465,7 +489,8 @@ function kotlinDiscriminatorFromSchema(schema, context) {
|
|
465
489
|
if (context.existingTypeIds.includes(className)) {
|
466
490
|
return result;
|
467
491
|
}
|
468
|
-
const
|
492
|
+
const codeComment = getCodeComment(schema.metadata, "", "class");
|
493
|
+
const content = `${codeComment}sealed interface ${className} : ${context.clientName}Model {
|
469
494
|
val ${kotlinDiscriminatorKey}: String
|
470
495
|
|
471
496
|
companion object Factory : ${context.clientName}ModelFactory<${className}> {
|
@@ -1100,8 +1125,16 @@ function kotlinHttpRpcFromSchema(schema, context) {
|
|
1100
1125
|
const name = getProcedureName(context);
|
1101
1126
|
const params = schema.params ? kotlinClassName(`${context.modelPrefix}_${schema.params}`) : void 0;
|
1102
1127
|
const response = schema.response ? kotlinClassName(`${context.modelPrefix}_${schema.response}`) : void 0;
|
1128
|
+
const codeComment = getCodeComment(
|
1129
|
+
{
|
1130
|
+
description: schema.description,
|
1131
|
+
isDeprecated: schema.isDeprecated
|
1132
|
+
},
|
1133
|
+
"",
|
1134
|
+
"method"
|
1135
|
+
);
|
1103
1136
|
if (schema.isEventStream) {
|
1104
|
-
return
|
1137
|
+
return `${codeComment}fun ${name}(
|
1105
1138
|
scope: CoroutineScope,
|
1106
1139
|
${params ? `params: ${params},` : ""}
|
1107
1140
|
lastEventId: String? = null,
|
@@ -1145,7 +1178,7 @@ function kotlinHttpRpcFromSchema(schema, context) {
|
|
1145
1178
|
stack = null,
|
1146
1179
|
)
|
1147
1180
|
}`;
|
1148
|
-
return
|
1181
|
+
return `${codeComment}suspend fun ${name}(${params ? `params: ${params}` : ""}): ${response ?? "Unit"} {
|
1149
1182
|
val response = __prepareRequest(
|
1150
1183
|
client = httpClient,
|
1151
1184
|
url = "$baseUrl${schema.path}",
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arrirpc/codegen-kotlin",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.59.0",
|
4
4
|
"type": "module",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": {
|
@@ -22,8 +22,8 @@
|
|
22
22
|
"dist"
|
23
23
|
],
|
24
24
|
"dependencies": {
|
25
|
-
"@arrirpc/codegen-utils": "0.
|
26
|
-
"@arrirpc/schema": "0.
|
27
|
-
"json-schema-to-jtd": "0.
|
25
|
+
"@arrirpc/codegen-utils": "0.59.0",
|
26
|
+
"@arrirpc/schema": "0.59.0",
|
27
|
+
"json-schema-to-jtd": "0.59.0"
|
28
28
|
}
|
29
29
|
}
|