-
Notifications
You must be signed in to change notification settings - Fork 380
feat(http-server-csharp): added include-operations-controller option to skip generating operations controller
#11495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
2
commits into
main
Choose a base branch
from
copilot/featurehttp-server-csharp-disable-operations-contr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+153
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
.chronus/changes/http-server-csharp-include-operations-controller-2026-7-30.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/http-server-csharp" | ||
| --- | ||
|
|
||
| Add `include-operations-controller` emitter option (boolean, default `false`) to control whether a controller and business-logic interface are generated for the ARM Operations endpoint. Set to `true` to include the Operations controller. | ||
|
|
||
| ```yaml | ||
| # tspconfig.yaml | ||
| options: | ||
| "@typespec/http-server-csharp": | ||
| include-operations-controller: true | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ export interface CSharpServiceEmitterOptions { | |
| "https-port"?: number; | ||
| /** Specifies the collection type to use: 'array' or 'enumerable'. The default is 'array'. */ | ||
| "collection-type"?: "array" | "enumerable"; | ||
| /** When true, generates a controller and business-logic interface for the ARM Operations endpoint. Default is false. */ | ||
| "include-operations-controller"?: boolean; | ||
| } | ||
|
|
||
| const EmitterOptionsSchema: JSONSchemaType<CSharpServiceEmitterOptions> = { | ||
|
|
@@ -96,6 +98,13 @@ const EmitterOptionsSchema: JSONSchemaType<CSharpServiceEmitterOptions> = { | |
| description: | ||
| "Specifies the collection type to use: 'array' or 'enumerable'. The default is 'array'.", | ||
| }, | ||
| "include-operations-controller": { | ||
| type: "boolean", | ||
| nullable: true, | ||
| default: false, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOTE: this is a breaking change |
||
| description: | ||
| "When true, generates a controller and business-logic interface for the ARM Operations endpoint. Default is false.", | ||
| }, | ||
| }, | ||
| required: [], | ||
| }; | ||
|
|
||
114 changes: 114 additions & 0 deletions
114
packages/http-server-csharp/test/include-operations-controller.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { TestFileSystem, TesterInstance } from "@typespec/compiler/testing"; | ||
| import assert from "assert"; | ||
| import { beforeEach, describe, it } from "vitest"; | ||
| import { CSharpServiceEmitterOptions } from "../src/lib.js"; | ||
| import { ApiTester, compileAndDiagnose, getStandardService } from "./test-host.js"; | ||
|
|
||
| function assertFileEmitted(fs: TestFileSystem, fileName: string): void { | ||
| const result = [...fs.fs.entries()].filter((e) => e[0].includes(`/${fileName}`)); | ||
| assert.strictEqual( | ||
| result.length, | ||
| 1, | ||
| `Expected ${fileName} to be emitted, but it was not found (${result.length} matches)`, | ||
| ); | ||
| } | ||
|
|
||
| function assertFileNotEmitted(fs: TestFileSystem, fileName: string): void { | ||
| const result = [...fs.fs.entries()].filter((e) => e[0].includes(`/${fileName}`)); | ||
| assert.strictEqual(result.length, 0, `Expected ${fileName} to not be emitted, but it was`); | ||
| } | ||
|
|
||
| async function compile( | ||
| tester: TesterInstance, | ||
| code: string, | ||
| emitterOptions: CSharpServiceEmitterOptions = { "skip-format": true }, | ||
| ): Promise<TestFileSystem> { | ||
| const [result] = await compileAndDiagnose(tester, getStandardService(code), emitterOptions); | ||
| return result.fs; | ||
| } | ||
|
|
||
| let tester: TesterInstance; | ||
|
|
||
| beforeEach(async () => { | ||
| tester = await ApiTester.createInstance(); | ||
| }); | ||
|
|
||
| describe("include-operations-controller option", () => { | ||
| it("excludes the Operations controller and interface by default", async () => { | ||
| const fs = await compile( | ||
| tester, | ||
| ` | ||
| interface Operations { | ||
| @route("/operations") @get list(): string[]; | ||
| } | ||
| interface Widgets { | ||
| @route("/widgets") @get list(): string[]; | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| assertFileNotEmitted(fs, "OperationsController.cs"); | ||
| assertFileNotEmitted(fs, "IOperations.cs"); | ||
| assertFileEmitted(fs, "WidgetsController.cs"); | ||
| assertFileEmitted(fs, "IWidgets.cs"); | ||
| }); | ||
|
|
||
| it("includes the Operations controller and interface when option is true", async () => { | ||
| const fs = await compile( | ||
| tester, | ||
| ` | ||
| interface Operations { | ||
| @route("/operations") @get list(): string[]; | ||
| } | ||
| interface Widgets { | ||
| @route("/widgets") @get list(): string[]; | ||
| } | ||
| `, | ||
| { "skip-format": true, "include-operations-controller": true }, | ||
| ); | ||
|
|
||
| assertFileEmitted(fs, "OperationsController.cs"); | ||
| assertFileEmitted(fs, "IOperations.cs"); | ||
| assertFileEmitted(fs, "WidgetsController.cs"); | ||
| assertFileEmitted(fs, "IWidgets.cs"); | ||
| }); | ||
|
|
||
| it("does not exclude synthetic namespace-level Operations interfaces (only exact 'Operations' name is excluded)", async () => { | ||
| // Namespace-level operations produce a synthetic `${ns.name}Operations` interface | ||
| // (e.g. ContosoOperations). These are kept; only an interface literally named "Operations" is excluded. | ||
| const [result] = await compileAndDiagnose( | ||
| tester, | ||
| ` | ||
| @service(#{title: "Contoso"}) | ||
| namespace Contoso { | ||
| @route("/operations") @get op listOps(): string[]; | ||
| interface Widgets { | ||
| @route("/widgets") @get list(): string[]; | ||
| } | ||
| } | ||
| `, | ||
| { "skip-format": true }, | ||
| ); | ||
| const fs = result.fs; | ||
|
|
||
| // Synthetic ContosoOperations interface is NOT named "Operations" so it is still emitted | ||
| assertFileEmitted(fs, "ContosoOperationsController.cs"); | ||
| assertFileEmitted(fs, "IContosoOperations.cs"); | ||
| assertFileEmitted(fs, "WidgetsController.cs"); | ||
| assertFileEmitted(fs, "IWidgets.cs"); | ||
| }); | ||
|
|
||
| it("does not affect non-Operations interfaces when option is false (default)", async () => { | ||
| const fs = await compile( | ||
| tester, | ||
| ` | ||
| interface Widgets { | ||
| @route("/widgets") @get list(): string[]; | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| assertFileEmitted(fs, "WidgetsController.cs"); | ||
| assertFileEmitted(fs, "IWidgets.cs"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is too azure specific, this emitter shouldn't have any reference to azure in its options and handling of things.
I think we might be better of having a generic
omit-types: string[]option which lets you exclude any types from being generated. This is still not ideal as this really should be defined with decorators but this is not something we'll have soon so this can unblock in the meantime