Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import type {
SdkBodyParameter,
SdkBuiltInKinds,
SdkContext,
SdkHeaderParameter,
SdkHttpOperation,
SdkHttpParameter,
Expand Down Expand Up @@ -41,7 +40,6 @@ import {
} from "@typespec/compiler";
import { unsafe_getEventDefinitions } from "@typespec/events/experimental";
import type { HttpStatusCodeRange } from "@typespec/http";
import { getResourceOperation } from "@typespec/rest";
import { isTerminalEvent } from "@typespec/sse";
import type { CSharpEmitterContext } from "../sdk-context.js";
import { collectionFormatToDelimMap } from "../type/collection-format.js";
Expand Down Expand Up @@ -76,7 +74,7 @@ import type { OperationResponse } from "../type/operation-response.js";
import { RequestLocation } from "../type/request-location.js";
import { parseHttpRequestMethod } from "../type/request-method.js";
import { ResponseLocation } from "../type/response-location.js";
import { getExternalDocs, getOperationId } from "./decorators.js";
import { getExternalDocs } from "./decorators.js";
import { fromSdkHttpExamples } from "./example-converter.js";
import { createDiagnostic } from "./lib.js";
import { fromSdkType } from "./type-converter.js";
Expand Down Expand Up @@ -220,10 +218,6 @@ export function fromSdkServiceMethodOperation(
operation = {
name: method.name,
isExactName: method.isExactName,
resourceName:
getResourceOperation(sdkContext.program, method.operation.__raw.operation)?.resourceType
.name ??
getOperationGroupName(sdkContext, method.operation, getClientNamespaceString(sdkContext)!),
deprecated: getDeprecated(sdkContext.program, method.__raw!),
summary: method.summary,
doc: method.doc,
Expand Down Expand Up @@ -1102,28 +1096,6 @@ function getParameterScope(
: InputParameterScope.Method;
}

function getOperationGroupName(
context: SdkContext,
operation: SdkHttpOperation,
namespace: string,
): string {
const explicitOperationId = getOperationId(context, operation.__raw.operation);
if (explicitOperationId) {
const ids: string[] = explicitOperationId.split("_");
if (ids.length > 1) {
return ids.slice(0, -2).join("_");
}
}

if (operation.__raw.operation.interface) {
return operation.__raw.operation.interface.name;
}
if (operation.__raw.operation.namespace) {
return operation.__raw.operation.namespace.name;
}
return namespace;
}

// TODO: remove after https://github.com/Azure/typespec-azure/issues/1227 is fixed
function normalizeHeaderName(name: string): string {
switch (name.toLocaleLowerCase()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { RequestMethod } from "./request-method.js";
export interface InputOperation {
name: string;
isExactName?: boolean;
resourceName?: string;
summary?: string;
deprecated?: string;
doc?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe("Operation Converter", () => {
// validate operation
const operation = root.clients[0].methods[0].operation;
ok(operation);
strictEqual("resourceName" in operation, false);
strictEqual(operation.parameters.length, 4);

// content type parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class InputOperation
{
public InputOperation(
string name,
string? resourceName,
string? summary,
string? doc,
string? deprecated,
Expand All @@ -32,7 +31,6 @@ public InputOperation(
string? ns)
{
Name = name;
ResourceName = resourceName;
Summary = summary;
Doc = doc;
Deprecated = deprecated;
Expand All @@ -53,7 +51,6 @@ public InputOperation(

public InputOperation() : this(
name: string.Empty,
resourceName: null,
summary: string.Empty,
doc: string.Empty,
deprecated: null,
Expand Down Expand Up @@ -83,7 +80,6 @@ public InputOperation() : this(
/// Gets the original name of the operation as defined in the TypeSpec before any mutations.
/// </summary>
public string? OriginalName { get; internal set; }
public string? ResourceName { get; internal set; }
public string? Summary { get; internal set; }
public string? Doc { get; internal set; }
public string? Deprecated { get; internal set; }
Expand All @@ -108,7 +104,6 @@ public InputOperation() : this(

public void Update(
string? name = null,
string? resourceName = null,
string? summary = null,
string? doc = null,
string? deprecated = null,
Expand All @@ -130,10 +125,6 @@ public void Update(
{
Name = name;
}
if (resourceName != null)
{
ResourceName = resourceName;
}
if (summary != null)
{
Summary = summary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public override void Write(Utf8JsonWriter writer, InputOperation value, JsonSeri
resolver.AddReference(id, operation);

string? name = null;
string? resourceName = null;
string? summary = null;
string? doc = null;
string? deprecated = null;
Expand All @@ -62,7 +61,6 @@ public override void Write(Utf8JsonWriter writer, InputOperation value, JsonSeri
{
var isKnownProperty = reader.TryReadString("name", ref name)
|| reader.TryReadBoolean("isExactName", ref isExactName)
|| reader.TryReadString("resourceName", ref resourceName)
|| reader.TryReadString("summary", ref summary)
|| reader.TryReadString("doc", ref doc)
|| reader.TryReadString("deprecated", ref deprecated)
Expand Down Expand Up @@ -91,7 +89,6 @@ public override void Write(Utf8JsonWriter writer, InputOperation value, JsonSeri
operation.Name = name ?? throw new JsonException("InputOperation must have name");
operation.IsExactName = isExactName;
operation.OriginalName = name;
operation.ResourceName = resourceName;
operation.Summary = summary;
operation.Doc = doc;
operation.Deprecated = deprecated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,39 @@ namespace Microsoft.TypeSpec.Generator.Input.Tests
{
public class TypeSpecInputConverterTests
{
[TestCase(false)]
[TestCase(true)]
public void LoadsOperationWithoutResourceName(bool includeLegacyResourceName)
{
var json = $$"""
{
"$id": "1",
"name": "getWidget",
{{(includeLegacyResourceName ? "\"resourceName\": \"Widget\"," : "")}}
"summary": "Gets a widget",
"httpMethod": "GET",
"uri": "https://example.com",
"path": "/widgets",
"crossLanguageDefinitionId": "Test.getWidget"
}
""";
var options = new JsonSerializerOptions
{
Converters = { new InputOperationConverter(new TypeSpecReferenceHandler()) }
};

var operation = JsonSerializer.Deserialize<InputOperation>(json, options);

Assert.IsNotNull(operation);
Assert.AreEqual("getWidget", operation!.Name);
Assert.AreEqual("Gets a widget", operation.Summary);
Assert.AreEqual("GET", operation.HttpMethod);
Assert.AreEqual("https://example.com", operation.Uri);
Assert.AreEqual("/widgets", operation.Path);
Assert.AreEqual("Test.getWidget", operation.CrossLanguageDefinitionId);
Assert.IsNull(typeof(InputOperation).GetProperty("ResourceName"));
}

[Test]
public void LoadsPagingWithNextLink()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,6 @@ public static InputOperation Operation(
{
var operation = new InputOperation(
name,
null,
"",
$"{name} description",
null,
Expand Down
Loading