Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -5701,8 +5701,6 @@ protected void addHeaders(ApiResponse response, List<CodegenProperty> properties
}
}

private final Map<String, Integer> seenOperationIds = new HashMap<String, Integer>();

/**
* Add operation to group
*
Expand All @@ -5723,18 +5721,13 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
}
// 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ private void postProcessResponseCode(CodegenResponse response, String status, Se
httpStatusesWithReturn.add(status);
}
}
private HashMap<String, String> duplicateOf = new HashMap<String, String>();

@Override
@SuppressWarnings("unchecked")
Expand All @@ -839,6 +840,12 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace {{packageName}}.{{apiPackage}}
{{/operation}}
}
{{#operation}}
{{^vendorExtensions.x-duplicates}}
{{#responses}}
{{#-first}}

Expand Down Expand Up @@ -115,6 +116,7 @@ namespace {{packageName}}.{{apiPackage}}
}
{{/-first}}
{{/responses}}
{{/vendorExtensions.x-duplicates}}
{{/operation}}

/// <summary>
Expand All @@ -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));
}
Expand Down Expand Up @@ -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}});

Expand Down Expand Up @@ -680,6 +682,7 @@ namespace {{packageName}}.{{apiPackage}}
}
{{/lambda.trimLineBreaks}}
}
{{^vendorExtensions.x-duplicates}}
{{#responses}}
{{#-first}}

Expand Down Expand Up @@ -792,6 +795,7 @@ namespace {{packageName}}.{{apiPackage}}
}
{{/-first}}
{{/responses}}
{{/vendorExtensions.x-duplicates}}
{{/operation}}
}
{{/operations}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,7 +24,7 @@ using Org.OpenAPITools.Model;

namespace Example
{
public class GetApiKeysId_1Example
public class GetApiKeysIdExample
{
public static void Main()
{
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,7 +24,7 @@ using Org.OpenAPITools.Model;

namespace Example
{
public class GetApiKeysId_0Example
public class GetApiKeysIdExample
{
public static void Main()
{
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public APIKEYSApiTests(): base(Array.Empty<string>())
}

/// <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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public APIKeysApiTests(): base(Array.Empty<string>())
}

/// <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);
}
}
}
Loading
Loading