[RETROFIT2] Field string/binary not work correctly with retrofit2 library.
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the Java retrofit2 generation using the reported string/binary schema and inspect the generated JSON.java file, focusing on the missing ByteArrayAdapter. Compare the output with the related Java issue #4824 and verify that generated byte[] fields can handle the service's Base64 string representation.
Written by the indexing model from the issue text.
Description
Description
I am working in a Java environment. Java projects build the model and the libraries by connection/client type (feign, retrofit2, etc) with Swagger Codegen.
In any case, I have an API Rest service with a file field defined in the following way:
"type": "string",
"format": "byte"
The generated libraries have the corresponding model class with file field type byte[] but the same field in the Rest service class is generated with string type. This generates a casting error because the generated client doesn’t know how to convert a Base64 string to a byte[].
The retrofit2 library generates a JSON.java file with date adapters but ByteArrayAdapter is not added.
Swagger-codegen version
2.4.7
Swagger declaration file content or url
avatar:
type: string
format: binary
Command line used for generation
<profile>
<id>AndroidClientGeneration</id>
<dependencies>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-gson</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-scalars</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${swagger.codegen.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${api-definition}</inputSpec>
<output>${generated-android-client-sources}</output>
<ignoreFileOverride>${ignore-file-override}</ignoreFileOverride>
<language>java</language>
<library>retrofit2</library>
<configOptions>
<apiPackage>${package-client-codegen}.api</apiPackage>
<modelPackage>${package-client-codegen}.model</modelPackage>
<invokerPackage>${package-client-codegen}</invokerPackage>
<licenseName>private</licenseName>
<serializableModel>true</serializableModel>
<useBeanValidation>true</useBeanValidation>
<dateLibrary>threetenbp</dateLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-generated-source</id>
<phase>initialize</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${generated-sources}</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>${android-client-classifier}</classifier>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<includes>
<include>${package-client-sources}</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Related issues/PRs
Similar issue for Java: #4824
Similar issue for C#: #7875
Suggest a fix/enhancement
// Register our new ByterArray type adapter
gsonBuilder.registerTypeAdapter(byte[].class, new ByteArrayAdapter(client));
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from swagger-api/swagger-codegen
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
swagger-api/swagger-codegen#12755 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
Difficulty 1/5 Under an hour Newbie friendliness 62/100
swagger-api/swagger-codegen#11942 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
swagger-api/swagger-codegen#11812 · 1 reaction ·
-
security vulnerability
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
swagger-api/swagger-codegen#11594 ·
All issues in swagger-api/swagger-codegen
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
use-agent-os/agent-os#3276 ·
-
good first issue refactor
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
[6.x]: "Cannot use object of type stdClass as array" loading Users index (regression of #19182) Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
area/sessions comp/agent P2 tool/skills type/perf
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
NousResearch/hermes-agent#117788 ·