Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger - Define Max Size Limit for Multipart File Requests

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:

  • spring.servlet.multipart.max-file-size: 15MB
  • spring.servlet.multipart.max-request-size: 30MB

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

like image 616
Wicaledon Avatar asked Sep 19 '25 23:09

Wicaledon


1 Answers

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)

like image 132
Hamma Fataka Avatar answered Sep 21 '25 15:09

Hamma Fataka