Skip to content

fix(csharp): make generichost oneOf constructors public - #24700

Merged
wing328 merged 2 commits into
masterfrom
KannaKim-fix-23046
Aug 14, 2026
Merged

fix(csharp): make generichost oneOf constructors public#24700
wing328 merged 2 commits into
masterfrom
KannaKim-fix-23046

Conversation

@wing328

@wing328 wing328 commented Aug 14, 2026

Copy link
Copy Markdown
Member

based on #24341

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Limit C# oneOf constructors to operation inputs to reduce public surface and prevent misuse. Previously all generated oneOf constructors were public; now constructors are public only for models used in request bodies or parameters, and internal for response-only models.

  • Adds x-model-is-operation-input and marks models by scanning operations’ request bodies and parameter schemas in AbstractCSharpCodegen.postProcessAllModels; the C# generichost modelGeneric.mustache uses this to set constructor visibility.
  • Adds issue_23046.yaml and CSharpClientCodegenTest#testGenericHostOneOfConstructorsRespectApiVisibility to verify public vs internal constructors; regenerates samples accordingly.

Migration

  • If you were directly instantiating response-only oneOf models, update code to rely on deserialization results or use input model types. No config changes are required for typical client usage.

Written for commit e5e3bb2. Summary will update on new commits.

Review in cubic

@wing328 wing328 changed the title Kanna kim fix 23046 fix(csharp): make generichost oneOf constructors public #24341 Aug 14, 2026
@wing328 wing328 changed the title fix(csharp): make generichost oneOf constructors public #24341 fix(csharp): make generichost oneOf constructors public Aug 14, 2026
@wing328 wing328 added this to the 7.25.0 milestone Aug 14, 2026
@wing328
wing328 marked this pull request as ready for review August 14, 2026 03:25

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 191 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java">

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java:624">
P3: `postProcessAllModels` here lives in AbstractCSharpCodegen, the base for every C# generator (csharp, csharp-netcore, csharp-dotnet2, ...). `getOperationInputModels()` walks every path, parameter, and the whole reachable schema graph and mutates each model's vendor extensions, but the new `x-model-is-operation-input` vendor extension is consumed only by the generichost `modelGeneric.mustache`. All non-generichost C# generators now pay this traversal cost for a result they never use. Consider gating the call (and the per-model extension writes) on the generichost library to avoid the wasted work elsewhere.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@Override
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
final Map<String, ModelsMap> processed = super.postProcessAllModels(objs);
final Set<String> operationInputModels = getOperationInputModels();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: postProcessAllModels here lives in AbstractCSharpCodegen, the base for every C# generator (csharp, csharp-netcore, csharp-dotnet2, ...). getOperationInputModels() walks every path, parameter, and the whole reachable schema graph and mutates each model's vendor extensions, but the new x-model-is-operation-input vendor extension is consumed only by the generichost modelGeneric.mustache. All non-generichost C# generators now pay this traversal cost for a result they never use. Consider gating the call (and the per-model extension writes) on the generichost library to avoid the wasted work elsewhere.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java, line 624:

<comment>`postProcessAllModels` here lives in AbstractCSharpCodegen, the base for every C# generator (csharp, csharp-netcore, csharp-dotnet2, ...). `getOperationInputModels()` walks every path, parameter, and the whole reachable schema graph and mutates each model's vendor extensions, but the new `x-model-is-operation-input` vendor extension is consumed only by the generichost `modelGeneric.mustache`. All non-generichost C# generators now pay this traversal cost for a result they never use. Consider gating the call (and the per-model extension writes) on the generichost library to avoid the wasted work elsewhere.</comment>

<file context>
@@ -616,6 +621,7 @@ public ModelsMap postProcessModels(ModelsMap objs) {
     @Override
     public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
         final Map<String, ModelsMap> processed = super.postProcessAllModels(objs);
+        final Set<String> operationInputModels = getOperationInputModels();
 
         Map<String, CodegenModel> enumRefs = new HashMap<>();
</file context>

@wing328
wing328 merged commit 71a84ff into master Aug 14, 2026
175 of 272 checks passed
@wing328
wing328 deleted the KannaKim-fix-23046 branch August 14, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants