Closed uuf6429 closed 4 years ago
I reworked the Type Schema builder system for exactly these cases, so in theory you could have simply added a module defined like this:
object DefaultSetSchemaProvider: SchemaBuilderProviderModule, OpenAPIGenModuleExtension, DefaultOpenAPIModule {
private val builders = listOf(
Builder(getKType<Set<*>?>()) { type: KType ->
type.arguments[0].type ?: error("bad type $type: star projected types are not supported")
}
)
override fun provide(apiGen: OpenAPIGen, provider: ModuleProvider<*>): List<SchemaBuilder> {
return builders
}
private data class Builder(override val superType: KType, private val getter: (KType) -> KType) :
SchemaBuilder {
override fun build(type: KType, builder: FinalSchemaBuilder, finalize: (SchemaModel<*>)->SchemaModel<*>): SchemaModel<*> {
checkType(type)
return finalize(SchemaModel.SchemaModelArr<Any?>(builder.build(getter(type)), type.isMarkedNullable, uniqueItems = true))
}
}
}
But the array model type didn't have the uniqueItems property so it would have been futile. I made the appropriate changes. I also merged the experimental branch, you can get the changes in the last release.
Awesome, that was very fast! Many thanks!
If I have a response class with a
List<SomeEnum>
field, the generated entity looks like:That looks pretty good, but if instead I had
Set<SomeEnum>
, I get:I think the expected schema should have looked like:
In the source code, I saw a few places with
clazz.isSubclassOf(List::class)
, not sure but I'm thinking the fix involves changing those places.