Skip to content

Commit 71e7c39

Browse files
authored
Merge branch 'OpenAPITools:master' into fix/17419_java_useOneOfInterface
2 parents cf52ca6 + 3ab495a commit 71e7c39

113 files changed

Lines changed: 6942 additions & 1612 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/samples-dotnet8-client.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
matrix:
1717
sample:
1818
- samples/client/petstore/csharp/restsharp/net8/ParameterMappings/
19+
- samples/client/petstore/csharp/restsharp/net8/useVirtualForHooks/
1920
steps:
2021
- uses: actions/checkout@v4
2122
- uses: actions/setup-dotnet@v4.3.0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# for .net standard
2+
generatorName: csharp
3+
library: restsharp
4+
outputDir: samples/client/petstore/csharp/restsharp/net8/useVirtualForHooks
5+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-addpet-only.yaml
6+
templateDir: modules/openapi-generator/src/main/resources/csharp
7+
additionalProperties:
8+
packageGuid: '{D0A67E81-4061-48EB-B4B8-C73BDF8B2D95}'
9+
targetFramework: net8.0
10+
useVirtualForHooks: true

docs/generators/csharp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5454
|useIntForTimeout|Use int for Timeout (fall back to v7.9.0 templates). This option (for restsharp only) will be deprecated so please migrated to TimeSpan instead.| |false|
5555
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped.| |false|
5656
|useSourceGeneration|Use source generation where available (only `generichost` library supports this option).| |false|
57+
|useVirtualForHooks|Generate code that exposes public virtual hooks on ApiClient to customize low-level HTTP requests (only `restsharp`. `httpclient` libraries support this option).| |false|
5758
|validatable|Generates self-validatable models.| |true|
5859
|zeroBasedEnums|Enumerations with string values will start from 0 when true, 1 when false. If not set, enumerations with string values will start from 0 if the first value is 'unknown', case insensitive.| |null|
5960

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
287287
public static final String SUPPORTS_ASYNC_DESC = "Generate code that supports async operations.";
288288

289289
public static final String USE_VIRTUAL_FOR_HOOKS = "useVirtualForHooks";
290-
public static final String USE_VIRTUAL_FOR_HOOKS_DESC = "Generate code that exposes public virtual hooks on ApiClient to customize low-level HTTP requests.";
290+
public static final String USE_VIRTUAL_FOR_HOOKS_DESC = "Generate code that exposes public virtual hooks on ApiClient to customize low-level HTTP requests (only `restsharp`. `httpclient` libraries support this option).";
291291

