json-kotlin-schema-codegen
json-kotlin-schema-codegen copied to clipboard
"Unexpected default value" with JSONZero type
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
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.
Thanks! :)
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.
It's fixed now. Thank you so much! :)
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.