javalin / javalin-openapi

Annotation processor for compile-time OpenAPI & JsonSchema, with out-of-the-box support for Javalin 5.x, Swagger & ReDoc
https://github.com/javalin/javalin-openapi/wiki
Apache License 2.0
45 stars 17 forks source link

OpenAPI type validation #204

Closed MathNerd28 closed 6 months ago

MathNerd28 commented 10 months ago

Support for OpenAPI 3.0/3.1 type validation (see here) as annotations rather than custom properties.

Something like this (Java):

@OpenApiNumberValidation(minimum = 1, maximum = 9999)
int count

@OpenApiStringValidation(maxLength = 32, pattern = "[\\w\\s]+")
String name

Would produce this:

"count" : {
    "type" : "integer",
    "format" : "int32",
    "minimum": 1,
    "maximum": 9999
},
"username" : {
    "type" : "string",
    "maxLength": 32,
    "pattern": "[\\w\\s]+"
}
dzikoysk commented 10 months ago

I guess it makes sense. Keep in mind that you can still do that with @Custom:

@Custom("pattern", "[\\w\\s]+")
String name

or even custom annotation:

@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER)
@Retention(RUNTIME)
@CustomAnnotation
annotation class OpenApiNumberValidation(
    val minimum: Int,
    val maximum: Int
)