Skip to content

Commit

Permalink
[Java][resttemplate] Add test for bearer auth (OpenAPITools#17081)
Browse files Browse the repository at this point in the history
* add bearer auth API to echo-api

* run generate-samples.sh

* add resttemplate echo-api sample

* add bearer auth test

* remove @ignore
  • Loading branch information
kota65535 authored and lwj5 committed Dec 5, 2023
1 parent a682094 commit 29ea180
Show file tree
Hide file tree
Showing 133 changed files with 12,443 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/samples-java-client-echo-api-jdk11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- samples/client/echo_api/java/apache-httpclient
- samples/client/echo_api/java/native
- samples/client/echo_api/java/feign-gson
- samples/client/echo_api/java/resttemplate
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/samples-java-client-echo-api-jdk8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ on:
- samples/client/echo_api/java/apache-httpclient/**
- samples/client/echo_api/java/feign-gson/**
- samples/client/echo_api/java/okhttp-gson/**
- samples/client/echo_api/java/resttemplate/**
pull_request:
paths:
- samples/client/echo_api/java/apache-httpclient/**
- samples/client/echo_api/java/feign-gson/**
- samples/client/echo_api/java/okhttp-gson/**
- samples/client/echo_api/java/resttemplate/**
jobs:
build:
name: Build Java Client JDK8
Expand All @@ -23,6 +25,7 @@ jobs:
- samples/client/echo_api/java/apache-httpclient
- samples/client/echo_api/java/feign-gson
- samples/client/echo_api/java/okhttp-gson
- samples/client/echo_api/java/resttemplate
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
Expand Down
10 changes: 10 additions & 0 deletions bin/configs/java-resttemplate-echo-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
generatorName: java
outputDir: samples/client/echo_api/java/resttemplate
library: resttemplate
inputSpec: modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
artifactId: echo-api-resttemplate
hideGenerationTimestamp: "true"
java8: true
containerDefaultToNull: true
20 changes: 20 additions & 0 deletions modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,31 @@ paths:
text/plain:
schema:
type: string
# To test http bearer auth
/auth/http/bearer:
post:
tags:
- auth
security:
- http_bearer_auth: []
summary: To test HTTP bearer authentication
description: To test HTTP bearer authentication
operationId: test/auth/http/bearer
responses:
'200':
description: Successful operation
content:
text/plain:
schema:
type: string
components:
securitySchemes:
http_auth:
type: http
scheme: basic
http_bearer_auth:
type: http
scheme: bearer
requestBodies:
Pet:
content:
Expand Down
6 changes: 6 additions & 0 deletions samples/client/echo_api/csharp-restsharp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

19 changes: 19 additions & 0 deletions samples/client/echo_api/csharp-restsharp/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -792,4 +808,7 @@ components:
http_auth:
scheme: basic
type: http
http_bearer_auth:
scheme: bearer
type: http

90 changes: 90 additions & 0 deletions samples/client/echo_api/csharp-restsharp/docs/AuthApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down Expand Up @@ -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)

Loading

0 comments on commit 29ea180

Please sign in to comment.