Skip to content

fix(csharp): scan webhooks for operation-input models - #25626

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
khayashi4337:fix/csharp-webhook-input-models
Nov 16, 2026
Merged

wing328 merged 1 commit into
OpenAPITools:masterfrom
khayashi4337:fix/csharp-webhook-input-models

Conversation

@khayashi4337

@khayashi4337 khayashi4337 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

In the csharp client with library=generichost, a oneOf model that is referenced only from a top-level webhooks operation gets internal constructors (the ones that take a oneOf member), although the generated API exposes the model in a public method signature. Code outside the generated assembly therefore cannot construct the request body (new AnimalChoice(cat) does not compile there).

webhooks is the OpenAPI 3.1 field for requests that the API provider sends to the consumer. generichost turns each webhook operation into an API method, like a path operation (in the fixture below, which has no tags, the method lands in DefaultApi).

Reproducer

modules/openapi-generator/src/test/resources/3_1/csharp/webhook-only-model.yaml (added by this PR): no paths at all and one webhook, petChanged (operationId: onPetChanged), whose request body is $ref: '#/components/schemas/AnimalChoice'; AnimalChoice is a oneOf of Cat and Dog. The file declares openapi: 3.1.0 because webhooks is a 3.1 field; nothing else in it is 3.1-specific.

Generated with -g csharp --library generichost. On master, Model/AnimalChoice.cs has

internal AnimalChoice(Cat cat)
...
internal AnimalChoice(Dog dog)

while Api/DefaultApi.cs declares, in public interface IDefaultApi (and implements as a public async method in public sealed partial class DefaultApi):

Task<IOnPetChangedApiResponse> OnPetChangedAsync(AnimalChoice animalChoice, System.Threading.CancellationToken cancellationToken = default);

So a caller outside the assembly cannot build the argument of that public method with new.

The cause: AbstractCSharpCodegen.getOperationInputModels() collects the models reachable from operation parameters and request bodies and marks them with the vendor extension x-model-is-operation-input. generichost/modelGeneric.mustache uses the mark to choose between {{>visibility}} (public, or internal when nonPublicApi is set) and internal for the oneOf constructors. The method only walked openAPI.getPaths(), so models reachable only from webhooks were never marked.

Fix

getOperationInputModels() now collects the PathItems of openAPI.getPaths() and of openAPI.getWebhooks() (both null-safe) and runs the existing traversal over all of them. It no longer returns early when getPaths() is null, so a spec that has only webhooks is scanned too.

After regenerating, the same lines read public AnimalChoice(Cat cat) and public AnimalChoice(Dog dog).

Behavior change

For oneOf models reachable only through webhook operations, the constructors that take a oneOf member get {{>visibility}} (public unless nonPublicApi=true) instead of internal. Other constructors and non-oneOf models are not affected. Models that are also referenced from paths are unaffected. generichost/modelGeneric.mustache is the only template that reads x-model-is-operation-input, so no other C# library or generator changes.

Tests

