[Java][resttemplate] Add test for bearer auth (#17081)

* add bearer auth API to echo-api

* run generate-samples.sh

* add resttemplate echo-api sample

* add bearer auth test

* remove @Ignore
This commit is contained in:
Tomohiko Ozawa
2023-11-16 01:38:49 +09:00
committed by GitHub
parent e47e7041f7
commit 37451fa569
133 changed files with 12443 additions and 0 deletions

View File

@@ -117,6 +117,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
*AuthApi* | [**TestAuthHttpBearer**](docs/AuthApi.md#testauthhttpbearer) | **POST** /auth/http/bearer | To test HTTP bearer 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
@@ -165,3 +166,8 @@ Authentication schemes defined for the API:
- **Type**: HTTP basic authentication
<a id="http_bearer_auth"></a>
### http_bearer_auth
- **Type**: Bearer Authentication

View File

@@ -521,6 +521,22 @@ paths:
summary: To test HTTP basic authentication
tags:
- auth
/auth/http/bearer:
post:
description: To test HTTP bearer authentication
operationId: test/auth/http/bearer
responses:
"200":
content:
text/plain:
schema:
type: string
description: Successful operation
security:
- http_bearer_auth: []
summary: To test HTTP bearer authentication
tags:
- auth
components:
requestBodies:
Pet:
@@ -792,4 +808,7 @@ components:
http_auth:
scheme: basic
type: http
http_bearer_auth:
scheme: bearer
type: http

View File

@@ -5,6 +5,7 @@ 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 |
| [**TestAuthHttpBearer**](AuthApi.md#testauthhttpbearer) | **POST** /auth/http/bearer | To test HTTP bearer authentication |
<a id="testauthhttpbasic"></a>
# **TestAuthHttpBasic**
@@ -96,3 +97,92 @@ This endpoint does not need any parameter.
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
<a id="testauthhttpbearer"></a>
# **TestAuthHttpBearer**
> string TestAuthHttpBearer ()
To test HTTP bearer authentication
To test HTTP bearer authentication
### Example
```csharp
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
namespace Example
{
public class TestAuthHttpBearerExample
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "http://localhost:3000";
// Configure Bearer token for authorization: http_bearer_auth
config.AccessToken = "YOUR_BEARER_TOKEN";
var apiInstance = new AuthApi(config);
try
{
// To test HTTP bearer authentication
string result = apiInstance.TestAuthHttpBearer();
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling AuthApi.TestAuthHttpBearer: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
```
#### Using the TestAuthHttpBearerWithHttpInfo variant
This returns an ApiResponse object which contains the response data, status code and headers.
```csharp
try
{
// To test HTTP bearer authentication
ApiResponse<string> response = apiInstance.TestAuthHttpBearerWithHttpInfo();
Debug.Write("Status Code: " + response.StatusCode);
Debug.Write("Response Headers: " + response.Headers);
Debug.Write("Response Body: " + response.Data);
}
catch (ApiException e)
{
Debug.Print("Exception when calling AuthApi.TestAuthHttpBearerWithHttpInfo: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
```
### Parameters
This endpoint does not need any parameter.
### Return type
**string**
### Authorization
[http_bearer_auth](../README.md#http_bearer_auth)
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

View File

@@ -47,6 +47,27 @@ namespace Org.OpenAPITools.Api
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of string</returns>
ApiResponse<string> TestAuthHttpBasicWithHttpInfo(int operationIndex = 0);
/// <summary>
/// To test HTTP bearer authentication
/// </summary>
/// <remarks>
/// To test HTTP bearer authentication
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>string</returns>
string TestAuthHttpBearer(int operationIndex = 0);
/// <summary>
/// To test HTTP bearer authentication
/// </summary>
/// <remarks>
/// To test HTTP bearer authentication
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of string</returns>
ApiResponse<string> TestAuthHttpBearerWithHttpInfo(int operationIndex = 0);
#endregion Synchronous Operations
}
@@ -79,6 +100,29 @@ namespace Org.OpenAPITools.Api
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse (string)</returns>
System.Threading.Tasks.Task<ApiResponse<string>> TestAuthHttpBasicWithHttpInfoAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <summary>
/// To test HTTP bearer authentication
/// </summary>
/// <remarks>
/// To test HTTP bearer authentication
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of string</returns>
System.Threading.Tasks.Task<string> TestAuthHttpBearerAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <summary>
/// To test HTTP bearer authentication
/// </summary>
/// <remarks>
/// To test HTTP bearer authentication
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse (string)</returns>
System.Threading.Tasks.Task<ApiResponse<string>> TestAuthHttpBearerWithHttpInfoAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
#endregion Asynchronous Operations
}
@@ -337,5 +381,143 @@ namespace Org.OpenAPITools.Api
return localVarResponse;
}
/// <summary>
/// To test HTTP bearer authentication To test HTTP bearer authentication
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>string</returns>
public string TestAuthHttpBearer(int operationIndex = 0)
{
Org.OpenAPITools.Client.ApiResponse<string> localVarResponse = TestAuthHttpBearerWithHttpInfo();
return localVarResponse.Data;
}
/// <summary>
/// To test HTTP bearer authentication To test HTTP bearer authentication
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of string</returns>
public Org.OpenAPITools.Client.ApiResponse<string> TestAuthHttpBearerWithHttpInfo(int operationIndex = 0)
{
Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();
string[] _contentTypes = new string[] {
};
// to determine the Accept header
string[] _accepts = new string[] {
"text/plain"
};
var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
if (localVarContentType != null)
{
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
}
var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts);
if (localVarAccept != null)
{
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
}
localVarRequestOptions.Operation = "AuthApi.TestAuthHttpBearer";
localVarRequestOptions.OperationIndex = operationIndex;
// authentication (http_bearer_auth) required
// bearer authentication required
if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization"))
{
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
}
// make the HTTP request
var localVarResponse = this.Client.Post<string>("/auth/http/bearer", localVarRequestOptions, this.Configuration);
if (this.ExceptionFactory != null)
{
Exception _exception = this.ExceptionFactory("TestAuthHttpBearer", localVarResponse);
if (_exception != null)
{
throw _exception;
}
}
return localVarResponse;
}
/// <summary>
/// To test HTTP bearer authentication To test HTTP bearer authentication
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of string</returns>
public async System.Threading.Tasks.Task<string> TestAuthHttpBearerAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
Org.OpenAPITools.Client.ApiResponse<string> localVarResponse = await TestAuthHttpBearerWithHttpInfoAsync(operationIndex, cancellationToken).ConfigureAwait(false);
return localVarResponse.Data;
}
/// <summary>
/// To test HTTP bearer authentication To test HTTP bearer authentication
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse (string)</returns>
public async System.Threading.Tasks.Task<Org.OpenAPITools.Client.ApiResponse<string>> TestAuthHttpBearerWithHttpInfoAsync(int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();
string[] _contentTypes = new string[] {
};
// to determine the Accept header
string[] _accepts = new string[] {
"text/plain"
};
var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
if (localVarContentType != null)
{
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
}
var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts);
if (localVarAccept != null)
{
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
}
localVarRequestOptions.Operation = "AuthApi.TestAuthHttpBearer";
localVarRequestOptions.OperationIndex = operationIndex;
// authentication (http_bearer_auth) required
// bearer authentication required
if (!string.IsNullOrEmpty(this.Configuration.AccessToken) && !localVarRequestOptions.HeaderParameters.ContainsKey("Authorization"))
{
localVarRequestOptions.HeaderParameters.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
}
// make the HTTP request
var localVarResponse = await this.AsynchronousClient.PostAsync<string>("/auth/http/bearer", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false);
if (this.ExceptionFactory != null)
{
Exception _exception = this.ExceptionFactory("TestAuthHttpBearer", localVarResponse);
if (_exception != null)
{
throw _exception;
}
}
return localVarResponse;
}
}
}