Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Birthright50 opened this issue Apr 10, 2020 · 4 comments
Closed

Comments

@Birthright50
Copy link

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

@webron
Copy link
Contributor

webron commented Apr 20, 2020

If you're using springddoc, you need to file an issue with them. They may use our annotations, but the way they parse the annotations is up to them.

@Birthright50
Copy link
Author

If you're using springddoc, you need to file an issue with them. They may use our annotations, but the way they parse the annotations is up to them.

I don’t really understand what springdoc has to do with it, because the Schema was generated by ModelConverterContextImpl. This class is written by this lib, , and not by the guys from springdoc.

@webron
Copy link
Contributor

webron commented Apr 20, 2020

Normally when other projects use swagger-core, they only rely on swagger-annotations and not our processors (because for the most part it doesn't make sense). If for some reason springdoc does use our processors, we'd ask for an example in a JAX-RS context that reproduces it.

Ideally, you could provide a PR with a failing test that we'd need to fix.

@lscorcia
Copy link

Would issue #3944 be a meaningful repro in a JAX-RS context of this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants