[csharp][generichost] Better handling of duplicate operation ids (#19913)

* fixed missing output

* bug fix

* add new sample

* build samples again

* delete sample

* move the sample and add to github workflow

* remove model not needed for this test

* handle specs with no models

* better handling of duplicate operation ids

* fixed mistake in resolving conflicts

* build samples again

* revert a change sent in another pr
This commit is contained in:
devhl-labs 2024-11-06 03:29:49 -05:00 committed by GitHub
parent f98073d508
commit 54920ff106
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 110 additions and 220 deletions

View File

@ -5701,8 +5701,6 @@ public class DefaultCodegen implements CodegenConfig {
}
}
private final Map<String, Integer> seenOperationIds = new HashMap<String, Integer>();
/**
* Add operation to group
*
@ -5723,18 +5721,13 @@ public class DefaultCodegen implements CodegenConfig {
}
// check for operationId uniqueness
String uniqueName = co.operationId;
int counter = seenOperationIds.getOrDefault(uniqueName, 0);
while (seenOperationIds.containsKey(uniqueName)) {
uniqueName = co.operationId + "_" + counter;
counter++;
}
int counter = 0;
for (CodegenOperation op : opList) {
if (uniqueName.equals(op.operationId)) {
uniqueName = co.operationId + "_" + counter;
counter++;
}
}
seenOperationIds.put(co.operationId, counter);
if (!co.operationId.equals(uniqueName)) {
LOGGER.warn("generated unique operationId `{}`", uniqueName);
}

View File

@ -823,6 +823,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
httpStatusesWithReturn.add(status);
}
}
private HashMap<String, String> duplicateOf = new HashMap<String, String>();
@Override
@SuppressWarnings("unchecked")
@ -842,6 +843,12 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
if (operations != null) {
List<CodegenOperation> ops = operations.getOperation();
for (CodegenOperation operation : ops) {
String duplicates = duplicateOf.get(operation.operationId);
if (duplicates != null) {
operation.vendorExtensions.put("x-duplicates", duplicates);
} else {
duplicateOf.put(operation.operationId, operations.getClassname());
}
if (operation.responses != null) {
for (CodegenResponse response : operation.responses) {

View File

@ -85,6 +85,7 @@ namespace {{packageName}}.{{apiPackage}}
{{/operation}}
}
{{#operation}}
{{^vendorExtensions.x-duplicates}}
{{#responses}}
{{#-first}}
@ -115,6 +116,7 @@ namespace {{packageName}}.{{apiPackage}}
}
{{/-first}}
{{/responses}}
{{/vendorExtensions.x-duplicates}}
{{/operation}}
/// <summary>
@ -134,7 +136,7 @@ namespace {{packageName}}.{{apiPackage}}
/// </summary>
public event EventHandler<ExceptionEventArgs>{{nrt?}} OnError{{operationId}};
internal void ExecuteOn{{operationId}}({{classname}}.{{operationId}}ApiResponse apiResponse)
internal void ExecuteOn{{operationId}}({{#vendorExtensions.x-duplicates}}{{.}}{{/vendorExtensions.x-duplicates}}{{^vendorExtensions.x-duplicates}}{{classname}}{{/vendorExtensions.x-duplicates}}.{{operationId}}ApiResponse apiResponse)
{
On{{operationId}}?.Invoke(this, new ApiResponseEventArgs(apiResponse));
}
@ -619,9 +621,9 @@ namespace {{packageName}}.{{apiPackage}}
{
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync({{#net60OrLater}}cancellationToken{{/net60OrLater}}).ConfigureAwait(false);
ILogger<{{operationId}}ApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<{{operationId}}ApiResponse>();
ILogger<{{#vendorExtensions.x-duplicates}}{{.}}.{{/vendorExtensions.x-duplicates}}{{operationId}}ApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<{{#vendorExtensions.x-duplicates}}{{.}}.{{/vendorExtensions.x-duplicates}}{{operationId}}ApiResponse>();
{{operationId}}ApiResponse apiResponseLocalVar = new{{^net60OrLater}} {{operationId}}ApiResponse{{/net60OrLater}}(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "{{{path}}}", requestedAtLocalVar, _jsonSerializerOptions);
{{#vendorExtensions.x-duplicates}}{{.}}.{{/vendorExtensions.x-duplicates}}{{operationId}}ApiResponse apiResponseLocalVar = new{{^net60OrLater}} {{operationId}}ApiResponse{{/net60OrLater}}(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "{{{path}}}", requestedAtLocalVar, _jsonSerializerOptions);
After{{operationId}}DefaultImplementation({{#lambda.joinWithComma}}apiResponseLocalVar {{#allParams}}{{paramName}} {{/allParams}}{{/lambda.joinWithComma}});
@ -680,6 +682,7 @@ namespace {{packageName}}.{{apiPackage}}
}
{{/lambda.trimLineBreaks}}
}
{{^vendorExtensions.x-duplicates}}
{{#responses}}
{{#-first}}
@ -792,6 +795,7 @@ namespace {{packageName}}.{{apiPackage}}
}
{{/-first}}
{{/responses}}
{{/vendorExtensions.x-duplicates}}
{{/operation}}
}
{{/operations}}

View File

@ -4,11 +4,11 @@ All URIs are relative to *http://app.files.com/api/rest/v1*
| Method | HTTP request | Description |
|--------|--------------|-------------|
| [**GetApiKeysId_1**](APIKEYSApi.md#getapikeysid_1) | **GET** /api_keys/{id} | Show API Key |
| [**GetApiKeysId**](APIKEYSApi.md#getapikeysid) | **GET** /api_keys/{id} | Show API Key |
<a id="getapikeysid_1"></a>
# **GetApiKeysId_1**
> void GetApiKeysId_1 (int id)
<a id="getapikeysid"></a>
# **GetApiKeysId**
> void GetApiKeysId (int id)
Show API Key
@ -24,7 +24,7 @@ using Org.OpenAPITools.Model;
namespace Example
{
public class GetApiKeysId_1Example
public class GetApiKeysIdExample
{
public static void Main()
{
@ -36,11 +36,11 @@ namespace Example
try
{
// Show API Key
apiInstance.GetApiKeysId_1(id);
apiInstance.GetApiKeysId(id);
}
catch (ApiException e)
{
Debug.Print("Exception when calling APIKEYSApi.GetApiKeysId_1: " + e.Message);
Debug.Print("Exception when calling APIKEYSApi.GetApiKeysId: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
@ -49,18 +49,18 @@ namespace Example
}
```
#### Using the GetApiKeysId_1WithHttpInfo variant
#### Using the GetApiKeysIdWithHttpInfo variant
This returns an ApiResponse object which contains the response data, status code and headers.
```csharp
try
{
// Show API Key
apiInstance.GetApiKeysId_1WithHttpInfo(id);
apiInstance.GetApiKeysIdWithHttpInfo(id);
}
catch (ApiException e)
{
Debug.Print("Exception when calling APIKEYSApi.GetApiKeysId_1WithHttpInfo: " + e.Message);
Debug.Print("Exception when calling APIKEYSApi.GetApiKeysIdWithHttpInfo: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}

View File

@ -4,11 +4,11 @@ All URIs are relative to *http://app.files.com/api/rest/v1*
| Method | HTTP request | Description |
|--------|--------------|-------------|
| [**GetApiKeysId_0**](APIKeysApi.md#getapikeysid_0) | **GET** /api_keys/{id} | Show API Key |
| [**GetApiKeysId**](APIKeysApi.md#getapikeysid) | **GET** /api_keys/{id} | Show API Key |
<a id="getapikeysid_0"></a>
# **GetApiKeysId_0**
> void GetApiKeysId_0 (int id)
<a id="getapikeysid"></a>
# **GetApiKeysId**
> void GetApiKeysId (int id)
Show API Key
@ -24,7 +24,7 @@ using Org.OpenAPITools.Model;
namespace Example
{
public class GetApiKeysId_0Example
public class GetApiKeysIdExample
{
public static void Main()
{
@ -36,11 +36,11 @@ namespace Example
try
{
// Show API Key
apiInstance.GetApiKeysId_0(id);
apiInstance.GetApiKeysId(id);
}
catch (ApiException e)
{
Debug.Print("Exception when calling APIKeysApi.GetApiKeysId_0: " + e.Message);
Debug.Print("Exception when calling APIKeysApi.GetApiKeysId: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
@ -49,18 +49,18 @@ namespace Example
}
```
#### Using the GetApiKeysId_0WithHttpInfo variant
#### Using the GetApiKeysIdWithHttpInfo variant
This returns an ApiResponse object which contains the response data, status code and headers.
```csharp
try
{
// Show API Key
apiInstance.GetApiKeysId_0WithHttpInfo(id);
apiInstance.GetApiKeysIdWithHttpInfo(id);
}
catch (ApiException e)
{
Debug.Print("Exception when calling APIKeysApi.GetApiKeysId_0WithHttpInfo: " + e.Message);
Debug.Print("Exception when calling APIKeysApi.GetApiKeysIdWithHttpInfo: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}

View File

@ -51,13 +51,13 @@ namespace Org.OpenAPITools.Test.Api
}
/// <summary>
/// Test GetApiKeysId_1
/// Test GetApiKeysId
/// </summary>
[Fact (Skip = "not implemented")]
public async Task GetApiKeysId_1AsyncTest()
public async Task GetApiKeysIdAsyncTest()
{
int id = default!;
await _instance.GetApiKeysId_1Async(id);
await _instance.GetApiKeysIdAsync(id);
}
}
}

View File

@ -51,13 +51,13 @@ namespace Org.OpenAPITools.Test.Api
}
/// <summary>
/// Test GetApiKeysId_0
/// Test GetApiKeysId
/// </summary>
[Fact (Skip = "not implemented")]
public async Task GetApiKeysId_0AsyncTest()
public async Task GetApiKeysIdAsyncTest()
{
int id = default!;
await _instance.GetApiKeysId_0Async(id);
await _instance.GetApiKeysIdAsync(id);
}
}
}

View File

@ -44,8 +44,8 @@ namespace Org.OpenAPITools.Api
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <param name="id">Api Key ID.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysId_1ApiResponse"/>&gt;</returns>
Task<IGetApiKeysId_1ApiResponse> GetApiKeysId_1Async(int id, System.Threading.CancellationToken cancellationToken = default);
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysIdApiResponse"/>&gt;</returns>
Task<IGetApiKeysIdApiResponse> GetApiKeysIdAsync(int id, System.Threading.CancellationToken cancellationToken = default);
/// <summary>
/// Show API Key
@ -55,14 +55,14 @@ namespace Org.OpenAPITools.Api
/// </remarks>
/// <param name="id">Api Key ID.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysId_1ApiResponse"/>?&gt;</returns>
Task<IGetApiKeysId_1ApiResponse?> GetApiKeysId_1OrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default);
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysIdApiResponse"/>?&gt;</returns>
Task<IGetApiKeysIdApiResponse?> GetApiKeysIdOrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default);
}
/// <summary>
/// The <see cref="IGetApiKeysId_1ApiResponse"/>
/// The <see cref="IGetApiKeysIdApiResponse"/>
/// </summary>
public interface IGetApiKeysId_1ApiResponse : Org.OpenAPITools.Client.IApiResponse
public interface IGetApiKeysIdApiResponse : Org.OpenAPITools.Client.IApiResponse
{
/// <summary>
/// Returns true if the response is 400 BadRequest
@ -79,21 +79,21 @@ namespace Org.OpenAPITools.Api
/// <summary>
/// The event raised after the server response
/// </summary>
public event EventHandler<ApiResponseEventArgs>? OnGetApiKeysId_1;
public event EventHandler<ApiResponseEventArgs>? OnGetApiKeysId;
/// <summary>
/// The event raised after an error querying the server
/// </summary>
public event EventHandler<ExceptionEventArgs>? OnErrorGetApiKeysId_1;
public event EventHandler<ExceptionEventArgs>? OnErrorGetApiKeysId;
internal void ExecuteOnGetApiKeysId_1(APIKEYSApi.GetApiKeysId_1ApiResponse apiResponse)
internal void ExecuteOnGetApiKeysId(APIKEYSApi.GetApiKeysIdApiResponse apiResponse)
{
OnGetApiKeysId_1?.Invoke(this, new ApiResponseEventArgs(apiResponse));
OnGetApiKeysId?.Invoke(this, new ApiResponseEventArgs(apiResponse));
}
internal void ExecuteOnErrorGetApiKeysId_1(Exception exception)
internal void ExecuteOnErrorGetApiKeysId(Exception exception)
{
OnErrorGetApiKeysId_1?.Invoke(this, new ExceptionEventArgs(exception));
OnErrorGetApiKeysId?.Invoke(this, new ExceptionEventArgs(exception));
}
}
@ -144,17 +144,17 @@ namespace Org.OpenAPITools.Api
ApiKeyProvider = apiKeyProvider;
}
partial void FormatGetApiKeysId_1(ref int id);
partial void FormatGetApiKeysId(ref int id);
/// <summary>
/// Processes the server response
/// </summary>
/// <param name="apiResponseLocalVar"></param>
/// <param name="id"></param>
private void AfterGetApiKeysId_1DefaultImplementation(IGetApiKeysId_1ApiResponse apiResponseLocalVar, int id)
private void AfterGetApiKeysIdDefaultImplementation(IGetApiKeysIdApiResponse apiResponseLocalVar, int id)
{
bool suppressDefaultLog = false;
AfterGetApiKeysId_1(ref suppressDefaultLog, apiResponseLocalVar, id);
AfterGetApiKeysId(ref suppressDefaultLog, apiResponseLocalVar, id);
if (!suppressDefaultLog)
Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path);
}
@ -165,7 +165,7 @@ namespace Org.OpenAPITools.Api
/// <param name="suppressDefaultLog"></param>
/// <param name="apiResponseLocalVar"></param>
/// <param name="id"></param>
partial void AfterGetApiKeysId_1(ref bool suppressDefaultLog, IGetApiKeysId_1ApiResponse apiResponseLocalVar, int id);
partial void AfterGetApiKeysId(ref bool suppressDefaultLog, IGetApiKeysIdApiResponse apiResponseLocalVar, int id);
/// <summary>
/// Logs exceptions that occur while retrieving the server response
@ -174,10 +174,10 @@ namespace Org.OpenAPITools.Api
/// <param name="pathFormatLocalVar"></param>
/// <param name="pathLocalVar"></param>
/// <param name="id"></param>
private void OnErrorGetApiKeysId_1DefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, int id)
private void OnErrorGetApiKeysIdDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, int id)
{
bool suppressDefaultLogLocalVar = false;
OnErrorGetApiKeysId_1(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, id);
OnErrorGetApiKeysId(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, id);
if (!suppressDefaultLogLocalVar)
Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server.");
}
@ -190,19 +190,19 @@ namespace Org.OpenAPITools.Api
/// <param name="pathFormatLocalVar"></param>
/// <param name="pathLocalVar"></param>
/// <param name="id"></param>
partial void OnErrorGetApiKeysId_1(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, int id);
partial void OnErrorGetApiKeysId(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, int id);
/// <summary>
/// Show API Key Show API Key
/// </summary>
/// <param name="id">Api Key ID.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysId_1ApiResponse"/>&gt;</returns>
public async Task<IGetApiKeysId_1ApiResponse?> GetApiKeysId_1OrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default)
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysIdApiResponse"/>&gt;</returns>
public async Task<IGetApiKeysIdApiResponse?> GetApiKeysIdOrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default)
{
try
{
return await GetApiKeysId_1Async(id, cancellationToken).ConfigureAwait(false);
return await GetApiKeysIdAsync(id, cancellationToken).ConfigureAwait(false);
}
catch (Exception)
{
@ -216,14 +216,14 @@ namespace Org.OpenAPITools.Api
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <param name="id">Api Key ID.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysId_1ApiResponse"/>&gt;</returns>
public async Task<IGetApiKeysId_1ApiResponse> GetApiKeysId_1Async(int id, System.Threading.CancellationToken cancellationToken = default)
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysIdApiResponse"/>&gt;</returns>
public async Task<IGetApiKeysIdApiResponse> GetApiKeysIdAsync(int id, System.Threading.CancellationToken cancellationToken = default)
{
UriBuilder uriBuilderLocalVar = new UriBuilder();
try
{
FormatGetApiKeysId_1(ref id);
FormatGetApiKeysId(ref id);
using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage())
{
@ -243,13 +243,13 @@ namespace Org.OpenAPITools.Api
{
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
ILogger<GetApiKeysId_1ApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<GetApiKeysId_1ApiResponse>();
ILogger<GetApiKeysIdApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<GetApiKeysIdApiResponse>();
GetApiKeysId_1ApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
GetApiKeysIdApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
AfterGetApiKeysId_1DefaultImplementation(apiResponseLocalVar, id);
AfterGetApiKeysIdDefaultImplementation(apiResponseLocalVar, id);
Events.ExecuteOnGetApiKeysId_1(apiResponseLocalVar);
Events.ExecuteOnGetApiKeysId(apiResponseLocalVar);
return apiResponseLocalVar;
}
@ -257,24 +257,24 @@ namespace Org.OpenAPITools.Api
}
catch(Exception e)
{
OnErrorGetApiKeysId_1DefaultImplementation(e, "/api_keys/{id}", uriBuilderLocalVar.Path, id);
Events.ExecuteOnErrorGetApiKeysId_1(e);
OnErrorGetApiKeysIdDefaultImplementation(e, "/api_keys/{id}", uriBuilderLocalVar.Path, id);
Events.ExecuteOnErrorGetApiKeysId(e);
throw;
}
}
/// <summary>
/// The <see cref="GetApiKeysId_1ApiResponse"/>
/// The <see cref="GetApiKeysIdApiResponse"/>
/// </summary>
public partial class GetApiKeysId_1ApiResponse : Org.OpenAPITools.Client.ApiResponse, IGetApiKeysId_1ApiResponse
public partial class GetApiKeysIdApiResponse : Org.OpenAPITools.Client.ApiResponse, IGetApiKeysIdApiResponse
{
/// <summary>
/// The logger
/// </summary>
public ILogger<GetApiKeysId_1ApiResponse> Logger { get; }
public ILogger<GetApiKeysIdApiResponse> Logger { get; }
/// <summary>
/// The <see cref="GetApiKeysId_1ApiResponse"/>
/// The <see cref="GetApiKeysIdApiResponse"/>
/// </summary>
/// <param name="logger"></param>
/// <param name="httpRequestMessage"></param>
@ -283,7 +283,7 @@ namespace Org.OpenAPITools.Api
/// <param name="path"></param>
/// <param name="requestedAt"></param>
/// <param name="jsonSerializerOptions"></param>
public GetApiKeysId_1ApiResponse(ILogger<GetApiKeysId_1ApiResponse> logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions)
public GetApiKeysIdApiResponse(ILogger<GetApiKeysIdApiResponse> logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions)
{
Logger = logger;
OnCreated(httpRequestMessage, httpResponseMessage);

View File

@ -44,8 +44,8 @@ namespace Org.OpenAPITools.Api
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <param name="id">Api Key ID.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysId_0ApiResponse"/>&gt;</returns>
Task<IGetApiKeysId_0ApiResponse> GetApiKeysId_0Async(int id, System.Threading.CancellationToken cancellationToken = default);
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysIdApiResponse"/>&gt;</returns>
Task<IGetApiKeysIdApiResponse> GetApiKeysIdAsync(int id, System.Threading.CancellationToken cancellationToken = default);
/// <summary>
/// Show API Key
@ -55,20 +55,8 @@ namespace Org.OpenAPITools.Api
/// </remarks>
/// <param name="id">Api Key ID.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysId_0ApiResponse"/>?&gt;</returns>
Task<IGetApiKeysId_0ApiResponse?> GetApiKeysId_0OrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default);
}
/// <summary>
/// The <see cref="IGetApiKeysId_0ApiResponse"/>
/// </summary>
public interface IGetApiKeysId_0ApiResponse : Org.OpenAPITools.Client.IApiResponse
{
/// <summary>
/// Returns true if the response is 400 BadRequest
/// </summary>
/// <returns></returns>
bool IsBadRequest { get; }
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysIdApiResponse"/>?&gt;</returns>
Task<IGetApiKeysIdApiResponse?> GetApiKeysIdOrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default);
}
/// <summary>
@ -79,21 +67,21 @@ namespace Org.OpenAPITools.Api
/// <summary>
/// The event raised after the server response
/// </summary>
public event EventHandler<ApiResponseEventArgs>? OnGetApiKeysId_0;
public event EventHandler<ApiResponseEventArgs>? OnGetApiKeysId;
/// <summary>
/// The event raised after an error querying the server
/// </summary>
public event EventHandler<ExceptionEventArgs>? OnErrorGetApiKeysId_0;
public event EventHandler<ExceptionEventArgs>? OnErrorGetApiKeysId;
internal void ExecuteOnGetApiKeysId_0(APIKeysApi.GetApiKeysId_0ApiResponse apiResponse)
internal void ExecuteOnGetApiKeysId(APIKEYSApi.GetApiKeysIdApiResponse apiResponse)
{
OnGetApiKeysId_0?.Invoke(this, new ApiResponseEventArgs(apiResponse));
OnGetApiKeysId?.Invoke(this, new ApiResponseEventArgs(apiResponse));
}
internal void ExecuteOnErrorGetApiKeysId_0(Exception exception)
internal void ExecuteOnErrorGetApiKeysId(Exception exception)
{
OnErrorGetApiKeysId_0?.Invoke(this, new ExceptionEventArgs(exception));
OnErrorGetApiKeysId?.Invoke(this, new ExceptionEventArgs(exception));
}
}
@ -144,17 +132,17 @@ namespace Org.OpenAPITools.Api
ApiKeyProvider = apiKeyProvider;
}
partial void FormatGetApiKeysId_0(ref int id);
partial void FormatGetApiKeysId(ref int id);
/// <summary>
/// Processes the server response
/// </summary>
/// <param name="apiResponseLocalVar"></param>
/// <param name="id"></param>
private void AfterGetApiKeysId_0DefaultImplementation(IGetApiKeysId_0ApiResponse apiResponseLocalVar, int id)
private void AfterGetApiKeysIdDefaultImplementation(IGetApiKeysIdApiResponse apiResponseLocalVar, int id)
{
bool suppressDefaultLog = false;
AfterGetApiKeysId_0(ref suppressDefaultLog, apiResponseLocalVar, id);
AfterGetApiKeysId(ref suppressDefaultLog, apiResponseLocalVar, id);
if (!suppressDefaultLog)
Logger.LogInformation("{0,-9} | {1} | {3}", (apiResponseLocalVar.DownloadedAt - apiResponseLocalVar.RequestedAt).TotalSeconds, apiResponseLocalVar.StatusCode, apiResponseLocalVar.Path);
}
@ -165,7 +153,7 @@ namespace Org.OpenAPITools.Api
/// <param name="suppressDefaultLog"></param>
/// <param name="apiResponseLocalVar"></param>
/// <param name="id"></param>
partial void AfterGetApiKeysId_0(ref bool suppressDefaultLog, IGetApiKeysId_0ApiResponse apiResponseLocalVar, int id);
partial void AfterGetApiKeysId(ref bool suppressDefaultLog, IGetApiKeysIdApiResponse apiResponseLocalVar, int id);
/// <summary>
/// Logs exceptions that occur while retrieving the server response
@ -174,10 +162,10 @@ namespace Org.OpenAPITools.Api
/// <param name="pathFormatLocalVar"></param>
/// <param name="pathLocalVar"></param>
/// <param name="id"></param>
private void OnErrorGetApiKeysId_0DefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, int id)
private void OnErrorGetApiKeysIdDefaultImplementation(Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, int id)
{
bool suppressDefaultLogLocalVar = false;
OnErrorGetApiKeysId_0(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, id);
OnErrorGetApiKeysId(ref suppressDefaultLogLocalVar, exceptionLocalVar, pathFormatLocalVar, pathLocalVar, id);
if (!suppressDefaultLogLocalVar)
Logger.LogError(exceptionLocalVar, "An error occurred while sending the request to the server.");
}
@ -190,19 +178,19 @@ namespace Org.OpenAPITools.Api
/// <param name="pathFormatLocalVar"></param>
/// <param name="pathLocalVar"></param>
/// <param name="id"></param>
partial void OnErrorGetApiKeysId_0(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, int id);
partial void OnErrorGetApiKeysId(ref bool suppressDefaultLogLocalVar, Exception exceptionLocalVar, string pathFormatLocalVar, string pathLocalVar, int id);
/// <summary>
/// Show API Key Show API Key
/// </summary>
/// <param name="id">Api Key ID.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysId_0ApiResponse"/>&gt;</returns>
public async Task<IGetApiKeysId_0ApiResponse?> GetApiKeysId_0OrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default)
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysIdApiResponse"/>&gt;</returns>
public async Task<IGetApiKeysIdApiResponse?> GetApiKeysIdOrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default)
{
try
{
return await GetApiKeysId_0Async(id, cancellationToken).ConfigureAwait(false);
return await GetApiKeysIdAsync(id, cancellationToken).ConfigureAwait(false);
}
catch (Exception)
{
@ -216,14 +204,14 @@ namespace Org.OpenAPITools.Api
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <param name="id">Api Key ID.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysId_0ApiResponse"/>&gt;</returns>
public async Task<IGetApiKeysId_0ApiResponse> GetApiKeysId_0Async(int id, System.Threading.CancellationToken cancellationToken = default)
/// <returns><see cref="Task"/>&lt;<see cref="IGetApiKeysIdApiResponse"/>&gt;</returns>
public async Task<IGetApiKeysIdApiResponse> GetApiKeysIdAsync(int id, System.Threading.CancellationToken cancellationToken = default)
{
UriBuilder uriBuilderLocalVar = new UriBuilder();
try
{
FormatGetApiKeysId_0(ref id);
FormatGetApiKeysId(ref id);
using (HttpRequestMessage httpRequestMessageLocalVar = new HttpRequestMessage())
{
@ -243,13 +231,13 @@ namespace Org.OpenAPITools.Api
{
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
ILogger<GetApiKeysId_0ApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<GetApiKeysId_0ApiResponse>();
ILogger<APIKEYSApi.GetApiKeysIdApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<APIKEYSApi.GetApiKeysIdApiResponse>();
GetApiKeysId_0ApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
APIKEYSApi.GetApiKeysIdApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
AfterGetApiKeysId_0DefaultImplementation(apiResponseLocalVar, id);
AfterGetApiKeysIdDefaultImplementation(apiResponseLocalVar, id);
Events.ExecuteOnGetApiKeysId_0(apiResponseLocalVar);
Events.ExecuteOnGetApiKeysId(apiResponseLocalVar);
return apiResponseLocalVar;
}
@ -257,55 +245,10 @@ namespace Org.OpenAPITools.Api
}
catch(Exception e)
{
OnErrorGetApiKeysId_0DefaultImplementation(e, "/api_keys/{id}", uriBuilderLocalVar.Path, id);
Events.ExecuteOnErrorGetApiKeysId_0(e);
OnErrorGetApiKeysIdDefaultImplementation(e, "/api_keys/{id}", uriBuilderLocalVar.Path, id);
Events.ExecuteOnErrorGetApiKeysId(e);
throw;
}
}
/// <summary>
/// The <see cref="GetApiKeysId_0ApiResponse"/>
/// </summary>
public partial class GetApiKeysId_0ApiResponse : Org.OpenAPITools.Client.ApiResponse, IGetApiKeysId_0ApiResponse
{
/// <summary>
/// The logger
/// </summary>
public ILogger<GetApiKeysId_0ApiResponse> Logger { get; }
/// <summary>
/// The <see cref="GetApiKeysId_0ApiResponse"/>
/// </summary>
/// <param name="logger"></param>
/// <param name="httpRequestMessage"></param>
/// <param name="httpResponseMessage"></param>
/// <param name="rawContent"></param>
/// <param name="path"></param>
/// <param name="requestedAt"></param>
/// <param name="jsonSerializerOptions"></param>
public GetApiKeysId_0ApiResponse(ILogger<GetApiKeysId_0ApiResponse> logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions)
{
Logger = logger;
OnCreated(httpRequestMessage, httpResponseMessage);
}
partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
/// <summary>
/// Returns true if the response is 400 BadRequest
/// </summary>
/// <returns></returns>
public bool IsBadRequest => 400 == (int)StatusCode;
private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode)
{
bool suppressDefaultLog = false;
OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode);
if (!suppressDefaultLog)
Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode);
}
partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode);
}
}
}

View File

@ -59,18 +59,6 @@ namespace Org.OpenAPITools.Api
Task<IGetApiKeysIdApiResponse?> GetApiKeysIdOrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default);
}
/// <summary>
/// The <see cref="IGetApiKeysIdApiResponse"/>
/// </summary>
public interface IGetApiKeysIdApiResponse : Org.OpenAPITools.Client.IApiResponse
{
/// <summary>
/// Returns true if the response is 400 BadRequest
/// </summary>
/// <returns></returns>
bool IsBadRequest { get; }
}
/// <summary>
/// Represents a collection of functions to interact with the API endpoints
/// </summary>
@ -86,7 +74,7 @@ namespace Org.OpenAPITools.Api
/// </summary>
public event EventHandler<ExceptionEventArgs>? OnErrorGetApiKeysId;
internal void ExecuteOnGetApiKeysId(ApiKeysApi.GetApiKeysIdApiResponse apiResponse)
internal void ExecuteOnGetApiKeysId(APIKEYSApi.GetApiKeysIdApiResponse apiResponse)
{
OnGetApiKeysId?.Invoke(this, new ApiResponseEventArgs(apiResponse));
}
@ -243,9 +231,9 @@ namespace Org.OpenAPITools.Api
{
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
ILogger<GetApiKeysIdApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<GetApiKeysIdApiResponse>();
ILogger<APIKEYSApi.GetApiKeysIdApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<APIKEYSApi.GetApiKeysIdApiResponse>();
GetApiKeysIdApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
APIKEYSApi.GetApiKeysIdApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
AfterGetApiKeysIdDefaultImplementation(apiResponseLocalVar, id);
@ -262,50 +250,5 @@ namespace Org.OpenAPITools.Api
throw;
}
}
/// <summary>
/// The <see cref="GetApiKeysIdApiResponse"/>
/// </summary>
public partial class GetApiKeysIdApiResponse : Org.OpenAPITools.Client.ApiResponse, IGetApiKeysIdApiResponse
{
/// <summary>
/// The logger
/// </summary>
public ILogger<GetApiKeysIdApiResponse> Logger { get; }
/// <summary>
/// The <see cref="GetApiKeysIdApiResponse"/>
/// </summary>
/// <param name="logger"></param>
/// <param name="httpRequestMessage"></param>
/// <param name="httpResponseMessage"></param>
/// <param name="rawContent"></param>
/// <param name="path"></param>
/// <param name="requestedAt"></param>
/// <param name="jsonSerializerOptions"></param>
public GetApiKeysIdApiResponse(ILogger<GetApiKeysIdApiResponse> logger, System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage, string rawContent, string path, DateTime requestedAt, System.Text.Json.JsonSerializerOptions jsonSerializerOptions) : base(httpRequestMessage, httpResponseMessage, rawContent, path, requestedAt, jsonSerializerOptions)
{
Logger = logger;
OnCreated(httpRequestMessage, httpResponseMessage);
}
partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
/// <summary>
/// Returns true if the response is 400 BadRequest
/// </summary>
/// <returns></returns>
public bool IsBadRequest => 400 == (int)StatusCode;
private void OnDeserializationErrorDefaultImplementation(Exception exception, HttpStatusCode httpStatusCode)
{
bool suppressDefaultLog = false;
OnDeserializationError(ref suppressDefaultLog, exception, httpStatusCode);
if (!suppressDefaultLog)
Logger.LogError(exception, "An error occurred while deserializing the {code} response.", httpStatusCode);
}
partial void OnDeserializationError(ref bool suppressDefaultLog, Exception exception, HttpStatusCode httpStatusCode);
}
}
}

View File

@ -61,7 +61,7 @@ namespace YourProject
{
var host = CreateHostBuilder(args).Build();
var api = host.Services.GetRequiredService<IAPIKEYSApi>();
GetApiKeysId_1ApiResponse apiResponse = await api.GetApiKeysId_1Async("todo");
GetApiKeysIdApiResponse apiResponse = await api.GetApiKeysIdAsync("todo");
object model = apiResponse.Ok();
}