[python-nextgen] Fix binary response (#15076)

* fix binary response in python nextgen client

* update samples
This commit is contained in:
William Cheng
2023-03-31 16:16:58 +08:00
committed by GitHub
parent 05fa5601dd
commit b59d535176
36 changed files with 906 additions and 75 deletions

View File

@@ -17,6 +17,7 @@ import org.openapitools.client.ApiException;
import org.openapitools.client.ApiResponse;
import org.openapitools.client.Pair;
import java.io.File;
import org.openapitools.client.model.Pet;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -81,6 +82,71 @@ public class BodyApi {
return operationId + " call failed with: " + statusCode + " - " + body;
}
/**
* Test binary (gif) response body
* Test binary (gif) response body
* @return File
* @throws ApiException if fails to make API call
*/
public File testBinaryGif() throws ApiException {
ApiResponse<File> localVarResponse = testBinaryGifWithHttpInfo();
return localVarResponse.getData();
}
/**
* Test binary (gif) response body
* Test binary (gif) response body
* @return ApiResponse&lt;File&gt;
* @throws ApiException if fails to make API call
*/
public ApiResponse<File> testBinaryGifWithHttpInfo() throws ApiException {
HttpRequest.Builder localVarRequestBuilder = testBinaryGifRequestBuilder();
try {
HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("testBinaryGif", localVarResponse);
}
return new ApiResponse<File>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<File>() {}) // closes the InputStream
);
} finally {
}
} catch (IOException e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}
private HttpRequest.Builder testBinaryGifRequestBuilder() throws ApiException {
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/binary/gif";
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Accept", "image/gif");
localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.noBody());
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
/**
* Test body parameter(s)
* Test body parameter(s)