swagger-api / swagger-api/swagger-codegen

Java Codegen Problem

Open
#10,439 3 comments 0 reactions 1 assignee View on GitHub

@HugoMario is already working on this.

Since Dec 23, 2020.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Wrong/different types in Java/C# for "type" : "string","format" : "binary" declarations

When we define something like this to transfer binary data we could do it like this:

"transferData" : {
"description" : "Any data to be exchanged between callers and callees.",
"type" : "string",
"format" : "base64"
}

The generated code for this is correct for both, C# and Java (both String). – Perfect!

But if we define the following:

"deviceData" : {
"type" : "string",
"format" : "binary"
}

The generated code for C# is correct (public byte[] DeviceData { get; set; }), but for Java a File type is generated (private File deviceData = null;) which is definitely not the intention behind ‘binary’.

3.0.21
The SwaggerHub CodeGen feature for 'java' and 'csharp' were used.
The problematic definition:
      "RequestData" : {
        "description" : "Data to be passed with directive calls.",
        "type" : "object",
        "properties" : {
          "deviceData" : {
            "type" : "string",
            "format" : "binary"
         }        
        }
      }

creates this Java code:

public class RequestData {
  @SerializedName("deviceData")
  private File deviceData = null;

  public RequestData deviceData(File deviceData) {
    this.deviceData = deviceData;
    return this;
  }
...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.