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

"Unexpected default value" with JSONZero type

Open jamievlin opened this issue 2 years ago • 4 comments

For build.gradle.kts file:

import net.pwall.json.kotlin.codegen.gradle.JSONSchemaCodegenPlugin
import net.pwall.json.kotlin.codegen.gradle.JSONSchemaCodegen

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("net.pwall.json:json-kotlin-gradle:0.84")
    }
}

apply<JSONSchemaCodegenPlugin>()

val baseGLTFUrl = "https://raw.githubusercontent.com/KhronosGroup/glTF/main/specification/2.0/schema/"

val gltfSchemasNames = arrayOf(
    "glTF"
)

configure<JSONSchemaCodegen> {
    inputs {
        for (gltfSchemaName in gltfSchemasNames) {
            val inputURI = uri("$baseGLTFUrl/$gltfSchemaName.schema.json")
            inputURI(uri(inputURI))
        }
    }
    language.set("kotlin")
}

(schema is here).

Running this, I see processDefaultValue calling

    private fun processDefaultValue(value: JSONValue?): Constraints.DefaultPropertyValue =
            when (value) {
                null -> Constraints.DefaultPropertyValue(null, JSONSchema.Type.NULL)
                is JSONInteger -> Constraints.DefaultPropertyValue(value.value, JSONSchema.Type.INTEGER)
                is JSONString -> Constraints.DefaultPropertyValue(StringValue(value.value), JSONSchema.Type.STRING)
                is JSONBoolean -> Constraints.DefaultPropertyValue(value.value, JSONSchema.Type.BOOLEAN)
                is JSONSequence<*> -> Constraints.DefaultPropertyValue(value.map { processDefaultValue(it) },
                        JSONSchema.Type.ARRAY)
                is JSONMapping<*> -> fatal("Can't handle object as default value")
                else -> fatal("Unexpected default value") // this line is being called
            }

with value type as JSONZero causing the generator to fail. For reference, the schema trying to access is https://raw.githubusercontent.com/KhronosGroup/glTF/main/specification/2.0/schema/accessor.schema.json with location /properties/byteOffset/default

jamievlin avatar Dec 07 '22 19:12 jamievlin

Hi Jamie, that's a bug. Very sorry about that, and thank you for locating it and reporting it.

Expect a new version with a fix for this in the next 24-48 hours.

pwall567 avatar Dec 08 '22 00:12 pwall567

Thanks! :)

jamievlin avatar Dec 08 '22 04:12 jamievlin

OK, version 0.85 has been uploaded a short while ago with a fix for this issue.

Let me know if you continue to have problems.

pwall567 avatar Dec 08 '22 12:12 pwall567

It's fixed now. Thank you so much! :)

jamievlin avatar Dec 08 '22 18:12 jamievlin

I'm closing this issue as resolved. If you think there are still outstanding questions, feel free to reopen it or create a new issue.

pwall567 avatar Jan 31 '23 11:01 pwall567