fix(csharp): make generichost oneOf constructors public - #24700
Conversation
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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>
based on #24341
PR checklist
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.
Summary by cubic
Limit C#
oneOfconstructors to operation inputs to reduce public surface and prevent misuse. Previously all generatedoneOfconstructors were public; now constructors are public only for models used in request bodies or parameters, and internal for response-only models.x-model-is-operation-inputand marks models by scanning operations’ request bodies and parameter schemas inAbstractCSharpCodegen.postProcessAllModels; the C#generichostmodelGeneric.mustacheuses this to set constructor visibility.issue_23046.yamlandCSharpClientCodegenTest#testGenericHostOneOfConstructorsRespectApiVisibilityto verify public vs internal constructors; regenerates samples accordingly.Migration
oneOfmodels, 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.