I have an API created with Spring and I use swagger.yaml
file (I use openapi 3.0.1) to define the resources.
In my application.yaml
I defined the limits for multipart requests such as:
My question is, can I define these same limit infos to swagger ? As I researched, I see maxLength
and minLength
but I guess these are for string limitations
yes you can, have a look at https://docs.swagger.io/swagger-core/v2.0.0-RC3/apidocs/io/swagger/v3/oas/annotations/media/Schema.html
also there is https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schemaObject
that allows you to specify length of the schema in OpenApi 3.X.X
if you are using spring boot just add @Schema(minLength = YOUR_MIN, maxLength = YOUR_MAX)
to your class
this can be applied to the request body class,
and if you want to define specific field length you can do with
jakarta.validation-api by annotating the property by @Size(min= YOUR_MIN, max= YOUR_MAX)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With