Skip to content

Fix #25575: derive generichost TokenProvider deps from per-operation auth - #25736

Open
Inf1mum wants to merge 1 commit into
OpenAPITools:masterfrom
Inf1mum:fix/25575-csharp-generichost-tokenprovider
Open

Inf1mum wants to merge 1 commit into
OpenAPITools:masterfrom
Inf1mum:fix/25575-csharp-generichost-tokenprovider

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25575

With an apiKey scheme declared, every generichost Api class took TokenProvider<ApiKeyToken> in its constructor even when none of its operations used that scheme, breaking DI resolution for the others. The class-level TokenProvider blocks now key off per-class flags computed from the operations' own auth methods (webhook Api classes included), instead of the global scheme presence. Support files (ClientUtils, RateLimitProvider) are untouched.

All 51 generichost samples regenerated (129 Api/*.cs files, removals only); dotnet build on sdk:8.0 passes for the issue repro, a mixed-scheme client, and the petstore sample; *CSharp generator test suite 104/104 with a new regression test + fixture.


Summary by cubic

Fixes #25575: generichost Api classes now only inject TokenProvider dependencies for security schemes their operations actually use, instead of always requiring them when a scheme is declared anywhere.

  • Previously, any Api class took TokenProvider<ApiKeyToken> in its constructor whenever the spec declared an apiKey scheme, even if none of its operations used it, breaking DI resolution for those classes.
  • Token provider flags are now computed per class from the operations' own auth methods (webhook Api classes included).
  • Support files (ClientUtils, RateLimitProvider) are untouched, and a regression test with a fixture was added.

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

View guided diff

…chost Api classes based on operations' auth methods

Signed-off-by: Inf1mum <vadimlazuk5@gmail.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.

1 issue found across 133 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/test/resources/3_1/csharp/issue_25575.yaml">

<violation number="1" location="modules/openapi-generator/src/test/resources/3_1/csharp/issue_25575.yaml:5">
P2: This fixture only declares one security scheme, so the regression test cannot catch a bug where an Api class gets the wrong scheme's TokenProvider. Add a second scheme (for example, a bearer or OAuth2 scheme) used by a different tag, and assert that each Api class gets only its own provider. A webhook operation with its own security would also cover the webhook path.</violation>
</file>

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

View guided diff | Re-trigger cubic

info:
title: issue 25575
version: "1"
security:

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.

P2: This fixture only declares one security scheme, so the regression test cannot catch a bug where an Api class gets the wrong scheme's TokenProvider. Add a second scheme (for example, a bearer or OAuth2 scheme) used by a different tag, and assert that each Api class gets only its own provider. A webhook operation with its own security would also cover the webhook path.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/test/resources/3_1/csharp/issue_25575.yaml, line 5:

<comment>This fixture only declares one security scheme, so the regression test cannot catch a bug where an Api class gets the wrong scheme's TokenProvider. Add a second scheme (for example, a bearer or OAuth2 scheme) used by a different tag, and assert that each Api class gets only its own provider. A webhook operation with its own security would also cover the webhook path.</comment>

<file context>
@@ -0,0 +1,40 @@
+info:
+  title: issue 25575
+  version: "1"
+security:
+  - api_key: []
+paths:
</file context>

@wing328

wing328 commented Nov 18, 2026

Copy link
Copy Markdown
Member

Thanks for the PR

cc @devhl-labs

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][CSHARP] generichost: every Api class requires TokenProvider<ApiKeyToken> when an apiKey scheme is only declared

2 participants