cancel
Showing results for 
Search instead for 
Did you mean: 

How to add Properties[] properties in @Schema annotation?

Highlighted
New Contributor

How to add Properties[] properties in @Schema annotation?

Hi.

 

Objective: I want multiple file-select buttons on swagger UI to upload a files as a request parts of a multipart request.

 

The following swagger config would do what I want/need:

 

"requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file_a": {
                    "type": "string",
                    "format": "binary"
                  },
                  "file_b": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }

Question: How can I use @Schema annotation (or any other) to generate such a swagger config?

 

Using annotation, this is as far as I get:

 

@Operation(
            requestBody = @RequestBody(
                    content = @Content(
                            mediaType = MediaType.MULTIPART_FORM_DATA_VALUE,
                            schema = @Schema(
                                    type = "object"
                                    // -> properties[] is missing !!!
                            )
                    ))
    )

@Schema does not seem to provide an means to add an properties[].

 

What am I missing? 😞

 

Thanks,

-Stefan

Tags (2)
2 REPLIES 2
New Contributor

Re: How to add Properties[] properties in @Schema annotation?

I'm pretty sure you could do something along of

@Content(schema = @Schema(implementation = fileaandfileb.class))

 while fileaandfileb has filea and fileb as members

Highlighted
New Contributor

Re: How to add Properties[] properties in @Schema annotation?

Hi. Thanks for the hint. I am aware of this possibility. I would consider this a "workaround" not a real solution.

 

OpenAPI reference https://swagger.io/docs/specification/describing-request-body/ describes the multipart upload as stated in the post above.

 

So I would assume, that the swagger annotation would allow me in some way to declare something that results in a correct openapi JSON ?

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors