json-kotlin-schema-codegen
json-kotlin-schema-codegen copied to clipboard
Invalid code generated for `patternProperties` containing objects
For example:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "foo.schema.json",
"type": "object",
"patternProperties": {
"abc": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
Generated code:
init {
cg_map.keys.forEach { key ->
if (!.matches(key))
throw IllegalArgumentException("Unexpected field $key")
}
}
Compile error:
e: file:///...Foo.kt:18:18 Expecting an element
Running through Gradle plugin v0.102 with "additionalPropertiesOption": "strict" in config.
@pwall567 Any thoughts?
Hi @gino-m , thank you for the bug report. You're testing using version 0.102, so you've obviously seen that there have already been a couple of bug fix releases for this new functionality.
I'm hopeful this will be another quick one; I'll let you know within 24 hours either way.
Thanks, @pwall567! I assume the type in patternProperties will only be checked at run-time, i.e., represented as an Any in generated code? If so I will probably still work around this by using additionalProperties instead, as it generated a strongly typed field.
That's correct @gino-m , patternProperties can be checked only at at run time.
Version 0.103 should fix the problem you identified in this issue, but I agree, it may be preferable to use additionalProperties.