Skip to content

Commit 58c23b1

Browse files
committed
fix(kotlin): validate Jackson string lengths
1 parent b10df2f commit 58c23b1

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

packages/quicktype-core/src/language/Kotlin/KotlinJacksonRenderer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { arrayIntercalate, iterableSome } from "collection-utils";
22

33
import {
44
minMaxItemsForType,
5+
minMaxLengthForType,
56
minMaxValueForType,
67
} from "../../attributes/Constraints.js";
78
import type { Name } from "../../Naming.js";
@@ -309,6 +310,15 @@ import com.fasterxml.jackson.module.kotlin.*`);
309310
checks.push(`${numberBefore} >= ${numberMin}${after}`);
310311
if (numberMax !== undefined)
311312
checks.push(`${numberBefore} <= ${numberMax}${after}`);
313+
const [lengthMin, lengthMax] =
314+
minMaxLengthForType(p.type) ?? [];
315+
const lengthBefore = p.isOptional
316+
? `${n}?.let { require(it.length`
317+
: `require(${n}.length`;
318+
if (lengthMin !== undefined)
319+
checks.push(`${lengthBefore} >= ${lengthMin}${after}`);
320+
if (lengthMax !== undefined)
321+
checks.push(`${lengthBefore} <= ${lengthMax}${after}`);
312322
});
313323
if (checks.length > 0)
314324
this.emitBlock("init", () =>

test/languages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,7 @@ export const KotlinJacksonLanguage: Language = {
13271327
"integer",
13281328
"minmaxitems",
13291329
"minmax",
1330+
"minmaxlength",
13301331
],
13311332
output: "TopLevel.kt",
13321333
topLevel: "TopLevel",

0 commit comments

Comments
 (0)