Skip to content

Commit 8d916d2

Browse files
fixed inconsistencies with the dart-dio json_serializable string binary response types
1 parent b57c23b commit 8d916d2

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartDioClientCodegen.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ private void configureSerializationLibraryJsonSerializable(String srcFolder) {
274274
supportingFiles.add(new SupportingFile("serialization/json_serializable/deserialize.mustache", srcFolder,
275275
"deserialize.dart"));
276276

277+
typeMapping.put("file", "Uint8List");
278+
typeMapping.put("binary", "Uint8List");
279+
277280
// most of these are defined in AbstractDartCodegen, we are overriding
278281
// just the binary / file handling
279282
languageSpecificPrimitives.add("Object");

modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/dio/DartDioClientCodegenTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package org.openapitools.codegen.dart.dio;
1818

19+
import io.swagger.v3.oas.models.media.Content;
20+
import io.swagger.v3.oas.models.media.MediaType;
21+
import io.swagger.v3.oas.models.media.Schema;
22+
import io.swagger.v3.oas.models.responses.ApiResponse;
1923
import org.openapitools.codegen.*;
2024
import org.openapitools.codegen.config.CodegenConfigurator;
2125
import org.openapitools.codegen.languages.DartDioClientCodegen;
@@ -115,4 +119,25 @@ public void verifyDartDioGeneratorRuns() throws IOException {
115119
TestUtils.ensureContainsFile(files, output, "README.md");
116120
TestUtils.ensureContainsFile(files, output, "lib/src/api.dart");
117121
}
122+
123+
@Test(description = "json_serializable with binary response type (#20682)")
124+
public void jsonSerializableBinaryResponseType() throws IOException {
125+
final DefaultCodegen codegen = new DartDioClientCodegen();
126+
codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "json_serializable");
127+
codegen.processOpts();
128+
129+
final MediaType binaryMediaType = new MediaType().schema(new Schema().type("string").format("binary"));
130+
131+
CodegenResponse zipResponse = codegen.fromResponse(
132+
"200",
133+
new ApiResponse().content(new Content().addMediaType("application/zip", binaryMediaType))
134+
);
135+
Assert.assertEquals(zipResponse.dataType, "Uint8List");
136+
137+
CodegenResponse streamResponse = codegen.fromResponse(
138+
"200",
139+
new ApiResponse().content(new Content().addMediaType("application/octet-stream", binaryMediaType))
140+
);
141+
Assert.assertEquals(streamResponse.dataType, "Uint8List");
142+
}
118143
}

0 commit comments

Comments
 (0)