openapi-tools / swagger-maven-plugin

Maven plugin to activate the Swagger Core library to generate OpenAPI documentation.
MIT License
72 stars 46 forks source link

OpenApi documentation converts byte[] in array of byte[] #81

Open andrei-ion opened 3 years ago

andrei-ion commented 3 years ago

Describe the bug I generate a java class from a yaml file describing the model.

I have the following model described in the yaml file:

Document: required:

This generates the following class which is ok:

public class DownloadDocument { @JsonProperty("documentMetaData") private DocumentMetaData documentMetaData;

@JsonProperty("documentContent") private byte[] documentContent;

But when entering the swagger-ui.html page and trying to get the documentation by click on the link:

image

it looks like this:

"DownloadDocument": { "required": [ "documentContent", "documentMetaData" ], "type": "object", "properties": { "documentMetaData": { "$ref": "#/components/schemas/DocumentMetaData" }, "documentContent": { "type": "array", "items": { "type": "string", "format": "byte" } } The document content which is a byte[] is documented as an array of byte[] and when using this description in other app to generate an api client it generates a List<byte[]>.

I would expect the following format also in the OpenApi Specification: "documentContent": { "type": "string", "format": "byte" }**

Can you please advice if this is a bug or if not how can be resolved?

andrei-ion commented 3 years ago

I am using the following versions:

1.5.9 1.5.22 and openapi-generator-maven-plugin 4.3.1
langecode commented 3 years ago

Hi,

Thanks for reaching out here. My guess is that this comes down to the way Swagger handles these kinds of properties so maybe the code generation needs to apply some other annotations to these properties.

But actually I think what you get from clicking the link in the Swagger UI is a runtime rendering rather than something generated by the swagger-maven-plugin? Or do you use the plugin to generate a file to be served at runtime by your Spring application?

andrei-ion commented 3 years ago

Hi, yes the swagger-maven-plugin works as expected and generated the model in the right way:

as

private byte[] documentContent;

but when entering the swagger-ui page and trying to get the api description the field is described as:

"documentContent": { "type": "array", "items": { "type": "string", "format": "byte" } },

And some other apps are using this json definition to generate a client to reach our API. And because the field is wrong described the plugin generates the following model

List<byte[]> documentContent;

which is not what our API is exposing....