Open stkleinbaum opened 4 years ago
Not sure, for what its worth, I added your annotations to the KotlinWithDefaultValues
type in the repo:
data class KotlinWithDefaultValues(
val optional: String?,
val required: String,
@JsonSchemaInject(
ints = [
JsonSchemaInt(path = "minLength", value = 3),
JsonSchemaInt(path = "maxLength", value = 10)
]
)
val optionalDefault: String = "Hello",
val optionalDefaultNull: String? = "Hello"
)
...and the schema was as expected:
{
"$schema" : "http://json-schema.org/draft-04/schema#",
"title" : "Kotlin With Default Values",
"type" : "object",
"additionalProperties" : false,
"properties" : {
"optional" : {
"type" : "string"
},
"required" : {
"type" : "string"
},
"optionalDefault" : {
"type" : "string",
"minLength" : 3,
"maxLength" : 10
},
"optionalDefaultNull" : {
"type" : "string"
}
},
"required" : [ "required", "optionalDefault" ]
}
Have you tried the latest version of the library?
Long time since you posted the original issue, but thought this may help others who land here.
Have you tried prepending "@field:JsonSchemaInject"?
@Test
internal fun `json schema from object`() {
val generator = JsonSchemaGenerator(jacksonObjectMapper())
val schema = generator.generateJsonSchema(Example::class.java)
println(schema.toPrettyString())
}
class Example {
/*
* Place it right here
*/
@field:JsonSchemaInject(
ints = [
JsonSchemaInt(path = "minLength", value = 3),
JsonSchemaInt(path = "maxLength", value = 10)
]
)
val aString: String = ""
@Size(min = 3, max = 10)
val aString2: String = ""
}
Kotlin's generates getters and setters under the hood at compile time, so it's better to be explicit with intent or you may not get the results you want.
Hey Morten,
thanks for this great library, but I have troubles to get it working in kotlin.
produces the json schema
but
minLength
andmaxLength
are not set.Do you have an idea?
Best