@arrirpc/codegen-kotlin 0.77.1 → 0.79.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 +15 -15
- package/dist/index.mjs +15 -15
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
@@ -100,7 +100,7 @@ function instanceDepth(context) {
|
|
100
100
|
return parts.length - 1;
|
101
101
|
}
|
102
102
|
function isNullable(schema, context) {
|
103
|
-
return schema.
|
103
|
+
return schema.isNullable === true || context.isOptional === true;
|
104
104
|
}
|
105
105
|
function getCodeComment(metadata, prefix, valueField) {
|
106
106
|
if (!metadata?.description && !metadata?.isDeprecated) return "";
|
@@ -140,7 +140,7 @@ function kotlinAnyFromSchema(schema, context) {
|
|
140
140
|
else -> ${input}
|
141
141
|
}`;
|
142
142
|
}
|
143
|
-
if (schema.
|
143
|
+
if (schema.isNullable) {
|
144
144
|
return `when (${input}) {
|
145
145
|
JsonNull -> null
|
146
146
|
null -> null
|
@@ -153,7 +153,7 @@ function kotlinAnyFromSchema(schema, context) {
|
|
153
153
|
}`;
|
154
154
|
},
|
155
155
|
toJson(input, target) {
|
156
|
-
if (schema.
|
156
|
+
if (schema.isNullable) {
|
157
157
|
return `${target} += when (${input}) {
|
158
158
|
null -> "null"
|
159
159
|
else -> JsonInstance.encodeToString(${input})
|
@@ -216,7 +216,7 @@ function kotlinArrayFromSchema(schema, context) {
|
|
216
216
|
}`;
|
217
217
|
},
|
218
218
|
toJson(input, target) {
|
219
|
-
if (schema.
|
219
|
+
if (schema.isNullable) {
|
220
220
|
return `if (${input} == null) {
|
221
221
|
${target} += "null"
|
222
222
|
} else {
|
@@ -276,7 +276,7 @@ function kotlinObjectFromSchema(schema, context) {
|
|
276
276
|
}`;
|
277
277
|
},
|
278
278
|
toJson(input, target) {
|
279
|
-
if (schema.
|
279
|
+
if (schema.isNullable) {
|
280
280
|
return `${target} += ${input}?.toJson()`;
|
281
281
|
}
|
282
282
|
return `${target} += ${input}.toJson()`;
|
@@ -489,7 +489,7 @@ function kotlinDiscriminatorFromSchema(schema, context) {
|
|
489
489
|
}`;
|
490
490
|
},
|
491
491
|
toJson(input, target) {
|
492
|
-
if (schema.
|
492
|
+
if (schema.isNullable) {
|
493
493
|
return `${target} += ${input}?.toJson()`;
|
494
494
|
}
|
495
495
|
return `${target} += ${input}.toJson()`;
|
@@ -617,7 +617,7 @@ function kotlinEnumFromSchema(schema, context) {
|
|
617
617
|
}`;
|
618
618
|
},
|
619
619
|
toJson(input, target) {
|
620
|
-
if (schema.
|
620
|
+
if (schema.isNullable) {
|
621
621
|
return `${target} += when (${input}) {
|
622
622
|
is ${prefixedClassName} -> "\\"\${${input}.serialValue}\\""
|
623
623
|
else -> "null"
|
@@ -631,7 +631,7 @@ function kotlinEnumFromSchema(schema, context) {
|
|
631
631
|
${target}.add("${key}=\${${input}.serialValue}")
|
632
632
|
}`;
|
633
633
|
}
|
634
|
-
if (schema.
|
634
|
+
if (schema.isNullable) {
|
635
635
|
return `${target}.add("${key}=\${${input}?.serialValue}")`;
|
636
636
|
}
|
637
637
|
return `${target}.add("${key}=\${${input}.serialValue}")`;
|
@@ -671,7 +671,7 @@ function kotlinMapFromSchema(schema, context) {
|
|
671
671
|
}`;
|
672
672
|
},
|
673
673
|
toJson(input, target) {
|
674
|
-
if (schema.
|
674
|
+
if (schema.isNullable) {
|
675
675
|
return `if (${input} == null) {
|
676
676
|
${target} += "null"
|
677
677
|
} else {
|
@@ -735,7 +735,7 @@ function kotlinStringFromSchema(schema, context) {
|
|
735
735
|
}`;
|
736
736
|
},
|
737
737
|
toJson(input, target) {
|
738
|
-
if (schema.
|
738
|
+
if (schema.isNullable) {
|
739
739
|
return `${target} += when (${input}) {
|
740
740
|
is String -> buildString { printQuoted(${input}) }
|
741
741
|
else -> "null"
|
@@ -797,7 +797,7 @@ function kotlinTimestampFromSchema(schema, context) {
|
|
797
797
|
}`;
|
798
798
|
},
|
799
799
|
toJson(input, target) {
|
800
|
-
if (schema.
|
800
|
+
if (schema.isNullable) {
|
801
801
|
return `${target} += when (${input}) {
|
802
802
|
is Instant -> "\\"\${timestampFormatter.format(${input})}\\""
|
803
803
|
else -> "null"
|
@@ -815,7 +815,7 @@ function kotlinTimestampFromSchema(schema, context) {
|
|
815
815
|
)
|
816
816
|
}`;
|
817
817
|
}
|
818
|
-
if (schema.
|
818
|
+
if (schema.isNullable) {
|
819
819
|
return `${target}.add(
|
820
820
|
"${key}=\${
|
821
821
|
when (${input}) {
|
@@ -1000,7 +1000,7 @@ function kotlinInt64FromSchema(schema, context) {
|
|
1000
1000
|
}`;
|
1001
1001
|
},
|
1002
1002
|
toJson(input, target) {
|
1003
|
-
if (schema.
|
1003
|
+
if (schema.isNullable) {
|
1004
1004
|
return `${target} += when (${input}) {
|
1005
1005
|
is Long -> "\\"\${${input}}\\""
|
1006
1006
|
else -> "null"
|
@@ -1122,7 +1122,7 @@ function kotlinUint64FromSchema(schema, context) {
|
|
1122
1122
|
}`;
|
1123
1123
|
},
|
1124
1124
|
toJson(input, target) {
|
1125
|
-
if (schema.
|
1125
|
+
if (schema.isNullable) {
|
1126
1126
|
return `${target} += when (${input}) {
|
1127
1127
|
is ULong -> "\\"\${${input}}\\""
|
1128
1128
|
else -> "null"
|
@@ -1304,7 +1304,7 @@ function kotlinRefFromSchema(schema, context) {
|
|
1304
1304
|
}`;
|
1305
1305
|
},
|
1306
1306
|
toJson(input, target) {
|
1307
|
-
if (schema.
|
1307
|
+
if (schema.isNullable) {
|
1308
1308
|
return `${target} += ${input}?.toJson()`;
|
1309
1309
|
}
|
1310
1310
|
return `${target} += ${input}.toJson()`;
|
package/dist/index.mjs
CHANGED
@@ -94,7 +94,7 @@ function instanceDepth(context) {
|
|
94
94
|
return parts.length - 1;
|
95
95
|
}
|
96
96
|
function isNullable(schema, context) {
|
97
|
-
return schema.
|
97
|
+
return schema.isNullable === true || context.isOptional === true;
|
98
98
|
}
|
99
99
|
function getCodeComment(metadata, prefix, valueField) {
|
100
100
|
if (!metadata?.description && !metadata?.isDeprecated) return "";
|
@@ -134,7 +134,7 @@ function kotlinAnyFromSchema(schema, context) {
|
|
134
134
|
else -> ${input}
|
135
135
|
}`;
|
136
136
|
}
|
137
|
-
if (schema.
|
137
|
+
if (schema.isNullable) {
|
138
138
|
return `when (${input}) {
|
139
139
|
JsonNull -> null
|
140
140
|
null -> null
|
@@ -147,7 +147,7 @@ function kotlinAnyFromSchema(schema, context) {
|
|
147
147
|
}`;
|
148
148
|
},
|
149
149
|
toJson(input, target) {
|
150
|
-
if (schema.
|
150
|
+
if (schema.isNullable) {
|
151
151
|
return `${target} += when (${input}) {
|
152
152
|
null -> "null"
|
153
153
|
else -> JsonInstance.encodeToString(${input})
|
@@ -210,7 +210,7 @@ function kotlinArrayFromSchema(schema, context) {
|
|
210
210
|
}`;
|
211
211
|
},
|
212
212
|
toJson(input, target) {
|
213
|
-
if (schema.
|
213
|
+
if (schema.isNullable) {
|
214
214
|
return `if (${input} == null) {
|
215
215
|
${target} += "null"
|
216
216
|
} else {
|
@@ -270,7 +270,7 @@ function kotlinObjectFromSchema(schema, context) {
|
|
270
270
|
}`;
|
271
271
|
},
|
272
272
|
toJson(input, target) {
|
273
|
-
if (schema.
|
273
|
+
if (schema.isNullable) {
|
274
274
|
return `${target} += ${input}?.toJson()`;
|
275
275
|
}
|
276
276
|
return `${target} += ${input}.toJson()`;
|
@@ -483,7 +483,7 @@ function kotlinDiscriminatorFromSchema(schema, context) {
|
|
483
483
|
}`;
|
484
484
|
},
|
485
485
|
toJson(input, target) {
|
486
|
-
if (schema.
|
486
|
+
if (schema.isNullable) {
|
487
487
|
return `${target} += ${input}?.toJson()`;
|
488
488
|
}
|
489
489
|
return `${target} += ${input}.toJson()`;
|
@@ -611,7 +611,7 @@ function kotlinEnumFromSchema(schema, context) {
|
|
611
611
|
}`;
|
612
612
|
},
|
613
613
|
toJson(input, target) {
|
614
|
-
if (schema.
|
614
|
+
if (schema.isNullable) {
|
615
615
|
return `${target} += when (${input}) {
|
616
616
|
is ${prefixedClassName} -> "\\"\${${input}.serialValue}\\""
|
617
617
|
else -> "null"
|
@@ -625,7 +625,7 @@ function kotlinEnumFromSchema(schema, context) {
|
|
625
625
|
${target}.add("${key}=\${${input}.serialValue}")
|
626
626
|
}`;
|
627
627
|
}
|
628
|
-
if (schema.
|
628
|
+
if (schema.isNullable) {
|
629
629
|
return `${target}.add("${key}=\${${input}?.serialValue}")`;
|
630
630
|
}
|
631
631
|
return `${target}.add("${key}=\${${input}.serialValue}")`;
|
@@ -665,7 +665,7 @@ function kotlinMapFromSchema(schema, context) {
|
|
665
665
|
}`;
|
666
666
|
},
|
667
667
|
toJson(input, target) {
|
668
|
-
if (schema.
|
668
|
+
if (schema.isNullable) {
|
669
669
|
return `if (${input} == null) {
|
670
670
|
${target} += "null"
|
671
671
|
} else {
|
@@ -729,7 +729,7 @@ function kotlinStringFromSchema(schema, context) {
|
|
729
729
|
}`;
|
730
730
|
},
|
731
731
|
toJson(input, target) {
|
732
|
-
if (schema.
|
732
|
+
if (schema.isNullable) {
|
733
733
|
return `${target} += when (${input}) {
|
734
734
|
is String -> buildString { printQuoted(${input}) }
|
735
735
|
else -> "null"
|
@@ -791,7 +791,7 @@ function kotlinTimestampFromSchema(schema, context) {
|
|
791
791
|
}`;
|
792
792
|
},
|
793
793
|
toJson(input, target) {
|
794
|
-
if (schema.
|
794
|
+
if (schema.isNullable) {
|
795
795
|
return `${target} += when (${input}) {
|
796
796
|
is Instant -> "\\"\${timestampFormatter.format(${input})}\\""
|
797
797
|
else -> "null"
|
@@ -809,7 +809,7 @@ function kotlinTimestampFromSchema(schema, context) {
|
|
809
809
|
)
|
810
810
|
}`;
|
811
811
|
}
|
812
|
-
if (schema.
|
812
|
+
if (schema.isNullable) {
|
813
813
|
return `${target}.add(
|
814
814
|
"${key}=\${
|
815
815
|
when (${input}) {
|
@@ -994,7 +994,7 @@ function kotlinInt64FromSchema(schema, context) {
|
|
994
994
|
}`;
|
995
995
|
},
|
996
996
|
toJson(input, target) {
|
997
|
-
if (schema.
|
997
|
+
if (schema.isNullable) {
|
998
998
|
return `${target} += when (${input}) {
|
999
999
|
is Long -> "\\"\${${input}}\\""
|
1000
1000
|
else -> "null"
|
@@ -1116,7 +1116,7 @@ function kotlinUint64FromSchema(schema, context) {
|
|
1116
1116
|
}`;
|
1117
1117
|
},
|
1118
1118
|
toJson(input, target) {
|
1119
|
-
if (schema.
|
1119
|
+
if (schema.isNullable) {
|
1120
1120
|
return `${target} += when (${input}) {
|
1121
1121
|
is ULong -> "\\"\${${input}}\\""
|
1122
1122
|
else -> "null"
|
@@ -1298,7 +1298,7 @@ function kotlinRefFromSchema(schema, context) {
|
|
1298
1298
|
}`;
|
1299
1299
|
},
|
1300
1300
|
toJson(input, target) {
|
1301
|
-
if (schema.
|
1301
|
+
if (schema.isNullable) {
|
1302
1302
|
return `${target} += ${input}?.toJson()`;
|
1303
1303
|
}
|
1304
1304
|
return `${target} += ${input}.toJson()`;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arrirpc/codegen-kotlin",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.79.0",
|
4
4
|
"type": "module",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": {
|
@@ -22,6 +22,6 @@
|
|
22
22
|
"dist"
|
23
23
|
],
|
24
24
|
"dependencies": {
|
25
|
-
"@arrirpc/codegen-utils": "0.
|
25
|
+
"@arrirpc/codegen-utils": "0.79.0"
|
26
26
|
}
|
27
27
|
}
|