From 50c622c73b858b236907a953a82199a84573129b Mon Sep 17 00:00:00 2001 From: tadelesh Date: Thu, 15 Aug 2024 14:04:49 +0800 Subject: [PATCH 1/8] wip --- .../src/interfaces.ts | 45 +++++++++++++++++++ .../src/package.ts | 4 ++ .../src/types.ts | 24 ++++++++++ 3 files changed, 73 insertions(+) diff --git a/packages/typespec-client-generator-core/src/interfaces.ts b/packages/typespec-client-generator-core/src/interfaces.ts index 772e1fbf3e..9a026ceb45 100644 --- a/packages/typespec-client-generator-core/src/interfaces.ts +++ b/packages/typespec-client-generator-core/src/interfaces.ts @@ -94,8 +94,16 @@ export interface SdkClientType extends DecoratedType { kind: "client"; name: string; + /** + * @deprecated Use `doc` and `summary` instead. + */ description?: string; + /** + * @deprecated Use `doc` and `summary` instead. + */ details?: string; + doc?: string; + summary?: string; initialization: SdkInitializationType; methods: SdkMethod[]; apiVersions: string[]; @@ -134,8 +142,16 @@ interface SdkTypeBase extends DecoratedType { __raw?: Type; kind: string; deprecation?: string; + /** + * @deprecated Use `doc` and `summary` instead. + */ description?: string; + /** + * @deprecated Use `doc` and `summary` instead. + */ details?: string; + doc?: string; + summary?: string; } export type SdkType = @@ -406,8 +422,16 @@ export interface SdkModelPropertyTypeBase extends DecoratedType { type: SdkType; name: string; isGeneratedName: boolean; + /** + * @deprecated Use `doc` and `summary` instead. + */ description?: string; + /** + * @deprecated Use `doc` and `summary` instead. + */ details?: string; + doc?: string; + summary?: string; apiVersions: string[]; onClient: boolean; clientDefaultValue?: any; @@ -512,8 +536,16 @@ export interface SdkServiceResponseHeader { __raw: ModelProperty; serializedName: string; type: SdkType; + /** + * @deprecated Use `doc` and `summary` instead. + */ description?: string; + /** + * @deprecated Use `doc` and `summary` instead. + */ details?: string; + doc?: string; + summary?: string; } export interface SdkMethodResponse { @@ -533,7 +565,12 @@ export interface SdkHttpResponse extends SdkServiceResponse { kind: "http"; contentTypes?: string[]; defaultContentType?: string; + /** + * @deprecated Use `doc` and `summary` instead. + */ description?: string; + doc?: string; + summary?: string; } interface SdkServiceOperationBase {} @@ -565,8 +602,16 @@ interface SdkMethodBase extends DecoratedType { access: AccessFlags; parameters: SdkParameter[]; apiVersions: string[]; + /** + * @deprecated Use `doc` and `summary` instead. + */ description?: string; + /** + * @deprecated Use `doc` and `summary` instead. + */ details?: string; + doc?: string; + summary?: string; crossLanguageDefintionId: string; } diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index c2860f71f2..f7dfb1e22d 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -2,8 +2,10 @@ import { getLroMetadata, getPagedResult } from "@azure-tools/typespec-azure-core import { createDiagnosticCollector, Diagnostic, + getDoc, getNamespaceFullName, getService, + getSummary, ignoreDiagnostics, Operation, Type, @@ -562,6 +564,8 @@ function createSdkClientType( name, description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, client.type), + summary: getSummary(context.program, client.type), methods: [], apiVersions: context.__tspTypeToApiVersions.get(client.type)!, nameSpace: getClientNamespaceStringHelper(context, client.service)!, diff --git a/packages/typespec-client-generator-core/src/types.ts b/packages/typespec-client-generator-core/src/types.ts index d08e2a2de3..179916bd3d 100644 --- a/packages/typespec-client-generator-core/src/types.ts +++ b/packages/typespec-client-generator-core/src/types.ts @@ -21,9 +21,11 @@ import { Union, createDiagnosticCollector, getDiscriminator, + getDoc, getEncode, getFormat, getKnownValues, + getSummary, getVisibility, ignoreDiagnostics, isErrorModel, @@ -258,6 +260,8 @@ function getSdkBuiltInTypeWithDiagnostics( encode: getEncodeHelper(context, type, kind), description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, type), + summary: getSummary(context.program, type), baseType: type.baseScalar && !context.program.checker.isStdType(type) // we only calculate the base type when this type has a base type and this type is not a std type because for std types there is no point of calculating its base type. ? diagnostics.pipe(getSdkBuiltInTypeWithDiagnostics(context, type.baseScalar, kind)) @@ -328,6 +332,8 @@ function getSdkDateTimeType( baseType: baseType, description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, type), + summary: getSummary(context.program, type), crossLanguageDefinitionId: getCrossLanguageDefinitionId(context, type), }); } @@ -427,6 +433,8 @@ function getSdkDurationTypeWithDiagnostics( baseType: baseType, description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, type), + summary: getSummary(context.program, type), crossLanguageDefinitionId: getCrossLanguageDefinitionId(context, type), }); } @@ -674,6 +682,7 @@ function addDiscriminatorToModelType( model.properties.splice(0, 0, { kind: "property", description: `Discriminator property for ${model.name}.`, + doc: `Discriminator property for ${model.name}.`, optional: false, discriminator: true, serializedName: discriminatorProperty @@ -725,6 +734,8 @@ export function getSdkModelWithDiagnostics( isGeneratedName: !type.name, description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, type), + summary: getSummary(context.program, type), properties: [], additionalProperties: undefined, // going to set additional properties in the next few lines when we look at base model access: "public", @@ -834,6 +845,8 @@ function getSdkEnumValueWithDiagnostics( value: type.value ?? type.name, description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, type), + summary: getSummary(context.program, type), enumType, valueType: enumType.valueType, }); @@ -858,6 +871,8 @@ function getSdkEnumWithDiagnostics( isGeneratedName: false, description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, type), + summary: getSummary(context.program, type), valueType: diagnostics.pipe(getSdkEnumValueType(context, type.members.values())), values: [], isFixed: true, // enums are always fixed after we switch to use union to represent extensible enum @@ -893,6 +908,8 @@ function getSdkUnionEnumValues( name: name ? name : `${member.value}`, description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, member.type), + summary: getSummary(context.program, member.type), value: member.value, valueType: enumType.valueType, enumType, @@ -922,6 +939,8 @@ export function getSdkUnionEnumWithDiagnostics( isGeneratedName: !type.union.name, description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, union), + summary: getSummary(context.program, union), valueType: diagnostics.pipe(getUnionAsEnumValueType(context, type.union)) ?? diagnostics.pipe(getSdkEnumValueType(context, type.flattenedMembers.values())), @@ -963,6 +982,8 @@ function getKnownValuesEnum( isGeneratedName: false, description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, type), + summary: getSummary(context.program, type), valueType: diagnostics.pipe(getSdkEnumValueType(context, knownValues.members.values())), values: [], isFixed: false, @@ -1145,6 +1166,7 @@ export function getSdkCredentialParameter( name, isGeneratedName: true, description: "Credential used to authenticate requests to the service.", + doc: "Credential used to authenticate requests to the service.", apiVersions: getAvailableApiVersions(context, client.service, client.type), onClient: true, optional: false, @@ -1175,6 +1197,8 @@ export function getSdkModelPropertyTypeBase( __raw: type, description: docWrapper.description, details: docWrapper.details, + doc: getDoc(context.program, type), + summary: getSummary(context.program, type), apiVersions, type: propertyType, name, From 5e0495b98bc6d730488b50fbe09679b29725109b Mon Sep 17 00:00:00 2001 From: tadelesh Date: Thu, 15 Aug 2024 14:36:32 +0800 Subject: [PATCH 2/8] add raw doc and summary from typespec --- .../src/http.ts | 7 ++++++ .../src/interfaces.ts | 5 ----- .../src/package.ts | 19 +++++++++++----- .../test/package.test.ts | 4 ++-- .../test/public-utils.test.ts | 1 - .../types/body-model-property-types.test.ts | 1 - .../test/types/built-in-types.test.ts | 7 +++--- .../test/types/date-time-types.test.ts | 6 +++-- .../test/types/duration-type.test.ts | 6 +++-- .../test/types/model-types.test.ts | 22 ++++++++++++------- .../test/types/multipart-types.test.ts | 11 +++++----- 11 files changed, 54 insertions(+), 35 deletions(-) diff --git a/packages/typespec-client-generator-core/src/http.ts b/packages/typespec-client-generator-core/src/http.ts index 476118455e..51224798c6 100644 --- a/packages/typespec-client-generator-core/src/http.ts +++ b/packages/typespec-client-generator-core/src/http.ts @@ -4,6 +4,8 @@ import { Operation, Type, createDiagnosticCollector, + getDoc, + getSummary, ignoreDiagnostics, isErrorModel, } from "@typespec/compiler"; @@ -159,6 +161,8 @@ function getSdkHttpParameters( isGeneratedName: true, description: getDocHelper(context, tspBody.type).description, details: getDocHelper(context, tspBody.type).details, + doc: getDoc(context.program, tspBody.type), + summary: getSummary(context.program, tspBody.type), onClient: false, contentTypes: [], defaultContentType: "application/json", // actual content type info is added later @@ -188,6 +192,7 @@ function getSdkHttpParameters( const contentTypeBase = { ...createContentTypeOrAcceptHeader(context, httpOperation, retval.bodyParam), description: `Body parameter's content type. Known values are ${retval.bodyParam.contentTypes}`, + doc: `Body parameter's content type. Known values are ${retval.bodyParam.contentTypes}`, }; if (!methodParameters.some((m) => m.name === "contentType")) { methodParameters.push({ @@ -394,6 +399,8 @@ function getSdkHttpResponseAndExceptions( __raw: header, description: getDocHelper(context, header).description, details: getDocHelper(context, header).details, + doc: getDoc(context.program, header), + summary: getSummary(context.program, header), serializedName: getHeaderFieldName(context.program, header), type: clientType, }); diff --git a/packages/typespec-client-generator-core/src/interfaces.ts b/packages/typespec-client-generator-core/src/interfaces.ts index 9a026ceb45..b12fcff803 100644 --- a/packages/typespec-client-generator-core/src/interfaces.ts +++ b/packages/typespec-client-generator-core/src/interfaces.ts @@ -565,12 +565,7 @@ export interface SdkHttpResponse extends SdkServiceResponse { kind: "http"; contentTypes?: string[]; defaultContentType?: string; - /** - * @deprecated Use `doc` and `summary` instead. - */ description?: string; - doc?: string; - summary?: string; } interface SdkServiceOperationBase {} diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index f7dfb1e22d..6a584b67f0 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -135,12 +135,12 @@ function getSdkPagingServiceMethod( - context, - pagedMetadata.nextLinkOperation, - basic.parameters - ) + getSdkServiceOperation( + context, + pagedMetadata.nextLinkOperation, + basic.parameters ) + ) : undefined, getResponseMapping(): string | undefined { return basic.response.resultPath; @@ -257,6 +257,8 @@ function getSdkBasicServiceMethod parameters: methodParameters, description: getDocHelper(context, operation).description, details: getDocHelper(context, operation).details, + doc: getDoc(context.program, operation), + summary: getSummary(context.program, operation), operation: serviceOperation, response, apiVersions, @@ -340,6 +342,7 @@ function getSdkInitializationType( return diagnostics.wrap({ __raw: client.service, description: "Initialization class for the client", + doc: "Initialization class for the client", kind: "model", properties, name, @@ -370,6 +373,8 @@ function getSdkMethodParameter( kind: "method", description: getDocHelper(context, type).description, details: getDocHelper(context, type).details, + doc: getDoc(context.program, type), + summary: getSummary(context.program, type), apiVersions, type: propertyType, name, @@ -411,6 +416,8 @@ function getSdkMethods( name, description: getDocHelper(context, operationGroup.type).description, details: getDocHelper(context, operationGroup.type).details, + doc: getDoc(context.program, operationGroup.type), + summary: getSummary(context.program, operationGroup.type), access: "internal", response: operationGroupClient, apiVersions: getAvailableApiVersions(context, operationGroup.type, client.type), @@ -436,6 +443,7 @@ function getEndpointTypeFromSingleServer( name: "endpoint", isGeneratedName: true, description: "Service host", + doc: "Service host", kind: "path", onClient: true, urlEncode: false, @@ -535,6 +543,7 @@ function getSdkEndpointParameter( name: "endpoint", isGeneratedName: true, description: "Service host", + doc: "Service host", onClient: true, urlEncode: false, apiVersions: context.__tspTypeToApiVersions.get(client.type)!, diff --git a/packages/typespec-client-generator-core/test/package.test.ts b/packages/typespec-client-generator-core/test/package.test.ts index 01816485bb..d7129f88e8 100644 --- a/packages/typespec-client-generator-core/test/package.test.ts +++ b/packages/typespec-client-generator-core/test/package.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable deprecation/deprecation */ import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing"; import { ApiKeyAuth, OAuth2Flow, Oauth2Auth } from "@typespec/http"; import { deepStrictEqual, ok, strictEqual } from "assert"; @@ -339,7 +338,8 @@ describe("typespec-client-generator-core: package", () => { strictEqual(templateArg.optional, false); strictEqual(templateArg.onClient, true); strictEqual(templateArg.clientDefaultValue, undefined); - strictEqual(templateArg.description, undefined); + strictEqual(templateArg.description, undefined); // eslint-disable-line deprecation/deprecation + strictEqual(templateArg.doc, undefined); const credentialParam = client.initialization.properties.filter( (p): p is SdkCredentialParameter => p.kind === "credential" diff --git a/packages/typespec-client-generator-core/test/public-utils.test.ts b/packages/typespec-client-generator-core/test/public-utils.test.ts index fab7935ead..dc3f7c03f6 100644 --- a/packages/typespec-client-generator-core/test/public-utils.test.ts +++ b/packages/typespec-client-generator-core/test/public-utils.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable deprecation/deprecation */ import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing"; import { Model, diff --git a/packages/typespec-client-generator-core/test/types/body-model-property-types.test.ts b/packages/typespec-client-generator-core/test/types/body-model-property-types.test.ts index de7683a30e..3e9099cdaa 100644 --- a/packages/typespec-client-generator-core/test/types/body-model-property-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/body-model-property-types.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable deprecation/deprecation */ import { deepStrictEqual, ok, strictEqual } from "assert"; import { beforeEach, describe, it } from "vitest"; import { isReadOnly } from "../../src/types.js"; diff --git a/packages/typespec-client-generator-core/test/types/built-in-types.test.ts b/packages/typespec-client-generator-core/test/types/built-in-types.test.ts index 39a8106c6b..654993b10f 100644 --- a/packages/typespec-client-generator-core/test/types/built-in-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/built-in-types.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable deprecation/deprecation */ import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing"; import { expectDiagnostics } from "@typespec/compiler/testing"; import { ok, strictEqual } from "assert"; @@ -413,8 +412,10 @@ describe("typespec-client-generator-core: built-in types", () => { const type = models[0].properties[0].type; strictEqual(type.kind, "string"); strictEqual(type.name, "TestScalar"); - strictEqual(type.description, "title"); - strictEqual(type.details, "doc"); + strictEqual(type.description, "title"); // eslint-disable-line deprecation/deprecation + strictEqual(type.details, "doc"); // eslint-disable-line deprecation/deprecation + strictEqual(type.doc, "doc"); + strictEqual(type.summary, "title"); strictEqual(type.crossLanguageDefinitionId, "TestService.TestScalar"); }); }); diff --git a/packages/typespec-client-generator-core/test/types/date-time-types.test.ts b/packages/typespec-client-generator-core/test/types/date-time-types.test.ts index 008a67c3e9..d5606d1d03 100644 --- a/packages/typespec-client-generator-core/test/types/date-time-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/date-time-types.test.ts @@ -172,8 +172,10 @@ describe("typespec-client-generator-core: date-time types", () => { strictEqual(sdkType.valueType.name, "unixTimestampDateTime"); strictEqual(sdkType.valueType.encode, "unixTimestamp"); strictEqual(sdkType.valueType.wireType?.kind, "int64"); - strictEqual(sdkType.valueType.description, "title"); - strictEqual(sdkType.valueType.details, "doc"); + strictEqual(sdkType.valueType.description, "title"); // eslint-disable-line deprecation/deprecation + strictEqual(sdkType.valueType.details, "doc"); // eslint-disable-line deprecation/deprecation + strictEqual(sdkType.valueType.doc, "doc"); + strictEqual(sdkType.valueType.summary, "title"); strictEqual(sdkType.valueType.crossLanguageDefinitionId, "TestService.unixTimestampDateTime"); strictEqual(sdkType.valueType.baseType?.kind, "utcDateTime"); strictEqual(sdkType.valueType.baseType.wireType.kind, "string"); diff --git a/packages/typespec-client-generator-core/test/types/duration-type.test.ts b/packages/typespec-client-generator-core/test/types/duration-type.test.ts index 43ab0a4e2c..7ef860af50 100644 --- a/packages/typespec-client-generator-core/test/types/duration-type.test.ts +++ b/packages/typespec-client-generator-core/test/types/duration-type.test.ts @@ -115,8 +115,10 @@ describe("typespec-client-generator-core: duration types", () => { strictEqual(sdkType.kind, "array"); strictEqual(sdkType.valueType.kind, "duration"); strictEqual(sdkType.valueType.name, "Float32Duration"); - strictEqual(sdkType.valueType.description, "title"); - strictEqual(sdkType.valueType.details, "doc"); + strictEqual(sdkType.valueType.description, "title"); // eslint-disable-line deprecation/deprecation + strictEqual(sdkType.valueType.details, "doc"); // eslint-disable-line deprecation/deprecation + strictEqual(sdkType.valueType.doc, "doc"); + strictEqual(sdkType.valueType.summary, "title"); // the encode and wireType will only be added to the outer type strictEqual(sdkType.valueType.encode, "seconds"); strictEqual(sdkType.valueType.crossLanguageDefinitionId, "TestService.Float32Duration"); diff --git a/packages/typespec-client-generator-core/test/types/model-types.test.ts b/packages/typespec-client-generator-core/test/types/model-types.test.ts index 177976849c..b17d42a4dc 100644 --- a/packages/typespec-client-generator-core/test/types/model-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/model-types.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable deprecation/deprecation */ import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing"; import { isErrorModel } from "@typespec/compiler"; import { deepStrictEqual, ok, strictEqual } from "assert"; @@ -188,7 +187,8 @@ describe("typespec-client-generator-core: model types", () => { const kindProperty = fish.properties[0]; ok(kindProperty); strictEqual(kindProperty.name, "kind"); - strictEqual(kindProperty.description, "Discriminator property for Fish."); + strictEqual(kindProperty.description, "Discriminator property for Fish."); // eslint-disable-line deprecation/deprecation + strictEqual(kindProperty.doc, "Discriminator property for Fish."); strictEqual(kindProperty.kind, "property"); strictEqual(kindProperty.discriminator, true); strictEqual(kindProperty.type.kind, "string"); @@ -200,7 +200,8 @@ describe("typespec-client-generator-core: model types", () => { const sharktypeProperty = shark.properties[0]; ok(sharktypeProperty); strictEqual(sharktypeProperty.name, "sharktype"); - strictEqual(sharktypeProperty.description, "Discriminator property for Shark."); + strictEqual(sharktypeProperty.description, "Discriminator property for Shark."); // eslint-disable-line deprecation/deprecation + strictEqual(sharktypeProperty.doc, "Discriminator property for Shark."); strictEqual(sharktypeProperty.kind, "property"); strictEqual(sharktypeProperty.discriminator, true); strictEqual(sharktypeProperty.type.kind, "string"); @@ -231,7 +232,8 @@ describe("typespec-client-generator-core: model types", () => { const kindProperty = fish.properties[0]; ok(kindProperty); strictEqual(kindProperty.name, "kind"); - strictEqual(kindProperty.description, "Discriminator property for Fish."); + strictEqual(kindProperty.description, "Discriminator property for Fish."); // eslint-disable-line deprecation/deprecation + strictEqual(kindProperty.doc, "Discriminator property for Fish."); strictEqual(kindProperty.kind, "property"); strictEqual(kindProperty.discriminator, true); strictEqual(kindProperty.type.kind, "string"); @@ -263,7 +265,8 @@ describe("typespec-client-generator-core: model types", () => { const kindProperty = fish.properties[0]; ok(kindProperty); strictEqual(kindProperty.name, "kind"); - strictEqual(kindProperty.description, "Discriminator property for Fish."); + strictEqual(kindProperty.description, "Discriminator property for Fish."); // eslint-disable-line deprecation/deprecation + strictEqual(kindProperty.doc, "Discriminator property for Fish."); strictEqual(kindProperty.kind, "property"); strictEqual(kindProperty.discriminator, true); strictEqual(kindProperty.type.kind, "string"); @@ -348,7 +351,8 @@ describe("typespec-client-generator-core: model types", () => { const catValue = values.find((x) => x.name === "Cat"); ok(catValue); strictEqual(catValue.value, "cat"); - strictEqual(catValue.description, "Cat"); + strictEqual(catValue.description, "Cat"); // eslint-disable-line deprecation/deprecation + strictEqual(catValue.doc, "Cat"); strictEqual(catValue.enumType, petKind); strictEqual(catValue.valueType, petKind.valueType); strictEqual(catValue.kind, "enumvalue"); @@ -356,7 +360,8 @@ describe("typespec-client-generator-core: model types", () => { const dogValue = values.find((x) => x.name === "Dog"); ok(dogValue); strictEqual(dogValue.value, "dog"); - strictEqual(dogValue.description, "Dog"); + strictEqual(dogValue.description, "Dog"); // eslint-disable-line deprecation/deprecation + strictEqual(dogValue.doc, "Dog"); strictEqual(dogValue.enumType, petKind); strictEqual(dogValue.valueType, petKind.valueType); strictEqual(dogValue.kind, "enumvalue"); @@ -477,7 +482,8 @@ describe("typespec-client-generator-core: model types", () => { const dogKindProperty = dog.properties[0]; ok(dogKindProperty); strictEqual(dogKindProperty.type, dogKind); - strictEqual(dogKindProperty.description, "Discriminator property for Dog."); + strictEqual(dogKindProperty.description, "Discriminator property for Dog."); // eslint-disable-line deprecation/deprecation + strictEqual(dogKindProperty.doc, "Discriminator property for Dog."); }); it("discriminator", async () => { diff --git a/packages/typespec-client-generator-core/test/types/multipart-types.test.ts b/packages/typespec-client-generator-core/test/types/multipart-types.test.ts index 8bddd65588..36eac6b918 100644 --- a/packages/typespec-client-generator-core/test/types/multipart-types.test.ts +++ b/packages/typespec-client-generator-core/test/types/multipart-types.test.ts @@ -1,4 +1,3 @@ -/* eslint-disable deprecation/deprecation */ import { expectDiagnostics } from "@typespec/compiler/testing"; import { deepEqual, ok, strictEqual } from "assert"; import { beforeEach, describe, it } from "vitest"; @@ -32,7 +31,7 @@ describe("typespec-client-generator-core: multipart types", () => { strictEqual(models.length, 1); const model = models[0]; strictEqual(model.kind, "model"); - strictEqual(model.isFormDataType, true); + strictEqual(model.isFormDataType, true); // eslint-disable-line deprecation/deprecation ok((model.usage & UsageFlags.MultipartFormData) > 0); strictEqual(model.name, "MultiPartRequest"); strictEqual(model.properties.length, 2); @@ -85,7 +84,7 @@ describe("typespec-client-generator-core: multipart types", () => { const modelA = models.find((x) => x.name === "MultipartOperationRequest"); ok(modelA); strictEqual(modelA.kind, "model"); - strictEqual(modelA.isFormDataType, true); + strictEqual(modelA.isFormDataType, true); // eslint-disable-line deprecation/deprecation strictEqual(modelA.usage, UsageFlags.MultipartFormData | UsageFlags.Spread); strictEqual(modelA.properties.length, 1); const modelAProp = modelA.properties[0]; @@ -97,7 +96,7 @@ describe("typespec-client-generator-core: multipart types", () => { const modelB = models.find((x) => x.name === "NormalOperationRequest"); ok(modelB); strictEqual(modelB.kind, "model"); - strictEqual(modelB.isFormDataType, false); + strictEqual(modelB.isFormDataType, false); // eslint-disable-line deprecation/deprecation strictEqual(modelB.usage, UsageFlags.Spread | UsageFlags.Json); strictEqual(modelB.properties.length, 1); strictEqual(modelB.properties[0].type.kind, "bytes"); @@ -187,13 +186,13 @@ describe("typespec-client-generator-core: multipart types", () => { const pictureWrapper = models.find((x) => x.name === "PictureWrapper"); ok(pictureWrapper); - strictEqual(pictureWrapper.isFormDataType, true); + strictEqual(pictureWrapper.isFormDataType, true); // eslint-disable-line deprecation/deprecation ok((pictureWrapper.usage & UsageFlags.MultipartFormData) > 0); const errorResponse = models.find((x) => x.name === "ErrorResponse"); ok(errorResponse); strictEqual(errorResponse.kind, "model"); - strictEqual(errorResponse.isFormDataType, false); + strictEqual(errorResponse.isFormDataType, false); // eslint-disable-line deprecation/deprecation ok((errorResponse.usage & UsageFlags.MultipartFormData) === 0); }); From 2d4b16bd491b8d719e910d7d47384e765b145f78 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Thu, 15 Aug 2024 16:07:42 +0800 Subject: [PATCH 3/8] chnagelog --- .chronus/changes/add_typespec_raw_doc-2024-7-15-16-7-32.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/add_typespec_raw_doc-2024-7-15-16-7-32.md diff --git a/.chronus/changes/add_typespec_raw_doc-2024-7-15-16-7-32.md b/.chronus/changes/add_typespec_raw_doc-2024-7-15-16-7-32.md new file mode 100644 index 0000000000..89a45ffbab --- /dev/null +++ b/.chronus/changes/add_typespec_raw_doc-2024-7-15-16-7-32.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +add `doc` and `summary` to tcgc types \ No newline at end of file From 7f8c11b832dfdc9721a7720ff28f1ce553c5a21c Mon Sep 17 00:00:00 2001 From: tadelesh Date: Thu, 15 Aug 2024 16:08:54 +0800 Subject: [PATCH 4/8] format --- packages/typespec-client-generator-core/src/package.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index 6a584b67f0..ca873fdaad 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -135,12 +135,12 @@ function getSdkPagingServiceMethod( - context, - pagedMetadata.nextLinkOperation, - basic.parameters + getSdkServiceOperation( + context, + pagedMetadata.nextLinkOperation, + basic.parameters + ) ) - ) : undefined, getResponseMapping(): string | undefined { return basic.response.resultPath; From 893e6533ed22cbff04ffea1f0fa36404c1453a48 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Tue, 20 Aug 2024 10:33:27 +0800 Subject: [PATCH 5/8] add unicode test --- .../test/types/usage-flags.test copy.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 packages/typespec-client-generator-core/test/types/usage-flags.test copy.ts diff --git a/packages/typespec-client-generator-core/test/types/usage-flags.test copy.ts b/packages/typespec-client-generator-core/test/types/usage-flags.test copy.ts new file mode 100644 index 0000000000..c408258b93 --- /dev/null +++ b/packages/typespec-client-generator-core/test/types/usage-flags.test copy.ts @@ -0,0 +1,25 @@ +import { beforeEach, describe, it } from "vitest"; +import { createSdkTestRunner, SdkTestRunner } from "../test-host.js"; +import { strictEqual } from "assert"; + +describe("typespec-client-generator-core: doc and summary", () => { + let runner: SdkTestRunner; + + beforeEach(async () => { + runner = await createSdkTestRunner({ emitterName: "@azure-tools/typespec-java" }); + }); + + it("unicode", async () => { + await runner.compileWithBuiltInService(` + @usage(Usage.input | Usage.output) + @doc("测试doc") + @summary("测试summary") + model Test {} + `); + + const models = runner.context.sdkPackage.models; + strictEqual(models.length, 1); + strictEqual(models[0].doc, "测试doc"); + strictEqual(models[0].summary, "测试summary"); + }); +}); From 84f3972f75084583cf2d999c9c72c83931422a34 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Tue, 20 Aug 2024 10:33:59 +0800 Subject: [PATCH 6/8] rename --- .../test/types/{usage-flags.test copy.ts => doc-summary.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/typespec-client-generator-core/test/types/{usage-flags.test copy.ts => doc-summary.ts} (100%) diff --git a/packages/typespec-client-generator-core/test/types/usage-flags.test copy.ts b/packages/typespec-client-generator-core/test/types/doc-summary.ts similarity index 100% rename from packages/typespec-client-generator-core/test/types/usage-flags.test copy.ts rename to packages/typespec-client-generator-core/test/types/doc-summary.ts From f27890d988214f3690b56f5e63c6407cf4119042 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Tue, 20 Aug 2024 10:41:01 +0800 Subject: [PATCH 7/8] format --- .../test/types/{doc-summary.ts => doc-summary.test.ts} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/typespec-client-generator-core/test/types/{doc-summary.ts => doc-summary.test.ts} (100%) diff --git a/packages/typespec-client-generator-core/test/types/doc-summary.ts b/packages/typespec-client-generator-core/test/types/doc-summary.test.ts similarity index 100% rename from packages/typespec-client-generator-core/test/types/doc-summary.ts rename to packages/typespec-client-generator-core/test/types/doc-summary.test.ts index c408258b93..aefa151ff4 100644 --- a/packages/typespec-client-generator-core/test/types/doc-summary.ts +++ b/packages/typespec-client-generator-core/test/types/doc-summary.test.ts @@ -1,6 +1,6 @@ +import { strictEqual } from "assert"; import { beforeEach, describe, it } from "vitest"; import { createSdkTestRunner, SdkTestRunner } from "../test-host.js"; -import { strictEqual } from "assert"; describe("typespec-client-generator-core: doc and summary", () => { let runner: SdkTestRunner; From 9ea25b93b944fbae228e39807f1d4740c5bd10e8 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Wed, 21 Aug 2024 22:06:26 +0800 Subject: [PATCH 8/8] fix lint --- .../typespec-client-generator-core/test/package.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/typespec-client-generator-core/test/package.test.ts b/packages/typespec-client-generator-core/test/package.test.ts index 28abb198d0..4e70085e27 100644 --- a/packages/typespec-client-generator-core/test/package.test.ts +++ b/packages/typespec-client-generator-core/test/package.test.ts @@ -141,7 +141,7 @@ describe("typespec-client-generator-core: package", () => { strictEqual(templateArg.kind, "path"); strictEqual(templateArg.name, "endpoint"); strictEqual(templateArg.serializedName, "endpoint"); - strictEqual(templateArg.urlEncode, false); + strictEqual(templateArg.urlEncode, false); // eslint-disable-line deprecation/deprecation strictEqual(templateArg.type.kind, "string"); strictEqual(templateArg.optional, false); strictEqual(templateArg.onClient, true); @@ -333,7 +333,7 @@ describe("typespec-client-generator-core: package", () => { const templateArg = endpointParam.type.templateArguments[0]; strictEqual(templateArg.kind, "path"); strictEqual(templateArg.name, "endpointInput"); - strictEqual(templateArg.urlEncode, false); + strictEqual(templateArg.urlEncode, false); // eslint-disable-line deprecation/deprecation strictEqual(templateArg.optional, false); strictEqual(templateArg.onClient, true); strictEqual(templateArg.clientDefaultValue, undefined); @@ -422,7 +422,7 @@ describe("typespec-client-generator-core: package", () => { const apiVersionParam = templatedEndpoint.templateArguments[1]; strictEqual(apiVersionParam.clientDefaultValue, "v1.0"); - strictEqual(apiVersionParam.urlEncode, true); + strictEqual(apiVersionParam.urlEncode, true); // eslint-disable-line deprecation/deprecation strictEqual(apiVersionParam.name, "apiVersion"); strictEqual(apiVersionParam.onClient, true); strictEqual(apiVersionParam.optional, false);