Skip to content

Swagger generates ArraySchema instead of StringSchema for byte array. #3511

@Birthright50

Description

@Birthright50

I use latest swagger 2.1.2, springdoc 1.3.1, spring boot 2.2.6 (MVC stack)
For example, one endpoint from my controller:

    @PostMapping(Routes.Item.External.ITEM_BY_ID_PHOTO)
    public ActionResult<Long> uploadImage(
            @PathVariable("id") @Min(1) long itemId,
            @AuthenticationPrincipal User principal,
            @RequestBody @Validated Base64ImageRequest req
    ) {
        final Long sellerId = principal.getCurrentAgent().isSeller() ? principal.getCurrentSellerId() : null;
        return ActionResult.ok(this.imageService.createImage(itemId, sellerId, req));
    }

Request model Base64ImageRequest:

public class Base64ImageRequest {
    private short order;
    @NotNull
    private byte[] image;
}

An example of a valid request:

{
"order": 5,
"image":  "someBase64Image"
}

It was expected that the generated specification with such a structure for this request:

      "Base64ImageRequest": {
        "required": [
          "image"
        ],
        "type": "object",
        "properties": {
          "order": {
            "type": "integer",
            "format": "int32"
          },
          "image": {
            "type": "string"
          }
        }
      }

But at the output, it turns out that the image field is interpreted as an array of strings.

      "Base64ImageRequest": {
        "required": [
          "image"
        ],
        "type": "object",
        "properties": {
          "order": {
            "type": "integer",
            "format": "int32"
          },
          "image": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "byte"
            }
          }
        }
      }

The problem is here
This line returns for field image io.swagger.v3.oas.models.media.ArraySchema instead of io.swagger.v3.oas.models.media.StringSchema

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions