json-kotlin-schema-codegen icon indicating copy to clipboard operation
json-kotlin-schema-codegen copied to clipboard

Compile error on arrays of objects with `additionalPropertiesOption: strict`

Open gino-m opened this issue 1 year ago • 2 comments

At compile-time we see the following when setting additionalPropertiesOption: strict in the config:

Cannot check for instance of erased type: List<Bar.Foo>

For a schema containing an array of objects:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "bar.schema.json",
  "properties": {
    "foos": {
      "type": "array",
      "items": {
        "id": "foo",
        "type": "object"
      }
    }
  }
}

The offending generated code in Bar.kt:

if (cg_map.containsKey("foos"))
  require(cg_map["foos"] is List<Foo>) { "foos is not the correct type, expecting List<Foo>?" }

This is a blocker for us, since our schema required pattern properties, thus iiuc we need to enable additionalPropertiesOption: strict for the relevant code the generated.

Applying via json-kotlin-gradle plugin 0.102.

@pwall567 Do you have bandwidth to provide a fix? 🙏

gino-m avatar Feb 21 '24 16:02 gino-m

I had already encountered this one, and I was hoping to get a fix out before anyone else ran into it. :smile:

I expect to have a fix for this shortly.

pwall567 avatar Feb 21 '24 23:02 pwall567

And version 0.103 should also fix this problem.

Thank you for your help in identifying these issues. As you have probably seen, there are a large number of combinations to be tested, and while I hope my tests cover most of them, I suspect there are still issues yet to be unearthed.

pwall567 avatar Feb 22 '24 21:02 pwall567