Skip to content

Commit 266073a

Browse files
only convert return_type to Uint8List
1 parent daf9295 commit 266073a

147 files changed

Lines changed: 4950 additions & 31 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,6 @@ 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-
280277
// most of these are defined in AbstractDartCodegen, we are overriding
281278
// just the binary / file handling
282279
languageSpecificPrimitives.add("Object");
@@ -661,6 +658,16 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
661658
}
662659
}
663660

661+
if (SERIALIZATION_LIBRARY_JSON_SERIALIZABLE.equals(library)) {
662+
// built_value serialization uses Uint8List for all MultipartFile types
663+
// in json_serialization, MultipartFile is used as the file parameter type, but
664+
// MultipartFile isn't readable, instead we convert this to a Uin8List
665+
if (op.isResponseFile) {
666+
op.returnType = "Uint8List";
667+
op.returnBaseType = "Uint8List";
668+
}
669+
}
670+
664671
// The MultipartFile handling above changes the type of some parameters from
665672
// `UInt8List`, the default for files, to `MultipartFile`.
666673
//

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,4 @@ public void verifyDartDioGeneratorRuns() throws IOException {
119119
TestUtils.ensureContainsFile(files, output, "README.md");
120120
TestUtils.ensureContainsFile(files, output, "lib/src/api.dart");
121121
}
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-
}
143122
}

modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,33 @@ paths:
311311
description: file to upload
312312
type: string
313313
format: binary
314+
'/pet/{petId}/downloadImage':
315+
post:
316+
tags:
317+
- pet
318+
summary: downloads an image
319+
description: ''
320+
operationId: downloadFile
321+
parameters:
322+
- name: petId
323+
in: path
324+
description: ID of pet to update
325+
required: true
326+
schema:
327+
type: integer
328+
format: int64
329+
responses:
330+
'200':
331+
description: successful operation
332+
content:
333+
application/zip:
334+
schema:
335+
type: string
336+
format: binary
337+
security:
338+
- petstore_auth:
339+
- 'write:pets'
340+
- 'read:pets'
314341
/store/inventory:
315342
get:
316343
tags:

