Skip to content

Commit

Permalink
refactor(http-client-csharp): dump deprecated description properties (
Browse files Browse the repository at this point in the history
#5154)

- emitter: replace all `description` properties of input types with
`summary` and `doc`
- generator:
  - update json converters for the emitter schema change
- only expose `Summary` and `Doc` properties if they are used by other
classes
- update test cases accordingly

part of #4771

---------

Co-authored-by: Mingzhe Huang (from Dev Box) <[email protected]>
Co-authored-by: Chenjie Shi <[email protected]>
Co-authored-by: Weidong Xu <[email protected]>
Co-authored-by: Wei Hu <[email protected]>
Co-authored-by: Pan Shao <[email protected]>
Co-authored-by: Pan Shao <[email protected]>
Co-authored-by: Christopher Radek <[email protected]>
Co-authored-by: Christopher Radek <[email protected]>
Co-authored-by: iscai-msft <[email protected]>
Co-authored-by: iscai-msft <[email protected]>
Co-authored-by: Jorge Rangel <[email protected]>
Co-authored-by: Jesse Squire <[email protected]>
Co-authored-by: Allen Zhang <[email protected]>
Co-authored-by: Mike Harder <[email protected]>
Co-authored-by: Will Temple <[email protected]>
Co-authored-by: Will Temple <[email protected]>
Co-authored-by: JoshLove-msft <[email protected]>
Co-authored-by: Xiaofei Cao <[email protected]>
Co-authored-by: Sarangan Rajamanickam <[email protected]>
Co-authored-by: Adam O'Brien <[email protected]>
Co-authored-by: Mark Cowlishaw <[email protected]>
Co-authored-by: Yuchao Yan <[email protected]>
Co-authored-by: mcgallan <[email protected]>
Co-authored-by: msyyc <[email protected]>
Co-authored-by: Tomer Aberbach <[email protected]>
Co-authored-by: Rodge Fu <[email protected]>
Co-authored-by: Zhonglei Ma <[email protected]>
Co-authored-by: Dapeng Zhang <[email protected]>
Co-authored-by: Praven Kuttappan <[email protected]>
Co-authored-by: Nisha Bhatia <[email protected]>
Co-authored-by: Alan Zimmer <[email protected]>
Co-authored-by: Laurent Mazuel <[email protected]>
Co-authored-by: Crystal YU <[email protected]>
  • Loading branch information
1 parent ad6088b commit 4225733
Show file tree
Hide file tree
Showing 111 changed files with 1,706 additions and 1,610 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export function createModel(sdkContext: SdkContext<NetEmitterOptions>): CodeMode
const clientParameters = fromSdkEndpointParameter(endpointParameter);
return {
Name: getClientName(client, parentNames),
Description: client.summary ?? client.doc,
Summary: client.summary,
Doc: client.doc,
Operations: client.methods
.filter((m) => m.kind !== "clientaccessor")
.map((m) =>
Expand Down Expand Up @@ -156,7 +157,8 @@ export function createModel(sdkContext: SdkContext<NetEmitterOptions>): CodeMode
parameters.push({
Name: parameter.name,
NameInRequest: parameter.serializedName,
Description: parameter.doc,
Summary: parameter.summary,
Doc: parameter.doc,
// TODO: we should do the magic in generator
Type: parameterType,
Location: RequestLocation.Uri,
Expand Down
16 changes: 10 additions & 6 deletions packages/http-client-csharp/emitter/src/lib/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export function fromSdkModelType(
) /* when tcgc provide a way to identify if the access is override or not, we can get the accessibility from the modelType.access */,
usage: modelType.usage,
deprecation: modelType.deprecation,
description: modelType.summary ?? modelType.doc,
doc: modelType.doc,
summary: modelType.summary,
discriminatorValue: modelType.discriminatorValue,
decorators: modelType.decorators,
} as InputModelType;
Expand Down Expand Up @@ -185,7 +186,8 @@ export function fromSdkModelType(
kind: property.kind,
name: property.name,
serializedName: serializedName,
description: property.summary ?? property.doc,
summary: property.summary,
doc: property.doc,
type: fromSdkType(
targetType,
context,
Expand Down Expand Up @@ -225,7 +227,8 @@ export function fromSdkEnumType(
enumType.__raw as any,
) /* when tcgc provide a way to identify if the access is override or not, we can get the accessibility from the enumType.access,*/,
deprecation: enumType.deprecation,
description: enumType.summary ?? enumType.doc,
summary: enumType.summary,
doc: enumType.doc,
isFixed: enumType.isFixed,
isFlags: enumType.isFlags,
usage: enumType.usage,
Expand Down Expand Up @@ -337,7 +340,7 @@ function fromSdkConstantType(
values: values,
crossLanguageDefinitionId: "",
access: undefined,
description: `The ${enumName}`, // TODO -- what should we put here?
doc: `The ${enumName}`, // TODO -- what should we put here?
isFixed: false,
isFlags: false,
usage: literalTypeContext.Usage,
Expand All @@ -350,7 +353,7 @@ function fromSdkConstantType(
kind: "enumvalue",
name: enumValueName,
value: constantType.value as string | number,
description: enumValueName,
doc: enumValueName,
valueType: enumType.valueType,
enumType: enumType,
});
Expand Down Expand Up @@ -386,7 +389,8 @@ function fromSdkEnumValueType(
value: enumValueType.value,
valueType: fromSdkBuiltInType(enumValueType.valueType),
enumType: fromSdkEnumType(enumValueType.enumType, context, typeMap),
description: enumValueType.summary ?? enumValueType.doc,
summary: enumValueType.summary,
doc: enumValueType.doc,
decorators: enumValueType.decorators,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { InputOperation } from "../type/input-operation.js";
import { InputParameter } from "../type/input-parameter.js";
import { InputType } from "../type/input-type.js";
import { convertLroFinalStateVia } from "../type/operation-final-state-via.js";
import { OperationLongRunning } from "../type/operation-long-running.js";
import { OperationPaging } from "../type/operation-paging.js";
import { OperationResponse } from "../type/operation-response.js";
import { RequestLocation } from "../type/request-location.js";
Expand Down Expand Up @@ -75,7 +76,7 @@ export function fromSdkServiceMethod(
getOperationGroupName(sdkContext, method.operation, sdkContext.sdkPackage.rootNamespace),
Deprecated: getDeprecated(sdkContext.program, method.__raw!),
Summary: method.summary,
Description: method.doc,
Doc: method.doc,
Accessibility: method.access,
Parameters: [...parameterMap.values()],
Responses: [...responseMap.values()],
Expand Down Expand Up @@ -189,7 +190,8 @@ function fromSdkHttpOperationParameter(
return {
Name: p.name,
NameInRequest: p.kind === "header" ? normalizeHeaderName(serializedName) : serializedName,
Description: p.summary ?? p.doc,
Summary: p.summary,
Doc: p.doc,
Type: parameterType,
Location: getParameterLocation(p),
IsApiVersion:
Expand All @@ -210,7 +212,7 @@ function loadLongRunningOperation(
method: SdkServiceMethod<SdkHttpOperation>,
sdkContext: SdkContext<NetEmitterOptions>,
typeMap: SdkTypeMap,
): import("../type/operation-long-running.js").OperationLongRunning | undefined {
): OperationLongRunning | undefined {
if (method.kind !== "lro") {
return undefined;
}
Expand Down Expand Up @@ -260,7 +262,8 @@ function fromSdkServiceResponseHeaders(
({
Name: h.__raw!.name,
NameInResponse: h.serializedName,
Description: h.summary ?? h.doc,
Summary: h.summary,
Doc: h.doc,
Type: fromSdkType(h.type, sdkContext, typeMap),
}) as HttpResponseHeader,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

import { SdkContext } from "@azure-tools/typespec-client-generator-core";
import { getDoc } from "@typespec/compiler";
import { getDoc, getSummary } from "@typespec/compiler";
import { HttpServer } from "@typespec/http";
import { getExtensions } from "@typespec/openapi";
import { NetEmitterOptions } from "../options.js";
Expand Down Expand Up @@ -50,7 +50,8 @@ export function resolveServers(
const variable: InputParameter = {
Name: name,
NameInRequest: name,
Description: getDoc(context.program, prop),
Summary: getSummary(context.program, prop),
Doc: getDoc(context.program, prop),
Type: inputType,
Location: RequestLocation.Uri,
IsApiVersion: name.toLowerCase() === "apiversion" || name.toLowerCase() === "api-version",
Expand All @@ -73,7 +74,7 @@ export function resolveServers(
const variable: InputParameter = {
Name: "host",
NameInRequest: "host",
Description: server.description,
Doc: server.description,
Type: {
kind: "string",
name: "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { InputType } from "./input-type.js";
export interface HttpResponseHeader {
Name: string;
NameInResponse: string;
Description: string;
Summary: string;
Doc: string;
Type: InputType;
}
3 changes: 2 additions & 1 deletion packages/http-client-csharp/emitter/src/type/input-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { Protocols } from "./protocols.js";

export interface InputClient {
Name: string;
Description?: string;
Summary?: string;
Doc?: string;
Operations: InputOperation[];
Protocol?: Protocols;
Parent?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface InputOperation {
ResourceName?: string;
Summary?: string;
Deprecated?: string;
Description?: string;
Doc?: string;
Accessibility?: string;
Parameters: InputParameter[];
Responses: OperationResponse[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export interface VirtualParameter {}
export interface InputParameter {
Name: string;
NameInRequest: string;
Description?: string;
Summary?: string;
Doc?: string;
Type: InputType;
Location: RequestLocation;
DefaultValue?: InputConstant;
Expand Down
3 changes: 2 additions & 1 deletion packages/http-client-csharp/emitter/src/type/input-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { DateTimeKnownEncoding, DurationKnownEncoding } from "@typespec/compiler

interface InputTypeBase {
kind: string;
description?: string;
summary?: string;
doc?: string;
deprecation?: string;
decorators?: DecoratorInfo[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ op test(@body input: Pet): Pet;
const discriminatorProperty = pet?.properties.find((p) => p === pet?.discriminatorProperty);
strictEqual(discriminatorProperty?.name, "kind");
strictEqual(discriminatorProperty.serializedName, "kind");
strictEqual(discriminatorProperty.description, "The kind of the pet");
strictEqual(discriminatorProperty.doc, "The kind of the pet");
strictEqual(discriminatorProperty.type.kind, "enum");
strictEqual(discriminatorProperty.type.name, "PetKind");
strictEqual(discriminatorProperty.type.valueType.kind, "string");
Expand Down Expand Up @@ -234,7 +234,7 @@ op test(@body input: Pet): Pet;
const discriminatorProperty = pet?.properties.find((p) => p === pet?.discriminatorProperty);
strictEqual(discriminatorProperty?.name, "kind");
strictEqual(discriminatorProperty.serializedName, "kind");
strictEqual(discriminatorProperty.description, "The kind of the pet");
strictEqual(discriminatorProperty.doc, "The kind of the pet");
strictEqual(discriminatorProperty.type.kind, "enum");
strictEqual(discriminatorProperty.type.name, "PetKind");
strictEqual(discriminatorProperty.type.valueType.kind, "string");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe("Test GetInputType for enum", () => {
strictEqual(type.kind, "enum");
strictEqual(type.name, "SimpleEnum");
strictEqual(type.isFixed, true);
strictEqual(type.description, "fixed string enum");
strictEqual(type.doc, "fixed string enum");
strictEqual(type.crossLanguageDefinitionId, "Azure.Csharp.Testing.SimpleEnum");
strictEqual(type.access, undefined);
strictEqual(type.valueType.kind, "string");
Expand Down Expand Up @@ -142,7 +142,7 @@ describe("Test GetInputType for enum", () => {
strictEqual(type.name, "FixedIntEnum");
strictEqual(type.crossLanguageDefinitionId, "Azure.Csharp.Testing.FixedIntEnum");
strictEqual(type.access, undefined);
strictEqual(type.description, "Fixed int enum");
strictEqual(type.doc, "Fixed int enum");
strictEqual(type.valueType.crossLanguageDefinitionId, "TypeSpec.int32");
strictEqual(type.valueType.kind, "int32");
strictEqual(type.values.length, 3);
Expand Down Expand Up @@ -181,7 +181,7 @@ describe("Test GetInputType for enum", () => {
strictEqual(type.name, "FixedEnum");
strictEqual(type.crossLanguageDefinitionId, "Azure.Csharp.Testing.FixedEnum");
strictEqual(type.access, undefined);
strictEqual(type.description, "Fixed enum");
strictEqual(type.doc, "Fixed enum");
strictEqual(type.valueType.kind, "string");
strictEqual(type.valueType.crossLanguageDefinitionId, "TypeSpec.string");
strictEqual(type.values.length, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using Microsoft.Generator.CSharp.Input;
using Microsoft.Generator.CSharp.Primitives;
using Microsoft.Generator.CSharp.Providers;
using Microsoft.Generator.CSharp.Utilities;
using static Microsoft.Generator.CSharp.Snippets.Snippet;
using System.ClientModel.Primitives;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
{
Expand Down Expand Up @@ -125,9 +125,10 @@ protected override PropertyProvider[] BuildProperties()
if (!p.IsEndpoint && !p.IsApiVersion && p.DefaultValue != null)
{
FormattableString? description = null;
if (p.Description != null)
var parameterDescription = DocHelpers.GetDescription(p.Summary, p.Doc);
if (parameterDescription is not null)
{
description = $"{p.Description}";
description = $"{parameterDescription}";
}

var type = ClientModelPlugin.Instance.TypeFactory.CreateCSharpType(p.Type)?.PropertyInitializationType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ private static IReadOnlyList<ParameterProvider> BuildSpreadParametersForModel(In
var inputParameter = new InputParameter(
property.Name,
property.SerializedName,
property.Description,
property.Summary,
property.Doc,
property.Type,
RequestLocation.Body,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.Generator.CSharp.Providers;
using Microsoft.Generator.CSharp.Snippets;
using Microsoft.Generator.CSharp.Statements;
using Microsoft.Generator.CSharp.Utilities;
using static Microsoft.Generator.CSharp.Snippets.Snippet;

namespace Microsoft.Generator.CSharp.ClientModel.Providers
Expand Down Expand Up @@ -71,7 +72,7 @@ private ScmMethodProvider BuildConvenienceMethod(MethodProvider protocolMethod,

var methodSignature = new MethodSignature(
isAsync ? _cleanOperationName + "Async" : _cleanOperationName,
FormattableStringHelpers.FromString(Operation.Description),
DocHelpers.GetFormattableDescription(Operation.Summary, Operation.Doc) ?? FormattableStringHelpers.FromString(Operation.Name),
methodModifier,
GetResponseType(Operation.Responses, true, isAsync, out var responseBodyType),
null,
Expand Down Expand Up @@ -421,7 +422,7 @@ private ScmMethodProvider BuildProtocolMethod(MethodProvider createRequestMethod

var methodSignature = new MethodSignature(
isAsync ? _cleanOperationName + "Async" : _cleanOperationName,
FormattableStringHelpers.FromString(Operation.Description),
DocHelpers.GetFormattableDescription(Operation.Summary, Operation.Doc) ?? FormattableStringHelpers.FromString(Operation.Name),
methodModifier,
GetResponseType(Operation.Responses, false, isAsync, out _),
$"The response returned from the service.",
Expand All @@ -447,7 +448,7 @@ private ScmMethodProvider BuildProtocolMethod(MethodProvider createRequestMethod
new XmlDocStatement("item", [], new XmlDocStatement("description", [$"This <see href=\"https://aka.ms/azsdk/net/protocol-methods\">protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios."]))
];
XmlDocStatement listXmlDoc = new XmlDocStatement("<list type=\"bullet\">", "</list>", [], innerStatements: [.. listItems]);
protocolMethod.XmlDocs!.Summary = new XmlDocSummaryStatement([$"[Protocol Method] {Operation.Description}"], listXmlDoc);
protocolMethod.XmlDocs!.Summary = new XmlDocSummaryStatement([$"[Protocol Method] {DocHelpers.GetDescription(Operation.Summary, Operation.Doc) ?? Operation.Name}"], listXmlDoc);
}
return protocolMethod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests.Providers.ClientProviders
public class ClientProviderSubClientTests
{
private const string TestClientName = "TestClient";
private static readonly InputClient _animalClient = new("animal", "AnimalClient description", [], [], TestClientName);
private static readonly InputClient _dogClient = new("dog", "DogClient description", [], [], _animalClient.Name);
private static readonly InputClient _catClient = new("cat", "CatClient description", [], [], _animalClient.Name);
private static readonly InputClient _hawkClient = new("hawkClient", "HawkClient description", [], [], _animalClient.Name);
private static readonly InputClient _huskyClient = new("husky", "HuskyClient description", [], [], _dogClient.Name);
private static readonly InputClient _animalClient = new("animal", string.Empty, "AnimalClient description", [], [], TestClientName);
private static readonly InputClient _dogClient = new("dog", string.Empty, "DogClient description", [], [], _animalClient.Name);
private static readonly InputClient _catClient = new("cat", string.Empty, "CatClient description", [], [], _animalClient.Name);
private static readonly InputClient _hawkClient = new("hawkClient", string.Empty, "HawkClient description", [], [], _animalClient.Name);
private static readonly InputClient _huskyClient = new("husky", string.Empty, "HuskyClient description", [], [], _dogClient.Name);

[SetUp]
public void SetUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class ClientProviderTests
private const string KeyAuthCategory = "WithKeyAuth";
private const string OAuth2Category = "WithOAuth2";
private const string TestClientName = "TestClient";
private static readonly InputClient _animalClient = new("animal", "AnimalClient description", [], [], TestClientName);
private static readonly InputClient _dogClient = new("dog", "DogClient description", [], [], _animalClient.Name);
private static readonly InputClient _huskyClient = new("husky", "HuskyClient description", [], [], _dogClient.Name);
private static readonly InputClient _animalClient = new("animal", "", "AnimalClient description", [], [], TestClientName);
private static readonly InputClient _dogClient = new("dog", "", "DogClient description", [], [], _animalClient.Name);
private static readonly InputClient _huskyClient = new("husky", "", "HuskyClient description", [], [], _dogClient.Name);
private static readonly InputModelType _spreadModel = InputFactory.Model(
"spreadModel",
usage: InputModelTypeUsage.Spread,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,10 @@ public void TestIntSerializationStatement(
var name = kind.ToString().ToLower();
var properties = new List<InputModelProperty>
{
new InputModelProperty("requiredInt", "requiredInt", "", new InputPrimitiveType(kind, name, $"TypeSpec.{name}", encode), true, false, false),
new InputModelProperty("requiredInt", "requiredInt", "", "", new InputPrimitiveType(kind, name, $"TypeSpec.{name}", encode), true, false, false),
};

var inputModel = new InputModelType("TestModel", "TestModel", "public", null, "Test model.", InputModelTypeUsage.Input, properties, null, Array.Empty<InputModelType>(), null, null, new Dictionary<string, InputModelType>(), null, false);
var inputModel = new InputModelType("TestModel", "TestModel", "public", null, "", "Test model.", InputModelTypeUsage.Input, properties, null, Array.Empty<InputModelType>(), null, null, new Dictionary<string, InputModelType>(), null, false);

var (_, serialization) = CreateModelAndSerialization(inputModel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ public class InputClient
private readonly string? _key;
private IReadOnlyDictionary<string, InputClientExample>? _examples;

public InputClient(string name, string description, IReadOnlyList<InputOperation> operations, IReadOnlyList<InputParameter> parameters, string? parent)
public InputClient(string name, string? summary, string? doc, IReadOnlyList<InputOperation> operations, IReadOnlyList<InputParameter> parameters, string? parent)
{
Name = name;
Description = description;
Summary = summary;
Doc = doc;
Operations = operations;
Parameters = parameters;
Parent = parent;
}

public InputClient() : this(string.Empty, string.Empty, Array.Empty<InputOperation>(), Array.Empty<InputParameter>(), null) { }
public InputClient() : this(string.Empty, string.Empty, string.Empty, Array.Empty<InputOperation>(), Array.Empty<InputParameter>(), null) { }

public string Name { get; internal set; }
public string Description { get; internal set; }
public string? Summary { get; internal set; }
public string? Doc { get; internal set; }
public IReadOnlyList<InputOperation> Operations { get; internal set; }
public IReadOnlyList<InputParameter> Parameters { get; internal set; }
public string? Parent { get; internal set; }
Expand Down
Loading

0 comments on commit 4225733

Please sign in to comment.