Skip to content

Commit 517cf64

Browse files
CopilotJoshLove-msftCopilot
authored
[http-client-csharp] Remove unused InputOperation.ResourceName (#11973)
`InputOperation.ResourceName` is a legacy AutoRest field that no longer determines client names and has no consumers. - **Input model:** Remove the property, constructor and `Update` parameters, and deserialization handling. - **Emitter:** Stop emitting `resourceName` and remove the helper used solely to compute it. - **Compatibility:** Older code models containing `resourceName` remain readable; regression coverage verifies this and the field’s absence from emitted operations. <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #8855 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com> Co-authored-by: jolov <jolov@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc0b1381-ff7e-4957-a7cb-273c935c22d1
1 parent 0f0291e commit 517cf64

86 files changed

Lines changed: 87 additions & 932 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/http-client-csharp/emitter/src/lib/operation-converter.ts‎

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import type {
55
SdkBodyParameter,
66
SdkBuiltInKinds,
7-
SdkContext,
87
SdkHeaderParameter,
98
SdkHttpOperation,
109
SdkHttpParameter,
@@ -41,7 +40,6 @@ import {
4140
} from "@typespec/compiler";
4241
import { unsafe_getEventDefinitions } from "@typespec/events/experimental";
4342
import type { HttpStatusCodeRange } from "@typespec/http";
44-
import { getResourceOperation } from "@typespec/rest";
4543
import { isTerminalEvent } from "@typespec/sse";
4644
import type { CSharpEmitterContext } from "../sdk-context.js";
4745
import { collectionFormatToDelimMap } from "../type/collection-format.js";
@@ -76,7 +74,7 @@ import type { OperationResponse } from "../type/operation-response.js";
7674
import { RequestLocation } from "../type/request-location.js";
7775
import { parseHttpRequestMethod } from "../type/request-method.js";
7876
import { ResponseLocation } from "../type/response-location.js";
79-
import { getExternalDocs, getOperationId } from "./decorators.js";
77+
import { getExternalDocs } from "./decorators.js";
8078
import { fromSdkHttpExamples } from "./example-converter.js";
8179
import { getExperimentalDetails } from "./experimental.js";
8280
import { createDiagnostic } from "./lib.js";
@@ -221,10 +219,6 @@ export function fromSdkServiceMethodOperation(
221219
operation = {
222220
name: method.name,
223221
isExactName: method.isExactName,
224-
resourceName:
225-
getResourceOperation(sdkContext.program, method.operation.__raw.operation)?.resourceType
226-
.name ??
227-
getOperationGroupName(sdkContext, method.operation, getClientNamespaceString(sdkContext)!),
228222
deprecated: getDeprecated(sdkContext.program, method.__raw!),
229223
summary: method.summary,
230224
doc: method.doc,
@@ -1109,28 +1103,6 @@ function getParameterScope(
11091103
: InputParameterScope.Method;
11101104
}
11111105

1112-
function getOperationGroupName(
1113-
context: SdkContext,
1114-
operation: SdkHttpOperation,
1115-
namespace: string,
1116-
): string {
1117-
const explicitOperationId = getOperationId(context, operation.__raw.operation);
1118-
if (explicitOperationId) {
1119-
const ids: string[] = explicitOperationId.split("_");
1120-
if (ids.length > 1) {
1121-
return ids.slice(0, -2).join("_");
1122-
}
1123-
}
1124-
1125-
if (operation.__raw.operation.interface) {
1126-
return operation.__raw.operation.interface.name;
1127-
}
1128-
if (operation.__raw.operation.namespace) {
1129-
return operation.__raw.operation.namespace.name;
1130-
}
1131-
return namespace;
1132-
}
1133-
11341106
// TODO: remove after https://github.com/Azure/typespec-azure/issues/1227 is fixed
11351107
function normalizeHeaderName(name: string): string {
11361108
switch (name.toLocaleLowerCase()) {

‎packages/http-client-csharp/emitter/src/type/input-operation.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type { RequestMethod } from "./request-method.js";
1010
export interface InputOperation {
1111
name: string;
1212
isExactName?: boolean;
13-
resourceName?: string;
1413
summary?: string;
1514
deprecated?: string;
1615
doc?: string;

‎packages/http-client-csharp/emitter/test/Unit/operation-converter.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { TestHost } from "@typespec/compiler/testing";
22
import { ok, strictEqual } from "assert";
33
import { beforeEach, describe, it } from "vitest";
4+
import { serializeCodeModel } from "../../src/code-model-writer.js";
45
import { createModel } from "../../src/lib/client-model-builder.js";
56
import type { InputEnumType } from "../../src/type/input-type.js";
67
import { RequestLocation } from "../../src/type/request-location.js";
@@ -18,6 +19,57 @@ describe("Operation Converter", () => {
1819
runner = await createEmitterTestHost();
1920
});
2021

22+
it.each([
23+
{
24+
scope: "namespace",
25+
code: `@get @route("/widgets") op getWidget(): string;`,
26+
path: "/widgets",
27+
},
28+
{
29+
scope: "interface",
30+
code: `interface Widgets {
31+
@get @route("/widgets") getWidget(): string;
32+
}`,
33+
path: "/widgets",
34+
},
35+
{
36+
scope: "REST resource",
37+
code: `
38+
@resource("widgets")
39+
model Widget {
40+
@key id: string;
41+
}
42+
@readsResource(Widget)
43+
@get @route("/widgets/{id}")
44+
op getWidget(@path id: string): Widget;
45+
`,
46+
path: "/widgets/{id}",
47+
},
48+
])(
49+
"omits resourceName for $scope operations and serialized code models",
50+
async ({ code, path }) => {
51+
const program = await typeSpecCompile(code, runner);
52+
const context = createEmitterContext(program);
53+
const sdkContext = await createCSharpSdkContext(context);
54+
const [root] = createModel(sdkContext);
55+
strictEqual(root.clients.length, 1);
56+
const client = root.clients[0];
57+
const methods = [
58+
...client.methods,
59+
...(client.children ?? []).flatMap((child) => child.methods),
60+
];
61+
62+
strictEqual(methods.length, 1);
63+
const operation = methods[0].operation;
64+
ok(operation);
65+
strictEqual(operation.name, "getWidget");
66+
strictEqual(operation.httpMethod, "GET");
67+
strictEqual(operation.path, path);
68+
strictEqual("resourceName" in operation, false);
69+
strictEqual(serializeCodeModel(sdkContext, root).includes('"resourceName"'), false);
70+
},
71+
);
72+
2173
describe("Operation with embedded non-body parameters in request body", () => {
2274
describe("With header in request model", () => {
2375
it("Header parameter in model should not be present in service method", async () => {
@@ -62,6 +114,7 @@ describe("Operation Converter", () => {
62114
// validate operation
63115
const operation = root.clients[0].methods[0].operation;
64116
ok(operation);
117+
strictEqual("resourceName" in operation, false);
65118
strictEqual(operation.parameters.length, 4);
66119

67120
// content type parameter

‎packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/InputOperation.cs‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class InputOperation
1313
{
1414
public InputOperation(
1515
string name,
16-
string? resourceName,
1716
string? summary,
1817
string? doc,
1918
string? deprecated,
@@ -32,7 +31,6 @@ public InputOperation(
3231
string? ns)
3332
{
3433
Name = name;
35-
ResourceName = resourceName;
3634
Summary = summary;
3735
Doc = doc;
3836
Deprecated = deprecated;
@@ -53,7 +51,6 @@ public InputOperation(
5351

5452
public InputOperation() : this(
5553
name: string.Empty,
56-
resourceName: null,
5754
summary: string.Empty,
5855
doc: string.Empty,
5956
deprecated: null,
@@ -83,7 +80,6 @@ public InputOperation() : this(
8380
/// Gets the original name of the operation as defined in the TypeSpec before any mutations.
8481
/// </summary>
8582
public string? OriginalName { get; internal set; }
86-
public string? ResourceName { get; internal set; }
8783
public string? Summary { get; internal set; }
8884
public string? Doc { get; internal set; }
8985
public string? Deprecated { get; internal set; }
@@ -109,7 +105,6 @@ public InputOperation() : this(
109105

110106
public void Update(
111107
string? name = null,
112-
string? resourceName = null,
113108
string? summary = null,
114109
string? doc = null,
115110
string? deprecated = null,
@@ -132,10 +127,6 @@ public void Update(
132127
{
133128
Name = name;
134129
}
135-
if (resourceName != null)
136-
{
137-
ResourceName = resourceName;
138-
}
139130
if (summary != null)
140131
{
141132
Summary = summary;

‎packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/InputOperationConverter.cs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public override void Write(Utf8JsonWriter writer, InputOperation value, JsonSeri
3737
resolver.AddReference(id, operation);
3838

3939
string? name = null;
40-
string? resourceName = null;
4140
string? summary = null;
4241
string? doc = null;
4342
string? deprecated = null;
@@ -63,7 +62,6 @@ public override void Write(Utf8JsonWriter writer, InputOperation value, JsonSeri
6362
{
6463
var isKnownProperty = reader.TryReadString("name", ref name)
6564
|| reader.TryReadBoolean("isExactName", ref isExactName)
66-
|| reader.TryReadString("resourceName", ref resourceName)
6765
|| reader.TryReadString("summary", ref summary)
6866
|| reader.TryReadString("doc", ref doc)
6967
|| reader.TryReadString("deprecated", ref deprecated)
@@ -93,7 +91,6 @@ public override void Write(Utf8JsonWriter writer, InputOperation value, JsonSeri
9391
operation.Name = name ?? throw new JsonException("InputOperation must have name");
9492
operation.IsExactName = isExactName;
9593
operation.OriginalName = name;
96-
operation.ResourceName = resourceName;
9794
operation.Summary = summary;
9895
operation.Doc = doc;
9996
operation.Deprecated = deprecated;

‎packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/test/TypeSpecInputConverterTests.cs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,39 @@ namespace Microsoft.TypeSpec.Generator.Input.Tests
1010
{
1111
public class TypeSpecInputConverterTests
1212
{
13+
[TestCase(false)]
14+
[TestCase(true)]
15+
public void LoadsOperationWithoutResourceName(bool includeLegacyResourceName)
16+
{
17+
var json = $$"""
18+
{
19+
"$id": "1",
20+
"name": "getWidget",
21+
{{(includeLegacyResourceName ? "\"resourceName\": \"Widget\"," : "")}}
22+
"summary": "Gets a widget",
23+
"httpMethod": "GET",
24+
"uri": "https://example.com",
25+
"path": "/widgets",
26+
"crossLanguageDefinitionId": "Test.getWidget"
27+
}
28+
""";
29+
var options = new JsonSerializerOptions
30+
{
31+
Converters = { new InputOperationConverter(new TypeSpecReferenceHandler()) }
32+
};
33+
34+
var operation = JsonSerializer.Deserialize<InputOperation>(json, options);
35+
36+
Assert.IsNotNull(operation);
37+
Assert.AreEqual("getWidget", operation!.Name);
38+
Assert.AreEqual("Gets a widget", operation.Summary);
39+
Assert.AreEqual("GET", operation.HttpMethod);
40+
Assert.AreEqual("https://example.com", operation.Uri);
41+
Assert.AreEqual("/widgets", operation.Path);
42+
Assert.AreEqual("Test.getWidget", operation.CrossLanguageDefinitionId);
43+
Assert.IsNull(typeof(InputOperation).GetProperty("ResourceName"));
44+
}
45+
1346
[TestCase("model", "\"properties\": []")]
1447
[TestCase("enum", "\"values\": [], \"valueType\": {\"kind\":\"string\"}")]
1548
[TestCase("string", "\"crossLanguageDefinitionId\": \"External.Value\"")]

‎packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/common/InputFactory.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,6 @@ public static InputOperation Operation(
762762
{
763763
var operation = new InputOperation(
764764
name,
765-
null,
766765
"",
767766
$"{name} description",
768767
null,

0 commit comments

Comments
 (0)