[java][okhttp-gson] Add streaming support in group parameters (#12601)

* add streaming support in group paramters

* add tests
This commit is contained in:
William Cheng
2022-06-16 16:20:32 +08:00
committed by GitHub
parent 01fdff0e06
commit 3143390d59
6 changed files with 351 additions and 3 deletions

View File

@@ -472,10 +472,17 @@ public class {{classname}} {
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
{{^vendorExtensions.x-streaming}}
public {{{returnType}}}{{^returnType}}void{{/returnType}} execute() throws ApiException {
{{#returnType}}ApiResponse<{{{.}}}> localVarResp = {{/returnType}}{{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});{{#returnType}}
return localVarResp.getData();{{/returnType}}
}
{{/vendorExtensions.x-streaming}}
{{#vendorExtensions.x-streaming}}
public InputStream execute() throws ApiException {
return {{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
}
{{/vendorExtensions.x-streaming}}
/**
* Execute {{operationId}} request with HTTP info returned
@@ -497,9 +504,16 @@ public class {{classname}} {
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
{{^vendorExtensions.x-streaming}}
public ApiResponse<{{{returnType}}}{{^returnType}}Void{{/returnType}}> executeWithHttpInfo() throws ApiException {
return {{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
}
{{/vendorExtensions.x-streaming}}
{{#vendorExtensions.x-streaming}}
public InputStream executeWithHttpInfo() throws ApiException {
return {{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});
}
{{/vendorExtensions.x-streaming}}
/**
* Execute {{operationId}} request (asynchronously)

View File

@@ -23,6 +23,39 @@ paths:
'application/json':
schema:
$ref: "#/components/schemas/SomeObj"
get:
x-streaming: true
x-group-parameters: true
operationId: getPing
tags:
- ping
parameters:
- name: petId
in: query
description: ID of pet that needs to be updated
required: true
schema:
type: integer
format: int64
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
responses:
'200':
description: OK
content:
'application/json':
schema:
$ref: "#/components/schemas/SomeObj"
components:
schemas:
SomeObj:

View File

@@ -91,12 +91,17 @@ public class Example {
defaultClient.setBasePath("http://localhost:8082");
PingApi apiInstance = new PingApi(defaultClient);
SomeObj someObj = new SomeObj(); // SomeObj |
Long petId = 56L; // Long | ID of pet that needs to be updated
String name = "name_example"; // String | Updated name of the pet
String status = "status_example"; // String | Updated status of the pet
try {
SomeObj result = apiInstance.postPing(someObj);
SomeObj result = apiInstance.getPing(petId)
.name(name)
.status(status)
.execute();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PingApi#postPing");
System.err.println("Exception when calling PingApi#getPing");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
@@ -113,6 +118,7 @@ All URIs are relative to *http://localhost:8082*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*PingApi* | [**getPing**](docs/PingApi.md#getPing) | **GET** /ping |
*PingApi* | [**postPing**](docs/PingApi.md#postPing) | **POST** /ping |

View File

@@ -6,6 +6,36 @@ servers:
- url: http://localhost:8082/
paths:
/ping:
get:
operationId: getPing
parameters:
- description: ID of pet that needs to be updated
explode: true
in: query
name: petId
required: true
schema:
format: int64
type: integer
style: form
requestBody:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/getPing_request'
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/SomeObj'
description: OK
tags:
- ping
x-streaming: true
x-group-parameters: true
x-content-type: application/x-www-form-urlencoded
x-accepts: application/json
post:
operationId: postPing
requestBody:
@@ -50,4 +80,13 @@ components:
type:
type: string
type: object
getPing_request:
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
type: object

View File

@@ -4,9 +4,77 @@ All URIs are relative to *http://localhost:8082*
| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**getPing**](PingApi.md#getPing) | **GET** /ping | |
| [**postPing**](PingApi.md#postPing) | **POST** /ping | |
<a name="getPing"></a>
# **getPing**
> SomeObj getPing(petId).name(name).status(status).execute();
### Example
```java
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.models.*;
import org.openapitools.client.api.PingApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:8082");
PingApi apiInstance = new PingApi(defaultClient);
Long petId = 56L; // Long | ID of pet that needs to be updated
String name = "name_example"; // String | Updated name of the pet
String status = "status_example"; // String | Updated status of the pet
try {
SomeObj result = apiInstance.getPing(petId)
.name(name)
.status(status)
.execute();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PingApi#getPing");
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 that needs to be updated | |
| **name** | **String**| Updated name of the pet | [optional] |
| **status** | **String**| Updated status of the pet | [optional] |
### Return type
[**SomeObj**](SomeObj.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: application/x-www-form-urlencoded
- **Accept**: application/json
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | OK | - |
<a name="postPing"></a>
# **postPing**
> SomeObj postPing(someObj)

View File

@@ -74,6 +74,194 @@ public class PingApi {
this.localCustomBaseUrl = customBaseUrl;
}
private okhttp3.Call getPingCall(Long petId, String name, String status, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };
// Determine Base Path to Use
if (localCustomBaseUrl != null){
basePath = localCustomBaseUrl;
} else if ( localBasePaths.length > 0 ) {
basePath = localBasePaths[localHostIndex];
} else {
basePath = null;
}
Object localVarPostBody = null;
// create path and map variables
String localVarPath = "/ping";
List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
if (name != null) {
localVarFormParams.put("name", name);
}
if (status != null) {
localVarFormParams.put("status", status);
}
if (petId != null) {
localVarQueryParams.addAll(localVarApiClient.parameterToPair("petId", petId));
}
final String[] localVarAccepts = {
"application/json"
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}
final String[] localVarContentTypes = {
"application/x-www-form-urlencoded"
};
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
if (localVarContentType != null) {
localVarHeaderParams.put("Content-Type", localVarContentType);
}
String[] localVarAuthNames = new String[] { };
return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
@SuppressWarnings("rawtypes")
private okhttp3.Call getPingValidateBeforeCall(Long petId, String name, String status, final ApiCallback _callback) throws ApiException {
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException("Missing the required parameter 'petId' when calling getPing(Async)");
}
okhttp3.Call localVarCall = getPingCall(petId, name, status, _callback);
return localVarCall;
}
private InputStream getPingWithHttpInfo(Long petId, String name, String status) throws ApiException {
okhttp3.Call localVarCall = getPingValidateBeforeCall(petId, name, status, null);
Type localVarReturnType = new TypeToken<SomeObj>(){}.getType();
return localVarApiClient.executeStream(localVarCall, localVarReturnType);
}
private okhttp3.Call getPingAsync(Long petId, String name, String status, final ApiCallback<SomeObj> _callback) throws ApiException {
okhttp3.Call localVarCall = getPingValidateBeforeCall(petId, name, status, _callback);
Type localVarReturnType = new TypeToken<SomeObj>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
public class APIgetPingRequest {
private final Long petId;
private String name;
private String status;
private APIgetPingRequest(Long petId) {
this.petId = petId;
}
/**
* Set name
* @param name Updated name of the pet (optional)
* @return APIgetPingRequest
*/
public APIgetPingRequest name(String name) {
this.name = name;
return this;
}
/**
* Set status
* @param status Updated status of the pet (optional)
* @return APIgetPingRequest
*/
public APIgetPingRequest status(String status) {
this.status = status;
return this;
}
/**
* Build call for getPing
* @param _callback ApiCallback API callback
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> OK </td><td> - </td></tr>
</table>
*/
public okhttp3.Call buildCall(final ApiCallback _callback) throws ApiException {
return getPingCall(petId, name, status, _callback);
}
/**
* Execute getPing request
* @return SomeObj
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> OK </td><td> - </td></tr>
</table>
*/
public InputStream execute() throws ApiException {
return getPingWithHttpInfo(petId, name, status);
}
/**
* Execute getPing request with HTTP info returned
* @return ApiResponse&lt;SomeObj&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> OK </td><td> - </td></tr>
</table>
*/
public InputStream executeWithHttpInfo() throws ApiException {
return getPingWithHttpInfo(petId, name, status);
}
/**
* Execute getPing request (asynchronously)
* @param _callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> OK </td><td> - </td></tr>
</table>
*/
public okhttp3.Call executeAsync(final ApiCallback<SomeObj> _callback) throws ApiException {
return getPingAsync(petId, name, status, _callback);
}
}
/**
*
*
* @param petId ID of pet that needs to be updated (required)
* @return APIgetPingRequest
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> OK </td><td> - </td></tr>
</table>
*/
public APIgetPingRequest getPing(Long petId) {
return new APIgetPingRequest(petId);
}
/**
* Build call for postPing
* @param someObj (optional)