Skip to content

Commit 0e34d39

Browse files
authored
add tests, option for useVirtualHooks (csharp) (#20837)
1 parent 21be5f5 commit 0e34d39

Some content is hidden

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

48 files changed

+5327
-1
lines changed

.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/[email protected]
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/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.)");

0 commit comments

Comments
 (0)