samples/client/petstore/java-helidon-client/v3/mp/docs/PetApi.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
66
|------------- | ------------- | -------------|
77
| [**addPet**](PetApi.md#addPet) | **POST** /pet | Add a new pet to the store |
88
| [**deletePet**](PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet |
9+
| [**downloadFile**](PetApi.md#downloadFile) | **POST** /pet/{petId}/downloadImage | downloads an image |
910
| [**findPetsByStatus**](PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status |
1011
| [**findPetsByTags**](PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags |
1112
| [**getPetById**](PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID |
@@ -89,6 +90,41 @@ Deletes a pet
8990
| **400** | Invalid pet value | - |
9091

9192

93+
## downloadFile
94+
95+
> File downloadFile(petId)
96+
97+
downloads an image
98+
99+
100+
101+
### Parameters
102+
103+
104+
| Name | Type | Description | Notes |
105+
|------------- | ------------- | ------------- | -------------|
106+
| **petId** | **Long**| ID of pet to update | |
107+
108+
### Return type
109+
110+
[**File**](File.md)
111+
112+
### Authorization
113+
114+
[petstore_auth](../README.md#petstore_auth)
115+
116+
### HTTP request headers
117+
118+
- **Content-Type**: Not defined
119+
- **Accept**: application/zip
120+
121+
122+
### HTTP response details
123+
| Status code | Description | Response headers |
124+
|-------------|-------------|------------------|
125+
| **200** | successful operation | - |
126+
127+
92128
## findPetsByStatus
93129

94130
> List&lt;Pet&gt; findPetsByStatus(status)

samples/client/petstore/java-helidon-client/v3/mp/src/main/java/org/openapitools/client/api/PetApi.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ public interface PetApi {
5757
@Path("/pet/{petId}")
5858
void deletePet(@PathParam("petId") Long petId, @HeaderParam("api_key") String apiKey) throws ApiException, ProcessingException;
5959

60+
/**
61+
* downloads an image
62+
*
63+
*/
64+
@POST
65+
@Path("/pet/{petId}/downloadImage")
66+
@Produces({ "application/zip" })
67+
File downloadFile(@PathParam("petId") Long petId) throws ApiException, ProcessingException;
68+
6069
/**
6170
* Finds Pets by status
6271
* Multiple status values can be provided with comma separated strings

samples/client/petstore/java-helidon-client/v3/se/docs/PetApi.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
66
|------------- | ------------- | -------------|
77
| [**addPet**](PetApi.md#addPet) | **POST** /pet | Add a new pet to the store |
88
| [**deletePet**](PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet |
9+
| [**downloadFile**](PetApi.md#downloadFile) | **POST** /pet/{petId}/downloadImage | downloads an image |
910
| [**findPetsByStatus**](PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status |
1011
| [**findPetsByTags**](PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags |
1112
| [**getPetById**](PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID |
@@ -160,6 +161,77 @@ null (empty response body)
160161
| **400** | Invalid pet value | - |
161162

162163

164+
## downloadFile
165+
166+
> File downloadFile(petId)
167+
168+
downloads an image
169+
170+
171+
172+
### Example
173+
174+
```java
175+
// Import classes:
176+
import org.openapitools.client.ApiClient;
177+
import org.openapitools.client.ApiException;
178+
import org.openapitools.client.Configuration;
179+
import org.openapitools.client.auth.*;
180+
import org.openapitools.client.models.*;
181+
import org.openapitools.client.api.PetApi;
182+
183+
public class Example {
184+
public static void main(String[] args) {
185+
ApiClient defaultClient = Configuration.getDefaultApiClient();
186+
defaultClient.setBasePath("http://petstore.swagger.io:80/v2");
187+
188+
// Configure OAuth2 access token for authorization: petstore_auth
189+
OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth");
190+
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
191+
192+
PetApi apiInstance = new PetApi(defaultClient);
193+
Long petId = 56L; // Long | ID of pet to update
194+
try {
195+
File result = apiInstance.downloadFile(petId);
196+
System.out.println(result);
197+
} catch (ApiException e) {
198+
System.err.println("Exception when calling PetApi#downloadFile");
199+
System.err.println("Status code: " + e.getCode());
200+
System.err.println("Reason: " + e.getResponseBody());
201+
System.err.println("Response headers: " + e.getResponseHeaders());
202+
e.printStackTrace();
203+
}
204+
}
205+
}
206+
```
207+
208+
### Parameters
209+
210+
211+
| Name | Type | Description | Notes |
212+
|------------- | ------------- | ------------- | -------------|
213+
| **petId** | **Long**| ID of pet to update | |
214+
215+
### Return type
216+
217+
[**File**](File.md)
218+
219+
### Authorization
220+
221+
[petstore_auth](../README.md#petstore_auth)
222+
223+
### HTTP request headers
224+
225+
- **Content-Type**: Not defined
226+
- **Accept**: application/zip
227+
228+
229+
### HTTP response details
230+
| Status code | Description | Response headers |
231+
|-------------|-------------|------------------|
232+
| **200** | successful operation | - |
233+
234+
163235
## findPetsByStatus
164236

165237
> List&lt;Pet&gt; findPetsByStatus(status)

samples/client/petstore/java-helidon-client/v3/se/src/main/java/org/openapitools/client/api/PetApi.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ public interface PetApi {
4444
*/
4545
ApiResponse<Void> deletePet(Long petId, String apiKey);
4646

47+
/**
48+
* downloads an image
49+
*
50+
* @param petId ID of pet to update (required)
51+
* @return {@code ApiResponse<File>}
52+
*/
53+
ApiResponse<File> downloadFile(Long petId);
54+
4755
/**
4856
* Finds Pets by status
4957
* Multiple status values can be provided with comma separated strings

samples/client/petstore/java-helidon-client/v3/se/src/main/java/org/openapitools/client/api/PetApiImpl.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class PetApiImpl implements PetApi {
5151

5252
protected static final GenericType<Void> RESPONSE_TYPE_addPet = ResponseType.create(Void.class);
5353
protected static final GenericType<Void> RESPONSE_TYPE_deletePet = ResponseType.create(Void.class);
54+
protected static final GenericType<File> RESPONSE_TYPE_downloadFile = ResponseType.create(File.class);
5455
protected static final GenericType<List<Pet>> RESPONSE_TYPE_findPetsByStatus = ResponseType.create(List.class, Pet.class);
5556
protected static final GenericType<List<Pet>> RESPONSE_TYPE_findPetsByTags = ResponseType.create(List.class, Pet.class);
5657
protected static final GenericType<Pet> RESPONSE_TYPE_getPetById = ResponseType.create(Pet.class);
@@ -155,6 +156,45 @@ protected ApiResponse<Void> deletePetSubmit(WebClientRequestBuilder webClientReq
155156
return ApiResponse.create(RESPONSE_TYPE_deletePet, webClientResponse);
156157
}
157158

159+
@Override
160+
public ApiResponse<File> downloadFile(Long petId) {
161+
Objects.requireNonNull(petId, "Required parameter 'petId' not specified");
162+
WebClientRequestBuilder webClientRequestBuilder = downloadFileRequestBuilder(petId);
163+
return downloadFileSubmit(webClientRequestBuilder, petId);
164+
}
165+
166+
/**
167+
* Creates a {@code WebClientRequestBuilder} for the downloadFile operation.
168+
* Optional customization point for subclasses.
169+
*
170+
* @param petId ID of pet to update (required)
171+
* @return WebClientRequestBuilder for downloadFile
172+
*/
173+
protected WebClientRequestBuilder downloadFileRequestBuilder(Long petId) {
174+
WebClientRequestBuilder webClientRequestBuilder = apiClient.webClient()
175+
.method("POST");
176+
177+
String path = "/pet/{petId}/downloadImage"
178+
.replace("{petId}", ApiClient.urlEncode(petId.toString()));
179+
webClientRequestBuilder.path(path);
180+
webClientRequestBuilder.accept(MediaType.APPLICATION_JSON);
181+
182+
return webClientRequestBuilder;
183+
}
184+
185+
/**
186+
* Initiates the request for the downloadFile operation.
187+
* Optional customization point for subclasses.
188+
*
189+
* @param webClientRequestBuilder the request builder to use for submitting the request
190+
* @param petId ID of pet to update (required)
191+
* @return {@code ApiResponse<File>} for the submitted request
192+
*/
193+
protected ApiResponse<File> downloadFileSubmit(WebClientRequestBuilder webClientRequestBuilder, Long petId) {
194+
Single<WebClientResponse> webClientResponse = webClientRequestBuilder.submit();
195+
return ApiResponse.create(RESPONSE_TYPE_downloadFile, webClientResponse);
196+
}
197+
158198
@Override
159199
public ApiResponse<List<Pet>> findPetsByStatus(List<String> status) {
160200
Objects.requireNonNull(status, "Required parameter 'status' not specified");

samples/client/petstore/java-helidon-client/v4/mp/docs/PetApi.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
66
|------------- | ------------- | -------------|
77
| [**addPet**](PetApi.md#addPet) | **POST** /pet | Add a new pet to the store |
88
| [**deletePet**](PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet |
9+
| [**downloadFile**](PetApi.md#downloadFile) | **POST** /pet/{petId}/downloadImage | downloads an image |
910
| [**findPetsByStatus**](PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status |
1011
| [**findPetsByTags**](PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags |
1112
| [**getPetById**](PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID |
@@ -89,6 +90,41 @@ Deletes a pet
8990
| **400** | Invalid pet value | - |
9091

9192

93+
## downloadFile
94+
95+
> File downloadFile(petId)
96+
97+
downloads an image
98+
99+
100+
101+
### Parameters
102+
103+
104+
| Name | Type | Description | Notes |
105+
|------------- | ------------- | ------------- | -------------|
106+
| **petId** | **Long**| ID of pet to update | |
107+
108+
### Return type
109+
110+
[**File**](File.md)
111+
112+
### Authorization
113+
114+
[petstore_auth](../README.md#petstore_auth)
115+
116+
### HTTP request headers
117+
118+
- **Content-Type**: Not defined
119+
- **Accept**: application/zip
120+
121+
122+
### HTTP response details
123+
| Status code | Description | Response headers |
124+
|-------------|-------------|------------------|
125+
| **200** | successful operation | - |
126+
127+
92128
## findPetsByStatus
93129

94130
> List&lt;Pet&gt; findPetsByStatus(status)

samples/client/petstore/java-helidon-client/v4/mp/src/main/java/org/openapitools/client/api/PetApi.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ public interface PetApi {
5858
@Path("/pet/{petId}")
5959
void deletePet(@PathParam("petId") Long petId, @HeaderParam("api_key") String apiKey) throws ApiException, ProcessingException;
6060

61+
/**
62+
* downloads an image
63+
*
64+
*/
65+
@POST
66+
@Path("/pet/{petId}/downloadImage")
67+
@Produces({ "application/zip" })
68+
File downloadFile(@PathParam("petId") Long petId) throws ApiException, ProcessingException;
69+
6170
/**
6271
* Finds Pets by status
6372
* Multiple status values can be provided with comma separated strings

0 commit comments

Comments
 (0)