Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,17 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
op.imports.remove("Uint8List");
}

if (SERIALIZATION_LIBRARY_JSON_SERIALIZABLE.equals(library)) {
// built_value serialization uses Uint8List for all MultipartFile types
// in json_serialization, MultipartFile is used as the file parameter type, but
// MultipartFile isn't readable, instead we convert this to a Uin8List
if (op.isResponseFile) {
op.imports.add("Uint8List");
op.returnType = "Uint8List";
op.returnBaseType = "Uint8List";
}
}
Comment on lines +673 to +682
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a previous iteration I implemented the same logic as the built_value serialization method, where both parameter and return types are considered Uint8List

In an effort to keep this change slightly less impactful, I've opted to just change the return type when the response is a file

I'm open to input on this change, whether we want parity with built_value (both parameters and return types are Uint8List) or are ok with what I have here


resultImports.addAll(rewriteImports(op.imports, false));

if (SERIALIZATION_LIBRARY_BUILT_VALUE.equals(library)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
final rawData = _response.data;
_responseData = rawData == null ? null : deserialize<{{{returnType}}}, {{{returnBaseType}}}>(rawData, '{{{returnType}}}', growable: true);
{{#isResponseFile}}
_responseData = rawData == null ? null : rawData as {{{returnType}}};
{{/isResponseFile}}
{{^isResponseFile}}
_responseData = rawData == null ? null : deserialize<{{{returnType}}}, {{{returnBaseType}}}>(rawData, '{{{returnType}}}', growable: true);
{{/isResponseFile}}
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,33 @@ paths:
description: file to upload
type: string
format: binary
'/pet/{petId}/downloadImage':
post:
tags:
- pet
summary: downloads an image
description: ''
operationId: downloadFile
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/zip:
schema:
type: string
format: binary
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
/store/inventory:
get:
tags:
Expand Down
36 changes: 36 additions & 0 deletions samples/client/petstore/java-helidon-client/v3/mp/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
|------------- | ------------- | -------------|
| [**addPet**](PetApi.md#addPet) | **POST** /pet | Add a new pet to the store |
| [**deletePet**](PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet |
| [**downloadFile**](PetApi.md#downloadFile) | **POST** /pet/{petId}/downloadImage | downloads an image |
| [**findPetsByStatus**](PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status |
| [**findPetsByTags**](PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags |
| [**getPetById**](PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID |
Expand Down Expand Up @@ -89,6 +90,41 @@ Deletes a pet
| **400** | Invalid pet value | - |


## downloadFile

> File downloadFile(petId)

downloads an image



### Parameters


| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **petId** | **Long**| ID of pet to update | |

### Return type

[**File**](File.md)

### Authorization

[petstore_auth](../README.md#petstore_auth)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/zip


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | successful operation | - |


## findPetsByStatus

> List&lt;Pet&gt; findPetsByStatus(status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public interface PetApi {
@Path("/pet/{petId}")
void deletePet(@PathParam("petId") Long petId, @HeaderParam("api_key") String apiKey) throws ApiException, ProcessingException;

/**
* downloads an image
*
*/
@POST
@Path("/pet/{petId}/downloadImage")
@Produces({ "application/zip" })
File downloadFile(@PathParam("petId") Long petId) throws ApiException, ProcessingException;

/**
* Finds Pets by status
* Multiple status values can be provided with comma separated strings
Expand Down
72 changes: 72 additions & 0 deletions samples/client/petstore/java-helidon-client/v3/se/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
|------------- | ------------- | -------------|
| [**addPet**](PetApi.md#addPet) | **POST** /pet | Add a new pet to the store |
| [**deletePet**](PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet |
| [**downloadFile**](PetApi.md#downloadFile) | **POST** /pet/{petId}/downloadImage | downloads an image |
| [**findPetsByStatus**](PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status |
| [**findPetsByTags**](PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags |
| [**getPetById**](PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID |
Expand Down Expand Up @@ -160,6 +161,77 @@ null (empty response body)
| **400** | Invalid pet value | - |


## downloadFile

> File downloadFile(petId)

downloads an image



### Example

```java
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.auth.*;
import org.openapitools.client.models.*;
import org.openapitools.client.api.PetApi;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

// Configure OAuth2 access token for authorization: petstore_auth
OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth");
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");

PetApi apiInstance = new PetApi(defaultClient);
Long petId = 56L; // Long | ID of pet to update
try {
File result = apiInstance.downloadFile(petId);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#downloadFile");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```

### Parameters


| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **petId** | **Long**| ID of pet to update | |

### Return type

[**File**](File.md)

### Authorization

[petstore_auth](../README.md#petstore_auth)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/zip


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | successful operation | - |


## findPetsByStatus

> List&lt;Pet&gt; findPetsByStatus(status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public interface PetApi {
*/
ApiResponse<Void> deletePet(Long petId, String apiKey);

/**
* downloads an image
*
* @param petId ID of pet to update (required)
* @return {@code ApiResponse<File>}
*/
ApiResponse<File> downloadFile(Long petId);

/**
* Finds Pets by status
* Multiple status values can be provided with comma separated strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class PetApiImpl implements PetApi {

protected static final GenericType<Void> RESPONSE_TYPE_addPet = ResponseType.create(Void.class);
protected static final GenericType<Void> RESPONSE_TYPE_deletePet = ResponseType.create(Void.class);
protected static final GenericType<File> RESPONSE_TYPE_downloadFile = ResponseType.create(File.class);
protected static final GenericType<List<Pet>> RESPONSE_TYPE_findPetsByStatus = ResponseType.create(List.class, Pet.class);
protected static final GenericType<List<Pet>> RESPONSE_TYPE_findPetsByTags = ResponseType.create(List.class, Pet.class);
protected static final GenericType<Pet> RESPONSE_TYPE_getPetById = ResponseType.create(Pet.class);
Expand Down Expand Up @@ -155,6 +156,45 @@ protected ApiResponse<Void> deletePetSubmit(WebClientRequestBuilder webClientReq
return ApiResponse.create(RESPONSE_TYPE_deletePet, webClientResponse);
}

@Override
public ApiResponse<File> downloadFile(Long petId) {
Objects.requireNonNull(petId, "Required parameter 'petId' not specified");
WebClientRequestBuilder webClientRequestBuilder = downloadFileRequestBuilder(petId);
return downloadFileSubmit(webClientRequestBuilder, petId);
}

/**
* Creates a {@code WebClientRequestBuilder} for the downloadFile operation.
* Optional customization point for subclasses.
*
* @param petId ID of pet to update (required)
* @return WebClientRequestBuilder for downloadFile
*/
protected WebClientRequestBuilder downloadFileRequestBuilder(Long petId) {
WebClientRequestBuilder webClientRequestBuilder = apiClient.webClient()
.method("POST");

String path = "/pet/{petId}/downloadImage"
.replace("{petId}", ApiClient.urlEncode(petId.toString()));
webClientRequestBuilder.path(path);
webClientRequestBuilder.accept(MediaType.APPLICATION_JSON);

return webClientRequestBuilder;
}

/**
* Initiates the request for the downloadFile operation.
* Optional customization point for subclasses.
*
* @param webClientRequestBuilder the request builder to use for submitting the request
* @param petId ID of pet to update (required)
* @return {@code ApiResponse<File>} for the submitted request
*/
protected ApiResponse<File> downloadFileSubmit(WebClientRequestBuilder webClientRequestBuilder, Long petId) {
Single<WebClientResponse> webClientResponse = webClientRequestBuilder.submit();
return ApiResponse.create(RESPONSE_TYPE_downloadFile, webClientResponse);
}

@Override
public ApiResponse<List<Pet>> findPetsByStatus(List<String> status) {
Objects.requireNonNull(status, "Required parameter 'status' not specified");
Expand Down
36 changes: 36 additions & 0 deletions samples/client/petstore/java-helidon-client/v4/mp/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All URIs are relative to *http://petstore.swagger.io:80/v2*
|------------- | ------------- | -------------|
| [**addPet**](PetApi.md#addPet) | **POST** /pet | Add a new pet to the store |
| [**deletePet**](PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet |
| [**downloadFile**](PetApi.md#downloadFile) | **POST** /pet/{petId}/downloadImage | downloads an image |
| [**findPetsByStatus**](PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status |
| [**findPetsByTags**](PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags |
| [**getPetById**](PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID |
Expand Down Expand Up @@ -89,6 +90,41 @@ Deletes a pet
| **400** | Invalid pet value | - |


## downloadFile

> File downloadFile(petId)

downloads an image



### Parameters


| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **petId** | **Long**| ID of pet to update | |

### Return type

[**File**](File.md)

### Authorization

[petstore_auth](../README.md#petstore_auth)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/zip


### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | successful operation | - |


## findPetsByStatus

> List&lt;Pet&gt; findPetsByStatus(status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public interface PetApi {
@Path("/pet/{petId}")
void deletePet(@PathParam("petId") Long petId, @HeaderParam("api_key") String apiKey) throws ApiException, ProcessingException;

/**
* downloads an image
*
*/
@POST
@Path("/pet/{petId}/downloadImage")
@Produces({ "application/zip" })
File downloadFile(@PathParam("petId") Long petId) throws ApiException, ProcessingException;

/**
* Finds Pets by status
* Multiple status values can be provided with comma separated strings
Expand Down
Loading
Loading