My use case is programmatically registering additional endpoints that are handled in filters. Similar to how Form Login is handled, you might need custom login endpoints that take different parameters and return different responses from filters.
Right now, the only way to do that (correct me if I'm wrong) is to programmatically build up the schema, e.g.:
Schema<?> schema = new ObjectSchema()
.addProperty(usernamePasswordAuthenticationFilter.getUsernameParameter(), new StringSchema())
.addProperty(usernamePasswordAuthenticationFilter.getPasswordParameter(), new StringSchema())
.required("username", "password");
What I'd like to have is a way to build up the component schema from types reusing built-in functionality. What I've currently landed upon is the following:
// this API does not properly handle nullability
SpringDocAnnotationsUtils.resolveSchemaFromType(
SomeClass::class.java,
it.components,
null,
).required(getRequiredFields(SomeClass::class).toList())
/**
* Note that this method does not respect Jackson's @JsonProperty or Kotlin Serialization's @SerialName
*/
fun <T : Any> getRequiredFields(clazz: KClass<T>): Set<String> = clazz.memberProperties
.filterNot { it.returnType.isMarkedNullable }
.map { it.name }
.toSet()
But of course that piece of code does not work recursively and neither resolves Kotlin serialization annotations nor Jackson ones. From what I've seen so far in the code base, the only way to make this work is to start from controller methods. There is no way to just build up a schema from a type alone.
My use case is programmatically registering additional endpoints that are handled in filters. Similar to how Form Login is handled, you might need custom login endpoints that take different parameters and return different responses from filters.
Right now, the only way to do that (correct me if I'm wrong) is to programmatically build up the schema, e.g.:
What I'd like to have is a way to build up the component schema from types reusing built-in functionality. What I've currently landed upon is the following:
But of course that piece of code does not work recursively and neither resolves Kotlin serialization annotations nor Jackson ones. From what I've seen so far in the code base, the only way to make this work is to start from controller methods. There is no way to just build up a schema from a type alone.