292292
public static final String EXCLUDE_TESTS = "excludeTests";
293293
public static final String EXCLUDE_TESTS_DESC = "Specifies that no tests are to be generated.";

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5657,6 +5657,7 @@ protected boolean isReservedWord(String word) {
56575657
*/
56585658
protected String getOrGenerateOperationId(Operation operation, String path, String httpMethod) {
56595659
String operationId = operation.getOperationId();
5660+
56605661
if (StringUtils.isBlank(operationId)) {
56615662
String tmpPath = path;
56625663
tmpPath = tmpPath.replaceAll("\\{", "");
@@ -5681,6 +5682,10 @@ protected String getOrGenerateOperationId(Operation operation, String path, Stri
56815682
LOGGER.warn("Empty operationId found for path: {} {}. Renamed to auto-generated operationId: {}", httpMethod, path, operationId);
56825683
}
56835684

5685+
if (operationIdNameMapping.containsKey(operationId)) {
5686+
return operationIdNameMapping.get(operationId);
5687+
}
5688+
56845689
// remove prefix in operationId
56855690
if (removeOperationIdPrefix) {
56865691
// The prefix is everything before the removeOperationIdPrefixCount occurrence of removeOperationIdPrefixDelimiter
@@ -5693,13 +5698,8 @@ protected String getOrGenerateOperationId(Operation operation, String path, Stri
56935698
operationId = String.join(removeOperationIdPrefixDelimiter, Arrays.copyOfRange(components, component_number, components.length));
56945699
}
56955700
}
5696-
operationId = removeNonNameElementToCamelCase(operationId);
56975701

5698-
if (operationIdNameMapping.containsKey(operationId)) {
5699-
return operationIdNameMapping.get(operationId);
5700-
} else {
5701-
return toOperationId(operationId);
5702-
}
5702+
return toOperationId(removeNonNameElementToCamelCase(operationId));
57035703
}
57045704

57055705
/**

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ public CSharpClientCodegen() {
357357
"Use source generation where available (only `generichost` library supports this option).",
358358
this.getUseSourceGeneration());
359359

360+
addSwitch(CodegenConstants.USE_VIRTUAL_FOR_HOOKS,
361+
CodegenConstants.USE_VIRTUAL_FOR_HOOKS_DESC,
362+
this.useVirtualForHooks);
363+
360364
supportedLibraries.put(GENERICHOST, "HttpClient, Generic Host integration, and System.Text.Json (https://docs.microsoft.com/en-us/dotnet/core/extensions/generic-host)");
361365
supportedLibraries.put(HTTPCLIENT, "HttpClient and Newtonsoft (https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient) "
362366
+ "(Experimental. Subject to breaking changes without notice.)");

modules/openapi-generator/src/main/resources/Java/libraries/feign/build.gradle.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ ext {
110110
jackson_databind_nullable_version = "0.2.6"
111111
{{/openApiNullable}}
112112
jakarta_annotation_version = "1.3.5"
113-
feign_version = "10.12"
113+
feign_version = "13.5"
114114
feign_form_version = "3.8.0"
115115
junit_version = "5.7.0"
116116
scribejava_version = "8.0.0"

modules/openapi-generator/src/main/resources/Java/libraries/feign/build.sbt.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ lazy val root = (project in file(".")).
1111
libraryDependencies ++= Seq(
1212
"io.swagger" % "swagger-annotations" % "1.6.11" % "compile",
1313
"com.google.code.findbugs" % "jsr305" % "3.0.2" % "compile",
14-
"io.github.openfeign" % "feign-core" % "10.12" % "compile",
14+
"io.github.openfeign" % "feign-core" % "13.5" % "compile",
1515
{{#jackson}}
16-
"io.github.openfeign" % "feign-jackson" % "10.12" % "compile",
16+
"io.github.openfeign" % "feign-jackson" % "13.5" % "compile",
1717
{{/jackson}}
18-
"io.github.openfeign" % "feign-slf4j" % "10.12" % "compile",
18+
"io.github.openfeign" % "feign-slf4j" % "13.5" % "compile",
1919
"io.github.openfeign.form" % "feign-form" % "3.8.0" % "compile",
20-
"io.github.openfeign" % "feign-okhttp" % "10.12" % "compile",
20+
"io.github.openfeign" % "feign-okhttp" % "13.5" % "compile",
2121
{{#jackson}}
2222
"com.fasterxml.jackson.core" % "jackson-core" % "2.17.1" % "compile",
2323
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.17.1" % "compile",

modules/openapi-generator/src/main/resources/csharp/RetryConfiguration.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ namespace {{packageName}}.Client
1919
/// <summary>
2020
/// Retry policy
2121
/// </summary>
22-
public static Policy<RestResponse> RetryPolicy { get; set; }
22+
public static ISyncPolicy<RestResponse> RetryPolicy { get; set; }
2323

2424
/// <summary>
2525
/// Async retry policy
2626
/// </summary>
27-
public static AsyncPolicy<RestResponse> AsyncRetryPolicy { get; set; }
27+
public static IAsyncPolicy<RestResponse> AsyncRetryPolicy { get; set; }
2828
{{/useRestSharp}}
2929
{{#useHttpClient}}
3030
/// <summary>
3131
/// Retry policy
3232
/// </summary>
33-
public static Policy<HttpResponseMessage> RetryPolicy { get; set; }
33+
public static ISyncPolicy<HttpResponseMessage> RetryPolicy { get; set; }
3434

3535
/// <summary>
3636
/// Async retry policy
3737
/// </summary>
38-
public static AsyncPolicy<HttpResponseMessage> AsyncRetryPolicy { get; set; }
38+
public static IAsyncPolicy<HttpResponseMessage> AsyncRetryPolicy { get; set; }
3939
{{/useHttpClient}}
4040
}
4141
}

0 commit comments

Comments
 (0)