Add tests for http basic authentication in python client (#16488)

* add tests for http basic auth in python client

* add new files
This commit is contained in:
William Cheng
2023-09-03 19:11:53 +08:00
committed by GitHub
parent b59719a6ea
commit 47a85e880b
41 changed files with 2096 additions and 30 deletions

View File

@@ -5,6 +5,7 @@ README.md
api/openapi.yaml
build.gradle
build.sbt
docs/AuthApi.md
docs/Bird.md
docs/BodyApi.md
docs/Category.md
@@ -39,6 +40,7 @@ src/main/java/org/openapitools/client/RFC3339DateFormat.java
src/main/java/org/openapitools/client/ServerConfiguration.java
src/main/java/org/openapitools/client/ServerVariable.java
src/main/java/org/openapitools/client/StringUtil.java
src/main/java/org/openapitools/client/api/AuthApi.java
src/main/java/org/openapitools/client/api/BodyApi.java
src/main/java/org/openapitools/client/api/FormApi.java
src/main/java/org/openapitools/client/api/HeaderApi.java

View File

@@ -75,20 +75,25 @@ Please follow the [installation](#installation) instruction and execute the foll
import org.openapitools.client.*;
import org.openapitools.client.auth.*;
import org.openapitools.client.model.*;
import org.openapitools.client.api.BodyApi;
import org.openapitools.client.api.AuthApi;
public class BodyApiExample {
public class AuthApiExample {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:3000");
BodyApi apiInstance = new BodyApi(defaultClient);
// Configure HTTP basic authorization: http_auth
HttpBasicAuth http_auth = (HttpBasicAuth) defaultClient.getAuthentication("http_auth");
http_auth.setUsername("YOUR USERNAME");
http_auth.setPassword("YOUR PASSWORD");
AuthApi apiInstance = new AuthApi(defaultClient);
try {
File result = apiInstance.testBinaryGif();
String result = apiInstance.testAuthHttpBasic();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling BodyApi#testBinaryGif");
System.err.println("Exception when calling AuthApi#testAuthHttpBasic");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
@@ -105,6 +110,7 @@ All URIs are relative to *http://localhost:3000*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AuthApi* | [**testAuthHttpBasic**](docs/AuthApi.md#testAuthHttpBasic) | **POST** /auth/http/basic | To test HTTP basic authentication
*BodyApi* | [**testBinaryGif**](docs/BodyApi.md#testBinaryGif) | **POST** /binary/gif | Test binary (gif) response body
*BodyApi* | [**testBodyApplicationOctetstreamBinary**](docs/BodyApi.md#testBodyApplicationOctetstreamBinary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
*BodyApi* | [**testBodyMultipartFormdataArrayOfBinary**](docs/BodyApi.md#testBodyMultipartFormdataArrayOfBinary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
@@ -144,7 +150,13 @@ Class | Method | HTTP request | Description
<a id="documentation-for-authorization"></a>
## Documentation for Authorization
Endpoints do not require authorization.
Authentication schemes defined for the API:
<a id="http_auth"></a>
### http_auth
- **Type**: HTTP basic authentication
## Recommendation

View File

@@ -469,6 +469,23 @@ paths:
- body
x-content-type: multipart/form-data
x-accepts: text/plain
/auth/http/basic:
post:
description: To test HTTP basic authentication
operationId: test/auth/http/basic
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
security:
- http_auth: []
summary: To test HTTP basic authentication
tags:
- auth
x-accepts: text/plain
components:
requestBodies:
Pet:
@@ -729,4 +746,8 @@ components:
required:
- files
type: object
securitySchemes:
http_auth:
scheme: basic
type: http

View File

@@ -0,0 +1,77 @@
# AuthApi
All URIs are relative to *http://localhost:3000*
| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**testAuthHttpBasic**](AuthApi.md#testAuthHttpBasic) | **POST** /auth/http/basic | To test HTTP basic authentication |
## testAuthHttpBasic
> String testAuthHttpBasic()
To test HTTP basic authentication
To test HTTP basic authentication
### 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.AuthApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:3000");
// Configure HTTP basic authorization: http_auth
HttpBasicAuth http_auth = (HttpBasicAuth) defaultClient.getAuthentication("http_auth");
http_auth.setUsername("YOUR USERNAME");
http_auth.setPassword("YOUR PASSWORD");
AuthApi apiInstance = new AuthApi(defaultClient);
try {
String result = apiInstance.testAuthHttpBasic();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AuthApi#testAuthHttpBasic");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```
### Parameters
This endpoint does not need any parameter.
### Return type
**String**
### Authorization
[http_auth](../README.md#http_auth)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |

View File

@@ -76,6 +76,7 @@ import java.net.URI;
import java.text.DateFormat;
import org.openapitools.client.auth.Authentication;
import org.openapitools.client.auth.HttpBasicAuth;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class ApiClient extends JavaTimeFormatter {
@@ -127,6 +128,7 @@ public class ApiClient extends JavaTimeFormatter {
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
authentications.put("http_auth", new HttpBasicAuth());
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
@@ -287,6 +289,36 @@ public class ApiClient extends JavaTimeFormatter {
}
/**
* Helper method to set username for the first HTTP basic authentication.
* @param username Username
* @return API client
*/
public ApiClient setUsername(String username) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setUsername(username);
return this;
}
}
throw new RuntimeException("No HTTP basic authentication configured!");
}
/**
* Helper method to set password for the first HTTP basic authentication.
* @param password Password
* @return API client
*/
public ApiClient setPassword(String password) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setPassword(password);
return this;
}
}
throw new RuntimeException("No HTTP basic authentication configured!");
}

View File

@@ -0,0 +1,120 @@
/*
* Echo Server API
* Echo Server API
*
* The version of the OpenAPI document: 0.1.0
* Contact: team@openapitools.org
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.api;
import com.fasterxml.jackson.core.type.TypeReference;
import org.openapitools.client.ApiException;
import org.openapitools.client.ApiClient;
import org.openapitools.client.Configuration;
import org.openapitools.client.Pair;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class AuthApi {
private ApiClient apiClient;
public AuthApi() {
this(Configuration.getDefaultApiClient());
}
public AuthApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* To test HTTP basic authentication
* To test HTTP basic authentication
* @return String
* @throws ApiException if fails to make API call
*/
public String testAuthHttpBasic() throws ApiException {
return this.testAuthHttpBasic(Collections.emptyMap());
}
/**
* To test HTTP basic authentication
* To test HTTP basic authentication
* @param additionalHeaders additionalHeaders for this call
* @return String
* @throws ApiException if fails to make API call
*/
public String testAuthHttpBasic(Map<String, String> additionalHeaders) throws ApiException {
Object localVarPostBody = null;
// create path and map variables
String localVarPath = "/auth/http/basic";
StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
String localVarQueryParameterBaseName;
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>();
localVarHeaderParams.putAll(additionalHeaders);
final String[] localVarAccepts = {
"text/plain"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
String[] localVarAuthNames = new String[] { "http_auth" };
TypeReference<String> localVarReturnType = new TypeReference<String>() {};
return apiClient.invokeAPI(
localVarPath,
"POST",
localVarQueryParams,
localVarCollectionQueryParams,
localVarQueryStringJoiner.toString(),
localVarPostBody,
localVarHeaderParams,
localVarCookieParams,
localVarFormParams,
localVarAccept,
localVarContentType,
localVarAuthNames,
localVarReturnType
);
}
}

View File

@@ -0,0 +1,50 @@
/*
* Echo Server API
* Echo Server API
*
* The version of the OpenAPI document: 0.1.0
* Contact: team@openapitools.org
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.api;
import org.openapitools.client.ApiException;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Assert;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API tests for AuthApi
*/
@Ignore
public class AuthApiTest {
private final AuthApi api = new AuthApi();
/**
* To test HTTP basic authentication
*
* To test HTTP basic authentication
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void testAuthHttpBasicTest() throws ApiException {
String response = api.testAuthHttpBasic();
// TODO: test validations
}
}

View File

@@ -19,6 +19,7 @@ src/main/java/org/openapitools/client/EncodingUtils.java
src/main/java/org/openapitools/client/ServerConfiguration.java
src/main/java/org/openapitools/client/ServerVariable.java
src/main/java/org/openapitools/client/StringUtil.java
src/main/java/org/openapitools/client/api/AuthApi.java
src/main/java/org/openapitools/client/api/BodyApi.java
src/main/java/org/openapitools/client/api/FormApi.java
src/main/java/org/openapitools/client/api/HeaderApi.java

View File

@@ -469,6 +469,23 @@ paths:
- body
x-content-type: multipart/form-data
x-accepts: text/plain
/auth/http/basic:
post:
description: To test HTTP basic authentication
operationId: test/auth/http/basic
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
security:
- http_auth: []
summary: To test HTTP basic authentication
tags:
- auth
x-accepts: text/plain
components:
requestBodies:
Pet:
@@ -729,4 +746,8 @@ components:
required:
- files
type: object
securitySchemes:
http_auth:
scheme: basic
type: http

View File

@@ -39,7 +39,15 @@ public class ApiClient {
this();
for(String authName : authNames) {
log.log(Level.FINE, "Creating authentication {0}", authName);
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
RequestInterceptor auth = null;
if ("http_auth".equals(authName)) {
auth = new HttpBasicAuth();
} else {
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
}
if (auth != null) {
addAuthorization(authName, auth);
}
}
}

View File

@@ -0,0 +1,42 @@
package org.openapitools.client.api;
import org.openapitools.client.ApiClient;
import org.openapitools.client.EncodingUtils;
import org.openapitools.client.model.ApiResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import feign.*;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public interface AuthApi extends ApiClient.Api {
/**
* To test HTTP basic authentication
* To test HTTP basic authentication
* @return String
*/
@RequestLine("POST /auth/http/basic")
@Headers({
"Accept: text/plain",
})
String testAuthHttpBasic();
/**
* To test HTTP basic authentication
* Similar to <code>testAuthHttpBasic</code> but it also returns the http response headers .
* To test HTTP basic authentication
* @return A ApiResponse that wraps the response boyd and the http headers.
*/
@RequestLine("POST /auth/http/basic")
@Headers({
"Accept: text/plain",
})
ApiResponse<String> testAuthHttpBasicWithHttpInfo();
}

View File

@@ -0,0 +1,40 @@
package org.openapitools.client.api;
import org.openapitools.client.ApiClient;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API tests for AuthApi
*/
class AuthApiTest {
private AuthApi api;
@BeforeEach
public void setup() {
api = new ApiClient().buildClient(AuthApi.class);
}
/**
* To test HTTP basic authentication
*
* To test HTTP basic authentication
*/
@Test
void testAuthHttpBasicTest() {
// String response = api.testAuthHttpBasic();
// TODO: test validations
}
}

View File

@@ -5,6 +5,7 @@ README.md
api/openapi.yaml
build.gradle
build.sbt
docs/AuthApi.md
docs/Bird.md
docs/BodyApi.md
docs/Category.md
@@ -39,6 +40,7 @@ src/main/java/org/openapitools/client/Pair.java
src/main/java/org/openapitools/client/RFC3339DateFormat.java
src/main/java/org/openapitools/client/ServerConfiguration.java
src/main/java/org/openapitools/client/ServerVariable.java
src/main/java/org/openapitools/client/api/AuthApi.java
src/main/java/org/openapitools/client/api/BodyApi.java
src/main/java/org/openapitools/client/api/FormApi.java
src/main/java/org/openapitools/client/api/HeaderApi.java

View File

@@ -74,20 +74,20 @@ Please follow the [installation](#installation) instruction and execute the foll
import org.openapitools.client.*;
import org.openapitools.client.model.*;
import org.openapitools.client.api.BodyApi;
import org.openapitools.client.api.AuthApi;
public class BodyApiExample {
public class AuthApiExample {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure clients using the `defaultClient` object, such as
// overriding the host and port, timeout, etc.
BodyApi apiInstance = new BodyApi(defaultClient);
AuthApi apiInstance = new AuthApi(defaultClient);
try {
File result = apiInstance.testBinaryGif();
String result = apiInstance.testAuthHttpBasic();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling BodyApi#testBinaryGif");
System.err.println("Exception when calling AuthApi#testAuthHttpBasic");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
@@ -104,6 +104,8 @@ All URIs are relative to *http://localhost:3000*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AuthApi* | [**testAuthHttpBasic**](docs/AuthApi.md#testAuthHttpBasic) | **POST** /auth/http/basic | To test HTTP basic authentication
*AuthApi* | [**testAuthHttpBasicWithHttpInfo**](docs/AuthApi.md#testAuthHttpBasicWithHttpInfo) | **POST** /auth/http/basic | To test HTTP basic authentication
*BodyApi* | [**testBinaryGif**](docs/BodyApi.md#testBinaryGif) | **POST** /binary/gif | Test binary (gif) response body
*BodyApi* | [**testBinaryGifWithHttpInfo**](docs/BodyApi.md#testBinaryGifWithHttpInfo) | **POST** /binary/gif | Test binary (gif) response body
*BodyApi* | [**testBodyApplicationOctetstreamBinary**](docs/BodyApi.md#testBodyApplicationOctetstreamBinary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
@@ -162,7 +164,13 @@ Class | Method | HTTP request | Description
<a id="documentation-for-authorization"></a>
## Documentation for Authorization
Endpoints do not require authorization.
Authentication schemes defined for the API:
<a id="http_auth"></a>
### http_auth
- **Type**: HTTP basic authentication
## Recommendation

View File

@@ -469,6 +469,23 @@ paths:
- body
x-content-type: multipart/form-data
x-accepts: text/plain
/auth/http/basic:
post:
description: To test HTTP basic authentication
operationId: test/auth/http/basic
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
security:
- http_auth: []
summary: To test HTTP basic authentication
tags:
- auth
x-accepts: text/plain
components:
requestBodies:
Pet:
@@ -729,4 +746,8 @@ components:
required:
- files
type: object
securitySchemes:
http_auth:
scheme: basic
type: http

View File

@@ -0,0 +1,148 @@
# AuthApi
All URIs are relative to *http://localhost:3000*
| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**testAuthHttpBasic**](AuthApi.md#testAuthHttpBasic) | **POST** /auth/http/basic | To test HTTP basic authentication |
| [**testAuthHttpBasicWithHttpInfo**](AuthApi.md#testAuthHttpBasicWithHttpInfo) | **POST** /auth/http/basic | To test HTTP basic authentication |
## testAuthHttpBasic
> String testAuthHttpBasic()
To test HTTP basic authentication
To test HTTP basic authentication
### 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.AuthApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:3000");
// Configure HTTP basic authorization: http_auth
HttpBasicAuth http_auth = (HttpBasicAuth) defaultClient.getAuthentication("http_auth");
http_auth.setUsername("YOUR USERNAME");
http_auth.setPassword("YOUR PASSWORD");
AuthApi apiInstance = new AuthApi(defaultClient);
try {
String result = apiInstance.testAuthHttpBasic();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AuthApi#testAuthHttpBasic");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```
### Parameters
This endpoint does not need any parameter.
### Return type
**String**
### Authorization
[http_auth](../README.md#http_auth)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |
## testAuthHttpBasicWithHttpInfo
> ApiResponse<String> testAuthHttpBasic testAuthHttpBasicWithHttpInfo()
To test HTTP basic authentication
To test HTTP basic authentication
### Example
```java
// Import classes:
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.ApiResponse;
import org.openapitools.client.Configuration;
import org.openapitools.client.auth.*;
import org.openapitools.client.models.*;
import org.openapitools.client.api.AuthApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:3000");
// Configure HTTP basic authorization: http_auth
HttpBasicAuth http_auth = (HttpBasicAuth) defaultClient.getAuthentication("http_auth");
http_auth.setUsername("YOUR USERNAME");
http_auth.setPassword("YOUR PASSWORD");
AuthApi apiInstance = new AuthApi(defaultClient);
try {
ApiResponse<String> response = apiInstance.testAuthHttpBasicWithHttpInfo();
System.out.println("Status code: " + response.getStatusCode());
System.out.println("Response headers: " + response.getHeaders());
System.out.println("Response body: " + response.getData());
} catch (ApiException e) {
System.err.println("Exception when calling AuthApi#testAuthHttpBasic");
System.err.println("Status code: " + e.getCode());
System.err.println("Response headers: " + e.getResponseHeaders());
System.err.println("Reason: " + e.getResponseBody());
e.printStackTrace();
}
}
}
```
### Parameters
This endpoint does not need any parameter.
### Return type
ApiResponse<**String**>
### Authorization
[http_auth](../README.md#http_auth)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |

View File

@@ -0,0 +1,156 @@
/*
* Echo Server API
* Echo Server API
*
* The version of the OpenAPI document: 0.1.0
* Contact: team@openapitools.org
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.api;
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.ApiResponse;
import org.openapitools.client.Pair;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.http.HttpRequest;
import java.nio.channels.Channels;
import java.nio.channels.Pipe;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.ArrayList;
import java.util.StringJoiner;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class AuthApi {
private final HttpClient memberVarHttpClient;
private final ObjectMapper memberVarObjectMapper;
private final String memberVarBaseUri;
private final Consumer<HttpRequest.Builder> memberVarInterceptor;
private final Duration memberVarReadTimeout;
private final Consumer<HttpResponse<InputStream>> memberVarResponseInterceptor;
private final Consumer<HttpResponse<String>> memberVarAsyncResponseInterceptor;
public AuthApi() {
this(new ApiClient());
}
public AuthApi(ApiClient apiClient) {
memberVarHttpClient = apiClient.getHttpClient();
memberVarObjectMapper = apiClient.getObjectMapper();
memberVarBaseUri = apiClient.getBaseUri();
memberVarInterceptor = apiClient.getRequestInterceptor();
memberVarReadTimeout = apiClient.getReadTimeout();
memberVarResponseInterceptor = apiClient.getResponseInterceptor();
memberVarAsyncResponseInterceptor = apiClient.getAsyncResponseInterceptor();
}
protected ApiException getApiException(String operationId, HttpResponse<InputStream> response) throws IOException {
String body = response.body() == null ? null : new String(response.body().readAllBytes());
String message = formatExceptionMessage(operationId, response.statusCode(), body);
return new ApiException(response.statusCode(), message, response.headers(), body);
}
private String formatExceptionMessage(String operationId, int statusCode, String body) {
if (body == null || body.isEmpty()) {
body = "[no body]";
}
return operationId + " call failed with: " + statusCode + " - " + body;
}
/**
* To test HTTP basic authentication
* To test HTTP basic authentication
* @return String
* @throws ApiException if fails to make API call
*/
public String testAuthHttpBasic() throws ApiException {
ApiResponse<String> localVarResponse = testAuthHttpBasicWithHttpInfo();
return localVarResponse.getData();
}
/**
* To test HTTP basic authentication
* To test HTTP basic authentication
* @return ApiResponse&lt;String&gt;
* @throws ApiException if fails to make API call
*/
public ApiResponse<String> testAuthHttpBasicWithHttpInfo() throws ApiException {
HttpRequest.Builder localVarRequestBuilder = testAuthHttpBasicRequestBuilder();
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("testAuthHttpBasic", localVarResponse);
}
// for plain text response
if (localVarResponse.headers().map().containsKey("Content-Type") &&
"text/plain".equalsIgnoreCase(localVarResponse.headers().map().get("Content-Type").get(0).split(";")[0].trim())) {
java.util.Scanner s = new java.util.Scanner(localVarResponse.body()).useDelimiter("\\A");
String responseBodyText = s.hasNext() ? s.next() : "";
return new ApiResponse<String>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
responseBodyText
);
} else {
throw new RuntimeException("Error! The response Content-Type is supposed to be `text/plain` but it's not: " + localVarResponse);
}
} finally {
}
} catch (IOException e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}
private HttpRequest.Builder testAuthHttpBasicRequestBuilder() throws ApiException {
HttpRequest.Builder localVarRequestBuilder = HttpRequest.newBuilder();
String localVarPath = "/auth/http/basic";
localVarRequestBuilder.uri(URI.create(memberVarBaseUri + localVarPath));
localVarRequestBuilder.header("Accept", "text/plain");
localVarRequestBuilder.method("POST", HttpRequest.BodyPublishers.noBody());
if (memberVarReadTimeout != null) {
localVarRequestBuilder.timeout(memberVarReadTimeout);
}
if (memberVarInterceptor != null) {
memberVarInterceptor.accept(localVarRequestBuilder);
}
return localVarRequestBuilder;
}
}

View File

@@ -0,0 +1,52 @@
/*
* Echo Server API
* Echo Server API
*
* The version of the OpenAPI document: 0.1.0
* Contact: team@openapitools.org
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.api;
import org.openapitools.client.ApiException;
import org.junit.Test;
import org.junit.Ignore;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* API tests for AuthApi
*/
@Ignore
public class AuthApiTest {
private final AuthApi api = new AuthApi();
/**
* To test HTTP basic authentication
*
* To test HTTP basic authentication
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void testAuthHttpBasicTest() throws ApiException {
String response =
api.testAuthHttpBasic();
// TODO: test validations
}
}

View File

@@ -5,6 +5,7 @@ README.md
api/openapi.yaml
build.gradle
build.sbt
docs/AuthApi.md
docs/Bird.md
docs/BodyApi.md
docs/Category.md
@@ -43,6 +44,7 @@ src/main/java/org/openapitools/client/ProgressResponseBody.java
src/main/java/org/openapitools/client/ServerConfiguration.java
src/main/java/org/openapitools/client/ServerVariable.java
src/main/java/org/openapitools/client/StringUtil.java
src/main/java/org/openapitools/client/api/AuthApi.java
src/main/java/org/openapitools/client/api/BodyApi.java
src/main/java/org/openapitools/client/api/FormApi.java
src/main/java/org/openapitools/client/api/HeaderApi.java

View File

@@ -82,20 +82,26 @@ Please follow the [installation](#installation) instruction and execute the foll
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.BodyApi;
import org.openapitools.client.api.AuthApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:3000");
// Configure HTTP basic authorization: http_auth
HttpBasicAuth http_auth = (HttpBasicAuth) defaultClient.getAuthentication("http_auth");
http_auth.setUsername("YOUR USERNAME");
http_auth.setPassword("YOUR PASSWORD");
BodyApi apiInstance = new BodyApi(defaultClient);
AuthApi apiInstance = new AuthApi(defaultClient);
try {
File result = apiInstance.testBinaryGif();
String result = apiInstance.testAuthHttpBasic();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling BodyApi#testBinaryGif");
System.err.println("Exception when calling AuthApi#testAuthHttpBasic");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
@@ -112,6 +118,7 @@ All URIs are relative to *http://localhost:3000*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AuthApi* | [**testAuthHttpBasic**](docs/AuthApi.md#testAuthHttpBasic) | **POST** /auth/http/basic | To test HTTP basic authentication
*BodyApi* | [**testBinaryGif**](docs/BodyApi.md#testBinaryGif) | **POST** /binary/gif | Test binary (gif) response body
*BodyApi* | [**testBodyApplicationOctetstreamBinary**](docs/BodyApi.md#testBodyApplicationOctetstreamBinary) | **POST** /body/application/octetstream/binary | Test body parameter(s)
*BodyApi* | [**testBodyMultipartFormdataArrayOfBinary**](docs/BodyApi.md#testBodyMultipartFormdataArrayOfBinary) | **POST** /body/application/octetstream/array_of_binary | Test array of binary in multipart mime
@@ -151,7 +158,12 @@ Class | Method | HTTP request | Description
<a id="documentation-for-authorization"></a>
## Documentation for Authorization
Endpoints do not require authorization.
Authentication schemes defined for the API:
<a id="http_auth"></a>
### http_auth
- **Type**: HTTP basic authentication
## Recommendation

View File

@@ -469,6 +469,23 @@ paths:
- body
x-content-type: multipart/form-data
x-accepts: text/plain
/auth/http/basic:
post:
description: To test HTTP basic authentication
operationId: test/auth/http/basic
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
security:
- http_auth: []
summary: To test HTTP basic authentication
tags:
- auth
x-accepts: text/plain
components:
requestBodies:
Pet:
@@ -729,4 +746,8 @@ components:
required:
- files
type: object
securitySchemes:
http_auth:
scheme: basic
type: http

View File

@@ -0,0 +1,73 @@
# AuthApi
All URIs are relative to *http://localhost:3000*
| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**testAuthHttpBasic**](AuthApi.md#testAuthHttpBasic) | **POST** /auth/http/basic | To test HTTP basic authentication |
<a id="testAuthHttpBasic"></a>
# **testAuthHttpBasic**
> String testAuthHttpBasic()
To test HTTP basic authentication
To test HTTP basic authentication
### 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.AuthApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:3000");
// Configure HTTP basic authorization: http_auth
HttpBasicAuth http_auth = (HttpBasicAuth) defaultClient.getAuthentication("http_auth");
http_auth.setUsername("YOUR USERNAME");
http_auth.setPassword("YOUR PASSWORD");
AuthApi apiInstance = new AuthApi(defaultClient);
try {
String result = apiInstance.testAuthHttpBasic();
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AuthApi#testAuthHttpBasic");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```
### Parameters
This endpoint does not need any parameter.
### Return type
**String**
### Authorization
[http_auth](../README.md#http_auth)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |

View File

@@ -99,6 +99,7 @@ public class ApiClient {
initHttpClient();
// Setup authentications (key: authentication name, value: authentication).
authentications.put("http_auth", new HttpBasicAuth());
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}
@@ -114,6 +115,7 @@ public class ApiClient {
httpClient = client;
// Setup authentications (key: authentication name, value: authentication).
authentications.put("http_auth", new HttpBasicAuth());
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}

View File

@@ -0,0 +1,187 @@
/*
* Echo Server API
* Echo Server API
*
* The version of the OpenAPI document: 0.1.0
* Contact: team@openapitools.org
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.api;
import org.openapitools.client.ApiCallback;
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.ApiResponse;
import org.openapitools.client.Configuration;
import org.openapitools.client.Pair;
import org.openapitools.client.ProgressRequestBody;
import org.openapitools.client.ProgressResponseBody;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AuthApi {
private ApiClient localVarApiClient;
private int localHostIndex;
private String localCustomBaseUrl;
public AuthApi() {
this(Configuration.getDefaultApiClient());
}
public AuthApi(ApiClient apiClient) {
this.localVarApiClient = apiClient;
}
public ApiClient getApiClient() {
return localVarApiClient;
}
public void setApiClient(ApiClient apiClient) {
this.localVarApiClient = apiClient;
}
public int getHostIndex() {
return localHostIndex;
}
public void setHostIndex(int hostIndex) {
this.localHostIndex = hostIndex;
}
public String getCustomBaseUrl() {
return localCustomBaseUrl;
}
public void setCustomBaseUrl(String customBaseUrl) {
this.localCustomBaseUrl = customBaseUrl;
}
/**
* Build call for testAuthHttpBasic
* @param _callback Callback for upload/download progress
* @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> Successful operation </td><td> - </td></tr>
</table>
*/
public okhttp3.Call testAuthHttpBasicCall(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 = "/auth/http/basic";
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>();
final String[] localVarAccepts = {
"text/plain"
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}
final String[] localVarContentTypes = {
};
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
if (localVarContentType != null) {
localVarHeaderParams.put("Content-Type", localVarContentType);
}
String[] localVarAuthNames = new String[] { "http_auth" };
return localVarApiClient.buildCall(basePath, localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}
@SuppressWarnings("rawtypes")
private okhttp3.Call testAuthHttpBasicValidateBeforeCall(final ApiCallback _callback) throws ApiException {
return testAuthHttpBasicCall(_callback);
}
/**
* To test HTTP basic authentication
* To test HTTP basic authentication
* @return String
* @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> Successful operation </td><td> - </td></tr>
</table>
*/
public String testAuthHttpBasic() throws ApiException {
ApiResponse<String> localVarResp = testAuthHttpBasicWithHttpInfo();
return localVarResp.getData();
}
/**
* To test HTTP basic authentication
* To test HTTP basic authentication
* @return ApiResponse&lt;String&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> Successful operation </td><td> - </td></tr>
</table>
*/
public ApiResponse<String> testAuthHttpBasicWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = testAuthHttpBasicValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<String>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}
/**
* To test HTTP basic authentication (asynchronously)
* To test HTTP basic authentication
* @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> Successful operation </td><td> - </td></tr>
</table>
*/
public okhttp3.Call testAuthHttpBasicAsync(final ApiCallback<String> _callback) throws ApiException {
okhttp3.Call localVarCall = testAuthHttpBasicValidateBeforeCall(_callback);
Type localVarReturnType = new TypeToken<String>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
}

View File

@@ -0,0 +1,46 @@
/*
* Echo Server API
* Echo Server API
*
* The version of the OpenAPI document: 0.1.0
* Contact: team@openapitools.org
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.client.api;
import org.openapitools.client.ApiException;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* API tests for AuthApi
*/
@Disabled
public class AuthApiTest {
private final AuthApi api = new AuthApi();
/**
* To test HTTP basic authentication
*
* To test HTTP basic authentication
*
* @throws ApiException if the Api call fails
*/
@Test
public void testAuthHttpBasicTest() throws ApiException {
String response = api.testAuthHttpBasic();
// TODO: test validations
}
}