Test Asserts
testGenerichostWebhookModelGetsPublicCtor (new) the parsed spec has no paths (so the null-paths branch is exercised); generating webhook-only-model.yaml with generichost produces Model/AnimalChoice.cs that contains public AnimalChoice( and does not contain internal AnimalChoice(

./mvnw -nsu -Denforcer.skip=true -pl modules/openapi-generator -am -Dtest=CSharpClientCodegenTest -Dsurefire.failIfNoSpecifiedTests=false test

Tests run Result
master + this PR 31 0 failures, 0 skipped
this PR with the AbstractCSharpCodegen.java change reverted (test kept; run limited to the new test) 1 1 failure — testGenerichostWebhookModelGetsPublicCtor

Samples

No sample changed. The only csharp config whose input spec declares webhooks is bin/configs/csharp-generichost-latest-helloWorld.yaml (3_1/csharp/hello-world.yaml); its webhook payload is an inline object schema, not a $ref to a oneOf model. Regenerating it with the CLI built from this branch gives a src/Org.OpenAPITools identical to the committed samples/client/petstore/csharp/generichost/latest/HelloWorld (built by samples-dotnet10.yaml).

cc @wing328 and the C# technical committee: @mandrean @shibayan @Blackclaws @lucamazzanti

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples — scoped to this change: built the CLI (./mvnw -pl modules/openapi-generator-cli -am package -DskipTests) and regenerated the only csharp config whose spec has webhooks (csharp-generichost-latest-helloWorld.yaml) with it; src/Org.OpenAPITools is identical to the committed sample, so no sample change is committed. export_docs_generators.sh not run: no generator option or metadata changes.
    ./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.

🤖 Generated with Claude Code


Summary by cubic

Fixes the csharp generichost client so oneOf models referenced only by webhooks operations get public constructors.

Previously, getOperationInputModels() scanned only openAPI.getPaths(), so a model reachable solely from a webhook was never marked as an operation input, and its oneOf constructors were generated internal even though the public API exposes the model — callers outside the assembly could not construct the request body with new. The scan now also traverses openAPI.getWebhooks() and no longer skips specs where paths is null, covering webhooks-only 3.1 documents. Models also referenced from paths are unaffected, as are non-oneOf models.

Adds a webhooks-only fixture and a test asserting the oneOf model's constructors are generated public.

Written for commit 7cdaa2c. Summary will update on new commits.

View guided diff

getOperationInputModels only traversed openAPI.getPaths(), so a model
referenced solely by a top-level webhook kept an `internal` ctor even
though generated API methods expose it to callers. Webhook PathItems
are now collected alongside paths so such models get a `public` ctor.

The fixture lives under 3_1/ because the 3.0 parser drops `webhooks`;
it omits `paths` entirely so the getPaths() == null branch is covered
directly.

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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.

No issues found across 3 files

View guided diff | Re-trigger cubic

@wing328

wing328 commented Nov 11, 2026

Copy link
Copy Markdown
Member

thanks for the PR

cc @devhl-labs

@khayashi4337

Copy link
Copy Markdown
Contributor Author

Thanks!

@devhl-labs

Copy link
Copy Markdown
Contributor

LGTM

@wing328
wing328 merged commit db87f5f into OpenAPITools:master Nov 16, 2026
15 checks passed
@wing328 wing328 added this to the 7.28.0 milestone Nov 16, 2026
khayashi4337 added a commit to khayashi4337/openapi-generator that referenced this pull request Dec 1, 2026
The following fixes were extracted into separate PRs and no longer
belong here; revert them to upstream/master so that this PR now only
carries the OpenAPI 3.2 changes.

| fix | what | original commits | split-out PR |
|-----|------|------------------|--------------|
| A1 | kotlin jvm-vertx form sending | parts of 75be8f4, 7f1bcb8 | OpenAPITools#25623 |
| A2 | kotlin ktor/multiplatform form `it` | parts of 07530ab, 3a953e5, f1575f3, 7f1bcb8 | OpenAPITools#25624 |
| A3 | kotlin `$` escaping | parts of 9074531, 7f1bcb8 | OpenAPITools#25625 |
| A4 | kotlin member reads via `this.` | 94aca3a, 19694ac (main part) | OpenAPITools#25691, OpenAPITools#25692 |
| A5 | kotlin param/generated-local collisions | rename part of 6b82674 | OpenAPITools#25690 |
| A6 | kotlin deepObject keys | 910b590 | OpenAPITools#25622 |
| A7 | core form required (allOf) | 7ab9da5, bc20a2c | OpenAPITools#25627 |
| A8 | php internal-variable collisions | 9f2676e, a00d51c (keeping the 3.2 capture/fixture parts) | OpenAPITools#25630 |
| A9 | csharp webhook input models | webhook-scan part of e49e09e | OpenAPITools#25626 |
| A10 | core unexpected-attribute regex | widen part of e5ec5f4 | OpenAPITools#25621 |

This PR now only carries the OpenAPI 3.2 changes.

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants