From 4aff739e6016c3cd9026ebe7ba49db864e3601cb Mon Sep 17 00:00:00 2001 From: Mary Gao Date: Tue, 23 Jul 2024 14:25:33 +0800 Subject: [PATCH] Fix the isUnexpected narrowing issue in modular (#2654) * generate deviceregistry with modular * Re-generate device registery mgmt * update tsp * regen code and build * Regen the deviceRegistryClient * Update the api view * regen code * fix ci * fix ci * remove test case * update the subset logic for default response * Update the responses * Update the interface * Update the narrowing with necessary conditions * update * update * Update the change for this * Update packages/typespec-ts/src/modular/helpers/operationHelpers.ts * Update the changes * fix ci * update * regen smoke test * remove device case * fix ci * regen smoke test * Regen with res not _result * Update the generation detail * regen code * Resolve comments * Update the operation name * revert some changes * Merge to main --------- Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com> Co-authored-by: Jiao Di (MSFT) <80496810+v-jiaodi@users.noreply.github.com> --- .../rlc-common/src/helpers/schemaHelpers.ts | 2 +- packages/rlc-common/src/interfaces.ts | 2 + .../typespec-ts/src/api/dataProducts/index.ts | 249 ++++++++---------- .../typespec-ts/src/api/dataTypes/index.ts | 86 +++--- .../typespec-ts/src/api/budgets/index.ts | 8 +- .../typespec-ts/src/api/widgets/index.ts | 8 +- packages/typespec-ts/src/lib.ts | 6 + .../src/modular/helpers/operationHelpers.ts | 97 ++++--- .../src/transform/transformResponses.ts | 99 ++++++- .../lro/rpc/generated/src/api/operations.ts | 8 +- .../standard/generated/src/api/operations.ts | 17 +- .../src/api/nestedProxyResources/index.ts | 66 ++--- .../src/api/topLevelTrackedResources/index.ts | 75 +++--- .../test/modularUnit/anonymousModel.spec.ts | 2 +- .../test/modularUnit/apiOperations.spec.ts | 6 +- .../test/modularUnit/modelsGenerator.spec.ts | 16 +- .../test/modularUnit/operations.spec.ts | 2 - 17 files changed, 417 insertions(+), 332 deletions(-) diff --git a/packages/rlc-common/src/helpers/schemaHelpers.ts b/packages/rlc-common/src/helpers/schemaHelpers.ts index 3f9c639a38..2709fc571e 100644 --- a/packages/rlc-common/src/helpers/schemaHelpers.ts +++ b/packages/rlc-common/src/helpers/schemaHelpers.ts @@ -31,7 +31,7 @@ export function isDictionarySchema( return false; } -export function isObjectSchema(schema: Schema) { +export function isObjectSchema(schema: Schema): schema is ObjectSchema { if (schema.type === "object") { return true; } diff --git a/packages/rlc-common/src/interfaces.ts b/packages/rlc-common/src/interfaces.ts index 32f286ab3c..a782089ec0 100644 --- a/packages/rlc-common/src/interfaces.ts +++ b/packages/rlc-common/src/interfaces.ts @@ -366,6 +366,8 @@ export interface OperationResponse { operationName: string; path: string; responses: ResponseMetadata[]; + // Check if the default response is one of superset of non-default responses + isDefaultSupersetOfOthers?: boolean; } export interface ResponseMetadata { statusCode: string; diff --git a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/api/dataProducts/index.ts b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/api/dataProducts/index.ts index 1f13f9302b..7876ee06d9 100644 --- a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/api/dataProducts/index.ts +++ b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/api/dataProducts/index.ts @@ -119,61 +119,59 @@ export async function _createDeserialize( throw createRestError(result); } - result = result as DataProductsCreateLogicalResponse; + const res = result as unknown as DataProductsCreateLogicalResponse; return { - tags: result.body["tags"], - location: result.body["location"], - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - systemData: !result.body.systemData + tags: res.body["tags"], + location: res.body["location"], + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData ? undefined : { - createdBy: result.body.systemData?.["createdBy"], - createdByType: result.body.systemData?.["createdByType"], + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], createdAt: - result.body.systemData?.["createdAt"] !== undefined - ? new Date(result.body.systemData?.["createdAt"]) + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) : undefined, - lastModifiedBy: result.body.systemData?.["lastModifiedBy"], - lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], lastModifiedAt: - result.body.systemData?.["lastModifiedAt"] !== undefined - ? new Date(result.body.systemData?.["lastModifiedAt"]) + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) : undefined, }, - properties: !result.body.properties + properties: !res.body.properties ? undefined : { - resourceGuid: result.body.properties?.["resourceGuid"], - provisioningState: result.body.properties?.["provisioningState"], - publisher: result.body.properties?.["publisher"], - product: result.body.properties?.["product"], - majorVersion: result.body.properties?.["majorVersion"], - owners: result.body.properties?.["owners"], - redundancy: result.body.properties?.["redundancy"], - purviewAccount: result.body.properties?.["purviewAccount"], - purviewCollection: result.body.properties?.["purviewCollection"], - privateLinksEnabled: result.body.properties?.["privateLinksEnabled"], - publicNetworkAccess: result.body.properties?.["publicNetworkAccess"], + resourceGuid: res.body.properties?.["resourceGuid"], + provisioningState: res.body.properties?.["provisioningState"], + publisher: res.body.properties?.["publisher"], + product: res.body.properties?.["product"], + majorVersion: res.body.properties?.["majorVersion"], + owners: res.body.properties?.["owners"], + redundancy: res.body.properties?.["redundancy"], + purviewAccount: res.body.properties?.["purviewAccount"], + purviewCollection: res.body.properties?.["purviewCollection"], + privateLinksEnabled: res.body.properties?.["privateLinksEnabled"], + publicNetworkAccess: res.body.properties?.["publicNetworkAccess"], customerManagedKeyEncryptionEnabled: - result.body.properties?.["customerManagedKeyEncryptionEnabled"], - customerEncryptionKey: !result.body.properties?.customerEncryptionKey + res.body.properties?.["customerManagedKeyEncryptionEnabled"], + customerEncryptionKey: !res.body.properties?.customerEncryptionKey ? undefined : { keyVaultUri: - result.body.properties?.customerEncryptionKey?.[ - "keyVaultUri" - ], + res.body.properties?.customerEncryptionKey?.["keyVaultUri"], keyName: - result.body.properties?.customerEncryptionKey?.["keyName"], + res.body.properties?.customerEncryptionKey?.["keyName"], keyVersion: - result.body.properties?.customerEncryptionKey?.["keyVersion"], + res.body.properties?.customerEncryptionKey?.["keyVersion"], }, - networkacls: !result.body.properties?.networkacls + networkacls: !res.body.properties?.networkacls ? undefined : { - virtualNetworkRule: result.body.properties?.networkacls?.[ + virtualNetworkRule: res.body.properties?.networkacls?.[ "virtualNetworkRule" ].map((p) => { return { @@ -182,69 +180,63 @@ export async function _createDeserialize( state: p["state"], }; }), - ipRules: result.body.properties?.networkacls?.["ipRules"].map( + ipRules: res.body.properties?.networkacls?.["ipRules"].map( (p) => { return { value: p["value"], action: p["action"] }; }, ), allowedQueryIpRangeList: - result.body.properties?.networkacls?.[ - "allowedQueryIpRangeList" - ], + res.body.properties?.networkacls?.["allowedQueryIpRangeList"], defaultAction: - result.body.properties?.networkacls?.["defaultAction"], + res.body.properties?.networkacls?.["defaultAction"], }, - managedResourceGroupConfiguration: !result.body.properties + managedResourceGroupConfiguration: !res.body.properties ?.managedResourceGroupConfiguration ? undefined : { - name: result.body.properties - ?.managedResourceGroupConfiguration?.["name"], + name: res.body.properties?.managedResourceGroupConfiguration?.[ + "name" + ], location: - result.body.properties?.managedResourceGroupConfiguration?.[ + res.body.properties?.managedResourceGroupConfiguration?.[ "location" ], }, availableMinorVersions: - result.body.properties?.["availableMinorVersions"], - currentMinorVersion: result.body.properties?.["currentMinorVersion"], - documentation: result.body.properties?.["documentation"], - consumptionEndpoints: !result.body.properties?.consumptionEndpoints + res.body.properties?.["availableMinorVersions"], + currentMinorVersion: res.body.properties?.["currentMinorVersion"], + documentation: res.body.properties?.["documentation"], + consumptionEndpoints: !res.body.properties?.consumptionEndpoints ? undefined : { ingestionUrl: - result.body.properties?.consumptionEndpoints?.[ - "ingestionUrl" - ], + res.body.properties?.consumptionEndpoints?.["ingestionUrl"], ingestionResourceId: - result.body.properties?.consumptionEndpoints?.[ + res.body.properties?.consumptionEndpoints?.[ "ingestionResourceId" ], fileAccessUrl: - result.body.properties?.consumptionEndpoints?.[ - "fileAccessUrl" - ], + res.body.properties?.consumptionEndpoints?.["fileAccessUrl"], fileAccessResourceId: - result.body.properties?.consumptionEndpoints?.[ + res.body.properties?.consumptionEndpoints?.[ "fileAccessResourceId" ], queryUrl: - result.body.properties?.consumptionEndpoints?.["queryUrl"], + res.body.properties?.consumptionEndpoints?.["queryUrl"], queryResourceId: - result.body.properties?.consumptionEndpoints?.[ + res.body.properties?.consumptionEndpoints?.[ "queryResourceId" ], }, - keyVaultUrl: result.body.properties?.["keyVaultUrl"], + keyVaultUrl: res.body.properties?.["keyVaultUrl"], }, - identity: !result.body.identity + identity: !res.body.identity ? undefined : { - principalId: result.body.identity?.["principalId"], - tenantId: result.body.identity?.["tenantId"], - type: result.body.identity?.["type"], - userAssignedIdentities: - result.body.identity?.["userAssignedIdentities"], + principalId: res.body.identity?.["principalId"], + tenantId: res.body.identity?.["tenantId"], + type: res.body.identity?.["type"], + userAssignedIdentities: res.body.identity?.["userAssignedIdentities"], }, }; } @@ -493,61 +485,59 @@ export async function _updateDeserialize( throw createRestError(result); } - result = result as DataProductsUpdateLogicalResponse; + const res = result as unknown as DataProductsUpdateLogicalResponse; return { - tags: result.body["tags"], - location: result.body["location"], - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - systemData: !result.body.systemData + tags: res.body["tags"], + location: res.body["location"], + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData ? undefined : { - createdBy: result.body.systemData?.["createdBy"], - createdByType: result.body.systemData?.["createdByType"], + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], createdAt: - result.body.systemData?.["createdAt"] !== undefined - ? new Date(result.body.systemData?.["createdAt"]) + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) : undefined, - lastModifiedBy: result.body.systemData?.["lastModifiedBy"], - lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], lastModifiedAt: - result.body.systemData?.["lastModifiedAt"] !== undefined - ? new Date(result.body.systemData?.["lastModifiedAt"]) + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) : undefined, }, - properties: !result.body.properties + properties: !res.body.properties ? undefined : { - resourceGuid: result.body.properties?.["resourceGuid"], - provisioningState: result.body.properties?.["provisioningState"], - publisher: result.body.properties?.["publisher"], - product: result.body.properties?.["product"], - majorVersion: result.body.properties?.["majorVersion"], - owners: result.body.properties?.["owners"], - redundancy: result.body.properties?.["redundancy"], - purviewAccount: result.body.properties?.["purviewAccount"], - purviewCollection: result.body.properties?.["purviewCollection"], - privateLinksEnabled: result.body.properties?.["privateLinksEnabled"], - publicNetworkAccess: result.body.properties?.["publicNetworkAccess"], + resourceGuid: res.body.properties?.["resourceGuid"], + provisioningState: res.body.properties?.["provisioningState"], + publisher: res.body.properties?.["publisher"], + product: res.body.properties?.["product"], + majorVersion: res.body.properties?.["majorVersion"], + owners: res.body.properties?.["owners"], + redundancy: res.body.properties?.["redundancy"], + purviewAccount: res.body.properties?.["purviewAccount"], + purviewCollection: res.body.properties?.["purviewCollection"], + privateLinksEnabled: res.body.properties?.["privateLinksEnabled"], + publicNetworkAccess: res.body.properties?.["publicNetworkAccess"], customerManagedKeyEncryptionEnabled: - result.body.properties?.["customerManagedKeyEncryptionEnabled"], - customerEncryptionKey: !result.body.properties?.customerEncryptionKey + res.body.properties?.["customerManagedKeyEncryptionEnabled"], + customerEncryptionKey: !res.body.properties?.customerEncryptionKey ? undefined : { keyVaultUri: - result.body.properties?.customerEncryptionKey?.[ - "keyVaultUri" - ], + res.body.properties?.customerEncryptionKey?.["keyVaultUri"], keyName: - result.body.properties?.customerEncryptionKey?.["keyName"], + res.body.properties?.customerEncryptionKey?.["keyName"], keyVersion: - result.body.properties?.customerEncryptionKey?.["keyVersion"], + res.body.properties?.customerEncryptionKey?.["keyVersion"], }, - networkacls: !result.body.properties?.networkacls + networkacls: !res.body.properties?.networkacls ? undefined : { - virtualNetworkRule: result.body.properties?.networkacls?.[ + virtualNetworkRule: res.body.properties?.networkacls?.[ "virtualNetworkRule" ].map((p) => { return { @@ -556,69 +546,63 @@ export async function _updateDeserialize( state: p["state"], }; }), - ipRules: result.body.properties?.networkacls?.["ipRules"].map( + ipRules: res.body.properties?.networkacls?.["ipRules"].map( (p) => { return { value: p["value"], action: p["action"] }; }, ), allowedQueryIpRangeList: - result.body.properties?.networkacls?.[ - "allowedQueryIpRangeList" - ], + res.body.properties?.networkacls?.["allowedQueryIpRangeList"], defaultAction: - result.body.properties?.networkacls?.["defaultAction"], + res.body.properties?.networkacls?.["defaultAction"], }, - managedResourceGroupConfiguration: !result.body.properties + managedResourceGroupConfiguration: !res.body.properties ?.managedResourceGroupConfiguration ? undefined : { - name: result.body.properties - ?.managedResourceGroupConfiguration?.["name"], + name: res.body.properties?.managedResourceGroupConfiguration?.[ + "name" + ], location: - result.body.properties?.managedResourceGroupConfiguration?.[ + res.body.properties?.managedResourceGroupConfiguration?.[ "location" ], }, availableMinorVersions: - result.body.properties?.["availableMinorVersions"], - currentMinorVersion: result.body.properties?.["currentMinorVersion"], - documentation: result.body.properties?.["documentation"], - consumptionEndpoints: !result.body.properties?.consumptionEndpoints + res.body.properties?.["availableMinorVersions"], + currentMinorVersion: res.body.properties?.["currentMinorVersion"], + documentation: res.body.properties?.["documentation"], + consumptionEndpoints: !res.body.properties?.consumptionEndpoints ? undefined : { ingestionUrl: - result.body.properties?.consumptionEndpoints?.[ - "ingestionUrl" - ], + res.body.properties?.consumptionEndpoints?.["ingestionUrl"], ingestionResourceId: - result.body.properties?.consumptionEndpoints?.[ + res.body.properties?.consumptionEndpoints?.[ "ingestionResourceId" ], fileAccessUrl: - result.body.properties?.consumptionEndpoints?.[ - "fileAccessUrl" - ], + res.body.properties?.consumptionEndpoints?.["fileAccessUrl"], fileAccessResourceId: - result.body.properties?.consumptionEndpoints?.[ + res.body.properties?.consumptionEndpoints?.[ "fileAccessResourceId" ], queryUrl: - result.body.properties?.consumptionEndpoints?.["queryUrl"], + res.body.properties?.consumptionEndpoints?.["queryUrl"], queryResourceId: - result.body.properties?.consumptionEndpoints?.[ + res.body.properties?.consumptionEndpoints?.[ "queryResourceId" ], }, - keyVaultUrl: result.body.properties?.["keyVaultUrl"], + keyVaultUrl: res.body.properties?.["keyVaultUrl"], }, - identity: !result.body.identity + identity: !res.body.identity ? undefined : { - principalId: result.body.identity?.["principalId"], - tenantId: result.body.identity?.["tenantId"], - type: result.body.identity?.["type"], - userAssignedIdentities: - result.body.identity?.["userAssignedIdentities"], + principalId: res.body.identity?.["principalId"], + tenantId: res.body.identity?.["tenantId"], + type: res.body.identity?.["type"], + userAssignedIdentities: res.body.identity?.["userAssignedIdentities"], }, }; } @@ -680,7 +664,6 @@ export async function _$deleteDeserialize( throw createRestError(result); } - result = result as DataProductsDeleteLogicalResponse; return; } diff --git a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/api/dataTypes/index.ts b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/api/dataTypes/index.ts index 3dd624ee3f..ff37539770 100644 --- a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/api/dataTypes/index.ts +++ b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/src/api/dataTypes/index.ts @@ -98,39 +98,39 @@ export async function _createDeserialize( throw createRestError(result); } - result = result as DataTypesCreateLogicalResponse; + const res = result as unknown as DataTypesCreateLogicalResponse; return { - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - systemData: !result.body.systemData + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData ? undefined : { - createdBy: result.body.systemData?.["createdBy"], - createdByType: result.body.systemData?.["createdByType"], + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], createdAt: - result.body.systemData?.["createdAt"] !== undefined - ? new Date(result.body.systemData?.["createdAt"]) + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) : undefined, - lastModifiedBy: result.body.systemData?.["lastModifiedBy"], - lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], lastModifiedAt: - result.body.systemData?.["lastModifiedAt"] !== undefined - ? new Date(result.body.systemData?.["lastModifiedAt"]) + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) : undefined, }, - properties: !result.body.properties + properties: !res.body.properties ? undefined : { - provisioningState: result.body.properties?.["provisioningState"], - state: result.body.properties?.["state"], - stateReason: result.body.properties?.["stateReason"], + provisioningState: res.body.properties?.["provisioningState"], + state: res.body.properties?.["state"], + stateReason: res.body.properties?.["stateReason"], storageOutputRetention: - result.body.properties?.["storageOutputRetention"], + res.body.properties?.["storageOutputRetention"], databaseCacheRetention: - result.body.properties?.["databaseCacheRetention"], - databaseRetention: result.body.properties?.["databaseRetention"], - visualizationUrl: result.body.properties?.["visualizationUrl"], + res.body.properties?.["databaseCacheRetention"], + databaseRetention: res.body.properties?.["databaseRetention"], + visualizationUrl: res.body.properties?.["visualizationUrl"], }, }; } @@ -286,39 +286,39 @@ export async function _updateDeserialize( throw createRestError(result); } - result = result as DataTypesUpdateLogicalResponse; + const res = result as unknown as DataTypesUpdateLogicalResponse; return { - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - systemData: !result.body.systemData + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData ? undefined : { - createdBy: result.body.systemData?.["createdBy"], - createdByType: result.body.systemData?.["createdByType"], + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], createdAt: - result.body.systemData?.["createdAt"] !== undefined - ? new Date(result.body.systemData?.["createdAt"]) + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) : undefined, - lastModifiedBy: result.body.systemData?.["lastModifiedBy"], - lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], lastModifiedAt: - result.body.systemData?.["lastModifiedAt"] !== undefined - ? new Date(result.body.systemData?.["lastModifiedAt"]) + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) : undefined, }, - properties: !result.body.properties + properties: !res.body.properties ? undefined : { - provisioningState: result.body.properties?.["provisioningState"], - state: result.body.properties?.["state"], - stateReason: result.body.properties?.["stateReason"], + provisioningState: res.body.properties?.["provisioningState"], + state: res.body.properties?.["state"], + stateReason: res.body.properties?.["stateReason"], storageOutputRetention: - result.body.properties?.["storageOutputRetention"], + res.body.properties?.["storageOutputRetention"], databaseCacheRetention: - result.body.properties?.["databaseCacheRetention"], - databaseRetention: result.body.properties?.["databaseRetention"], - visualizationUrl: result.body.properties?.["visualizationUrl"], + res.body.properties?.["databaseCacheRetention"], + databaseRetention: res.body.properties?.["databaseRetention"], + visualizationUrl: res.body.properties?.["visualizationUrl"], }, }; } @@ -384,7 +384,6 @@ export async function _$deleteDeserialize( throw createRestError(result); } - result = result as DataTypesDeleteLogicalResponse; return; } @@ -453,7 +452,6 @@ export async function _deleteDataDeserialize( throw createRestError(result); } - result = result as DataTypesDeleteDataLogicalResponse; return; } diff --git a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/api/budgets/index.ts b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/api/budgets/index.ts index a5bdc3a025..9c95337fa6 100644 --- a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/api/budgets/index.ts +++ b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/api/budgets/index.ts @@ -50,11 +50,11 @@ export async function _createOrReplaceDeserialize( throw createRestError(result); } - result = result as BudgetsCreateOrReplaceLogicalResponse; + const res = result as unknown as BudgetsCreateOrReplaceLogicalResponse; return { - name: result.body["name"], - role: result.body["role"], - id: result.body["id"], + name: res.body["name"], + role: res.body["role"], + id: res.body["id"], }; } diff --git a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/api/widgets/index.ts b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/api/widgets/index.ts index 3a4a226d5a..cca125a8f8 100644 --- a/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/api/widgets/index.ts +++ b/packages/typespec-test/test/widget_dpg/generated/typespec-ts/src/api/widgets/index.ts @@ -348,11 +348,11 @@ export async function _createOrReplaceDeserialize( throw createRestError(result); } - result = result as WidgetsCreateOrReplaceLogicalResponse; + const res = result as unknown as WidgetsCreateOrReplaceLogicalResponse; return { - name: result.body["name"], - role: result.body["role"], - id: result.body["id"], + name: res.body["name"], + role: res.body["role"], + id: res.body["id"], }; } diff --git a/packages/typespec-ts/src/lib.ts b/packages/typespec-ts/src/lib.ts index e3bf239c05..efea91dda2 100644 --- a/packages/typespec-ts/src/lib.ts +++ b/packages/typespec-ts/src/lib.ts @@ -231,6 +231,12 @@ const libDef = { messages: { default: paramMessage`Please note that only compatible additional properties is supported for now. You can enable compatibilityMode to generate compatible additional properties for the model - ${"modelName"}.` } + }, + "default-response-body-type": { + severity: "warning", + messages: { + default: paramMessage`Please note the body type of default response for operation - ${"operationName"} is not a model type.` + } } }, emitter: { diff --git a/packages/typespec-ts/src/modular/helpers/operationHelpers.ts b/packages/typespec-ts/src/modular/helpers/operationHelpers.ts index 1c186dd9c4..d85b6f7b5f 100644 --- a/packages/typespec-ts/src/modular/helpers/operationHelpers.ts +++ b/packages/typespec-ts/src/modular/helpers/operationHelpers.ts @@ -37,6 +37,7 @@ import { Operation, Parameter, Property, + Response, Type } from "../modularCodeModel.js"; import { @@ -46,30 +47,55 @@ import { import { getClassicalLayerPrefix, getOperationName } from "./namingHelpers.js"; import { buildType, isTypeNullable } from "./typeHelpers.js"; -function getRLCResponseType(rlcResponse?: OperationResponse) { +function getRLCResponseTypes(rlcResponse?: OperationResponse) { if (!rlcResponse?.responses) { return; } return rlcResponse?.responses - .map((resp) => { - const baseResponseName = getResponseBaseName( - rlcResponse.operationGroup, - rlcResponse.operationName, - resp.statusCode - ); - // Get the information to build the Response Interface - return resp.predefinedName ?? getResponseTypeName(baseResponseName); - }) + .map( + (resp) => + resp.predefinedName ?? getRLCResponseType(resp.statusCode, rlcResponse) + ) .join(" | "); } -function getRLCLroLogicalResponse(rlcResponse?: OperationResponse) { - const logicalResponse = (rlcResponse?.responses ?? []).filter( - (r) => r.predefinedName && r.predefinedName.endsWith(`LogicalResponse`) +function getRLCResponseType( + statusCode: string, + operationInfo?: OperationResponse +) { + if (!operationInfo) { + return; + } + const baseResponseName = getResponseBaseName( + operationInfo.operationGroup, + operationInfo.operationName, + statusCode + ); + // Get the information to build the Response Interface + return getResponseTypeName(baseResponseName); +} + +function getNarrowedRLCResponse( + response: Response, + rlcResponse?: OperationResponse +): string | undefined { + if (!rlcResponse) { + return; + } + const statusCode = response.statusCodes; + const names = getRLCResponseTypes(rlcResponse)?.split(" | "); + const lroResponse = names?.filter((n) => n.endsWith(`LogicalResponse`)); + const normalResponse = names?.filter( + (n) => n === getRLCResponseType(`${statusCode}`, rlcResponse) + ); + return ( + // if the response is a LRO response, narrow to the lro logical response + lroResponse?.at(0) ?? + // if the default response is a superset of one of other responses, narrow to the normal response + (rlcResponse.isDefaultSupersetOfOthers + ? normalResponse?.at(0) ?? "any" + : undefined) ); - return logicalResponse.length > 0 - ? logicalResponse[0]!.predefinedName! - : "any"; } export function getSendPrivateFunction( @@ -80,7 +106,7 @@ export function getSendPrivateFunction( ): OptionalKind { const parameters = getOperationSignatureParameters(operation, clientType); const { name } = getOperationName(operation); - const returnType = `StreamableMethod<${getRLCResponseType( + const returnType = `StreamableMethod<${getRLCResponseTypes( operation.rlcResponse )}>`; @@ -125,7 +151,7 @@ export function getDeserializePrivateFunction( const parameters: OptionalKind[] = [ { name: "result", - type: getRLCResponseType(operation.rlcResponse) + type: getRLCResponseTypes(operation.rlcResponse) } ]; // TODO: Support LRO + paging operation @@ -187,20 +213,27 @@ export function getDeserializePrivateFunction( ? operation?.lroMetadata?.finalResult : response.type; const hasLroSubPath = operation?.lroMetadata?.finalResultPath !== undefined; + // Narrow down the rlc response type to deserialized one + const isNarrowedResponse = getNarrowedRLCResponse( + response, + operation.rlcResponse + ); + let deserializePrefix = "result.body"; + if (isNarrowedResponse) { + statements.push(`const res = result as unknown as ${isNarrowedResponse};`); + deserializePrefix = "res.body"; + } + const deserializedRoot = hasLroSubPath - ? `result.body.${operation?.lroMetadata?.finalResultPath}` - : "result.body"; - if (isLroOnly) { - const lroLogicalResponse = getRLCLroLogicalResponse(operation.rlcResponse); - statements.push(`result = result as ${lroLogicalResponse};`); - if (hasLroSubPath) { - statements.push( - `if(${deserializedRoot.split(".").join("?.")} === undefined) { - throw createRestError(\`Expected a result in the response at position "${deserializedRoot}"\`, result); - } - ` - ); - } + ? `${deserializePrefix}.${operation?.lroMetadata?.finalResultPath}` + : `${deserializePrefix}`; + if (isLroOnly && hasLroSubPath) { + statements.push( + `if(${deserializedRoot.split(".").join("?.")} === undefined) { + throw createRestError(\`Expected a result in the response at position "${deserializedRoot}"\`, result); + } + ` + ); } const allParents = deserializedType ? getAllAncestors(deserializedType) : []; @@ -215,7 +248,7 @@ export function getDeserializePrivateFunction( response.isBinaryPayload ) { // TODO: Fix this any cast when implementing handling dict. - statements.push(`return result.body as any`); + statements.push(`return ${deserializedRoot} as any`); } else if ( deserializedType && properties.length > 0 && diff --git a/packages/typespec-ts/src/transform/transformResponses.ts b/packages/typespec-ts/src/transform/transformResponses.ts index 3bb56d16d7..a07ca409b9 100644 --- a/packages/typespec-ts/src/transform/transformResponses.ts +++ b/packages/typespec-ts/src/transform/transformResponses.ts @@ -4,6 +4,8 @@ import { getLroLogicalResponseName, Imports, + isObjectSchema, + ObjectSchema, OperationResponse, ResponseHeaderSchema, ResponseMetadata, @@ -16,7 +18,7 @@ import { listOperationsInOperationGroup, SdkClient } from "@azure-tools/typespec-client-generator-core"; -import { getDoc, isVoidType } from "@typespec/compiler"; +import { getDoc, isVoidType, NoTarget } from "@typespec/compiler"; import { HttpOperation, HttpOperationResponse } from "@typespec/http"; import { SdkContext } from "../utils/interfaces.js"; import { @@ -33,6 +35,7 @@ import { isBinaryPayload, sortedOperationResponses } from "../utils/operationUtil.js"; +import { reportDiagnostic } from "../lib.js"; export function transformToResponseTypes( client: SdkClient, @@ -73,8 +76,11 @@ export function transformToResponseTypes( operationGroup: getOperationGroupName(dpgContext, route), operationName: getOperationName(dpgContext, route.operation), path: route.path, + isDefaultSupersetOfOthers: false, responses: [] }; + const defaultSchemas: Schema[] = [], + nonDefaultSchemas: Schema[] = []; for (const resp of sortedOperationResponses(route.responses)) { const statusCode = getOperationStatuscode(resp); const rlcResponseUnit: ResponseMetadata = { @@ -84,12 +90,21 @@ export function transformToResponseTypes( // transform header const headers = transformHeaders(dpgContext, resp, inputImportedSet); // transform body - const body = transformBody(dpgContext, resp, inputImportedSet); + const [body, schemas] = transformBody( + dpgContext, + resp, + inputImportedSet + ) ?? [undefined, []]; rlcOperationUnit.responses.push({ ...rlcResponseUnit, headers, body }); + if (statusCode === "default") { + defaultSchemas.push(...schemas); + } else { + nonDefaultSchemas.push(...schemas); + } } const lroLogicalResponse = transformLroLogicalResponse( dpgContext, @@ -100,15 +115,72 @@ export function transformToResponseTypes( if (lroLogicalResponse) { rlcOperationUnit.responses.push(lroLogicalResponse); } + rlcOperationUnit.isDefaultSupersetOfOthers = + transformIsDefaultSupersetOfOthers( + dpgContext, + defaultSchemas, + nonDefaultSchemas, + getOperationName(dpgContext, route.operation) + ); rlcResponses.push(rlcOperationUnit); } return rlcResponses; } +function transformIsDefaultSupersetOfOthers( + dpgContext: SdkContext, + defaultSchemas: Schema[], + nonDefaultSchemas: Schema[], + operationName: string +): boolean { + if (defaultSchemas.length !== 1 || nonDefaultSchemas.length === 0) { + return false; + } + if (!isObjectSchema(defaultSchemas[0]!)) { + reportDiagnostic(dpgContext.program, { + code: "default-response-body-type", + format: { + operationName + }, + target: NoTarget + }); + return false; + } + const [typeName, properties] = getNameAndPropertyMap(defaultSchemas[0]!); + for (const schema of nonDefaultSchemas) { + if (!isObjectSchema(schema)) { + return false; + } + const [nonDefaultTypeName, nonDefaultProperties] = + getNameAndPropertyMap(schema); + if (typeName === nonDefaultTypeName) { + return true; + } + // check if any properties in default schema is existing in non-default schema + for (const [propName, propTypeName] of properties) { + if (propTypeName === nonDefaultProperties.get(propName)) { + return true; + } + } + } + + return false; +} + +function getNameAndPropertyMap( + schema: ObjectSchema +): [string, Map] { + const map = new Map(); + for (const [key, value] of Object.entries(schema.properties!)) { + map.set(key, getTypeName(value)); + } + return [getTypeName(schema), map]; +} + /** * Return undefined if no valid header param * @param response response detail - * @returns rlc header shcema + * @returns rlc header schema */ function transformHeaders( dpgContext: SdkContext, @@ -162,15 +234,16 @@ function transformBody( dpgContext: SdkContext, response: HttpOperationResponse, importedModels: Set -) { +): [Schema, Schema[]] | undefined { if (!response.responses.length) { return; } - // Currently RLC reponse only have one header and body defined + // Currently RLC response only have one header and body defined // So we'll union all body shapes together with "|" const typeSet = new Set(); const descriptions = new Set(); let fromCore = false; + const schemas = []; for (const data of response.responses) { const body = data?.body; if (!body || isVoidType(body.type)) { @@ -198,18 +271,22 @@ function transformBody( .forEach(importedModels.add, importedModels); } typeSet.add(bodyType); + schemas.push(bodySchema); } if (!typeSet.size) { return; } - return { - name: "body", - type: [...typeSet].join("|"), - description: [...descriptions].join("\n\n"), - fromCore - }; + return [ + { + name: "body", + type: [...typeSet].join("|"), + description: [...descriptions].join("\n\n"), + fromCore + }, + schemas + ]; } function transformLroLogicalResponse( diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/api/operations.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/api/operations.ts index 166ece1a67..c08c3cfb77 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/api/operations.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/rpc/generated/src/api/operations.ts @@ -45,16 +45,16 @@ export async function _longRunningRpcDeserialize( throw createRestError(result); } - result = result as LongRunningRpcLogicalResponse; - if (result?.body?.result === undefined) { + const res = result as unknown as LongRunningRpcLogicalResponse; + if (res?.body?.result === undefined) { throw createRestError( - `Expected a result in the response at position "result.body.result"`, + `Expected a result in the response at position "res.body.result"`, result, ); } return { - data: result.body.result["data"], + data: res.body.result["data"], }; } diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/api/operations.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/api/operations.ts index 9e9d9de722..b336728bc9 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/api/operations.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/core/lro/standard/generated/src/api/operations.ts @@ -59,10 +59,10 @@ export async function _createOrReplaceDeserialize( throw createRestError(result); } - result = result as CreateOrReplaceLogicalResponse; + const res = result as unknown as CreateOrReplaceLogicalResponse; return { - name: result.body["name"], - role: result.body["role"], + name: res.body["name"], + role: res.body["role"], }; } @@ -100,7 +100,6 @@ export async function _$deleteDeserialize( throw createRestError(result); } - result = result as DeleteLogicalResponse; return; } @@ -145,17 +144,17 @@ export async function _$exportDeserialize( throw createRestError(result); } - result = result as ExportLogicalResponse; - if (result?.body?.result === undefined) { + const res = result as unknown as ExportLogicalResponse; + if (res?.body?.result === undefined) { throw createRestError( - `Expected a result in the response at position "result.body.result"`, + `Expected a result in the response at position "res.body.result"`, result, ); } return { - name: result.body.result["name"], - resourceUri: result.body.result["resourceUri"], + name: res.body.result["name"], + resourceUri: res.body.result["resourceUri"], }; } diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/resource-manager/models/resources/src/api/nestedProxyResources/index.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/resource-manager/models/resources/src/api/nestedProxyResources/index.ts index c63a41c362..635a8b2a7e 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/resource-manager/models/resources/src/api/nestedProxyResources/index.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/resource-manager/models/resources/src/api/nestedProxyResources/index.ts @@ -167,32 +167,33 @@ export async function _nestedProxyResourcesCreateOrReplaceDeserialize( throw createRestError(result); } - result = result as NestedProxyResourcesCreateOrReplaceLogicalResponse; + const res = + result as unknown as NestedProxyResourcesCreateOrReplaceLogicalResponse; return { - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - systemData: !result.body.systemData + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData ? undefined : { - createdBy: result.body.systemData?.["createdBy"], - createdByType: result.body.systemData?.["createdByType"], + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], createdAt: - result.body.systemData?.["createdAt"] !== undefined - ? new Date(result.body.systemData?.["createdAt"]) + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) : undefined, - lastModifiedBy: result.body.systemData?.["lastModifiedBy"], - lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], lastModifiedAt: - result.body.systemData?.["lastModifiedAt"] !== undefined - ? new Date(result.body.systemData?.["lastModifiedAt"]) + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) : undefined, }, - properties: !result.body.properties + properties: !res.body.properties ? undefined : { - provisioningState: result.body.properties?.["provisioningState"], - description: result.body.properties?.["description"], + provisioningState: res.body.properties?.["provisioningState"], + description: res.body.properties?.["description"], }, }; } @@ -272,32 +273,32 @@ export async function _nestedProxyResourcesUpdateDeserialize( throw createRestError(result); } - result = result as NestedProxyResourcesUpdateLogicalResponse; + const res = result as unknown as NestedProxyResourcesUpdateLogicalResponse; return { - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - systemData: !result.body.systemData + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData ? undefined : { - createdBy: result.body.systemData?.["createdBy"], - createdByType: result.body.systemData?.["createdByType"], + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], createdAt: - result.body.systemData?.["createdAt"] !== undefined - ? new Date(result.body.systemData?.["createdAt"]) + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) : undefined, - lastModifiedBy: result.body.systemData?.["lastModifiedBy"], - lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], lastModifiedAt: - result.body.systemData?.["lastModifiedAt"] !== undefined - ? new Date(result.body.systemData?.["lastModifiedAt"]) + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) : undefined, }, - properties: !result.body.properties + properties: !res.body.properties ? undefined : { - provisioningState: result.body.properties?.["provisioningState"], - description: result.body.properties?.["description"], + provisioningState: res.body.properties?.["provisioningState"], + description: res.body.properties?.["description"], }, }; } @@ -363,7 +364,6 @@ export async function _nestedProxyResourcesDeleteDeserialize( throw createRestError(result); } - result = result as NestedProxyResourcesDeleteLogicalResponse; return; } diff --git a/packages/typespec-ts/test/modularIntegration/generated/azure/resource-manager/models/resources/src/api/topLevelTrackedResources/index.ts b/packages/typespec-ts/test/modularIntegration/generated/azure/resource-manager/models/resources/src/api/topLevelTrackedResources/index.ts index f7a55b4463..9717bc579b 100644 --- a/packages/typespec-ts/test/modularIntegration/generated/azure/resource-manager/models/resources/src/api/topLevelTrackedResources/index.ts +++ b/packages/typespec-ts/test/modularIntegration/generated/azure/resource-manager/models/resources/src/api/topLevelTrackedResources/index.ts @@ -172,34 +172,35 @@ export async function _topLevelTrackedResourcesCreateOrReplaceDeserialize( throw createRestError(result); } - result = result as TopLevelTrackedResourcesCreateOrReplaceLogicalResponse; + const res = + result as unknown as TopLevelTrackedResourcesCreateOrReplaceLogicalResponse; return { - tags: result.body["tags"], - location: result.body["location"], - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - systemData: !result.body.systemData + tags: res.body["tags"], + location: res.body["location"], + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData ? undefined : { - createdBy: result.body.systemData?.["createdBy"], - createdByType: result.body.systemData?.["createdByType"], + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], createdAt: - result.body.systemData?.["createdAt"] !== undefined - ? new Date(result.body.systemData?.["createdAt"]) + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) : undefined, - lastModifiedBy: result.body.systemData?.["lastModifiedBy"], - lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], lastModifiedAt: - result.body.systemData?.["lastModifiedAt"] !== undefined - ? new Date(result.body.systemData?.["lastModifiedAt"]) + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) : undefined, }, - properties: !result.body.properties + properties: !res.body.properties ? undefined : { - provisioningState: result.body.properties?.["provisioningState"], - description: result.body.properties?.["description"], + provisioningState: res.body.properties?.["provisioningState"], + description: res.body.properties?.["description"], }, }; } @@ -287,34 +288,35 @@ export async function _topLevelTrackedResourcesUpdateDeserialize( throw createRestError(result); } - result = result as TopLevelTrackedResourcesUpdateLogicalResponse; + const res = + result as unknown as TopLevelTrackedResourcesUpdateLogicalResponse; return { - tags: result.body["tags"], - location: result.body["location"], - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - systemData: !result.body.systemData + tags: res.body["tags"], + location: res.body["location"], + id: res.body["id"], + name: res.body["name"], + type: res.body["type"], + systemData: !res.body.systemData ? undefined : { - createdBy: result.body.systemData?.["createdBy"], - createdByType: result.body.systemData?.["createdByType"], + createdBy: res.body.systemData?.["createdBy"], + createdByType: res.body.systemData?.["createdByType"], createdAt: - result.body.systemData?.["createdAt"] !== undefined - ? new Date(result.body.systemData?.["createdAt"]) + res.body.systemData?.["createdAt"] !== undefined + ? new Date(res.body.systemData?.["createdAt"]) : undefined, - lastModifiedBy: result.body.systemData?.["lastModifiedBy"], - lastModifiedByType: result.body.systemData?.["lastModifiedByType"], + lastModifiedBy: res.body.systemData?.["lastModifiedBy"], + lastModifiedByType: res.body.systemData?.["lastModifiedByType"], lastModifiedAt: - result.body.systemData?.["lastModifiedAt"] !== undefined - ? new Date(result.body.systemData?.["lastModifiedAt"]) + res.body.systemData?.["lastModifiedAt"] !== undefined + ? new Date(res.body.systemData?.["lastModifiedAt"]) : undefined, }, - properties: !result.body.properties + properties: !res.body.properties ? undefined : { - provisioningState: result.body.properties?.["provisioningState"], - description: result.body.properties?.["description"], + provisioningState: res.body.properties?.["provisioningState"], + description: res.body.properties?.["description"], }, }; } @@ -390,7 +392,6 @@ export async function _topLevelTrackedResourcesDeleteDeserialize( throw createRestError(result); } - result = result as TopLevelTrackedResourcesDeleteLogicalResponse; return; } diff --git a/packages/typespec-ts/test/modularUnit/anonymousModel.spec.ts b/packages/typespec-ts/test/modularUnit/anonymousModel.spec.ts index 90ce8e39f5..baf3056031 100644 --- a/packages/typespec-ts/test/modularUnit/anonymousModel.spec.ts +++ b/packages/typespec-ts/test/modularUnit/anonymousModel.spec.ts @@ -1054,7 +1054,7 @@ describe("anonymous model", () => { if (result.status !== "200") { throw createRestError(result); } - + return { baz: { foo: result.body.baz["foo"], diff --git a/packages/typespec-ts/test/modularUnit/apiOperations.spec.ts b/packages/typespec-ts/test/modularUnit/apiOperations.spec.ts index 4a21e7b6c0..97a992a397 100644 --- a/packages/typespec-ts/test/modularUnit/apiOperations.spec.ts +++ b/packages/typespec-ts/test/modularUnit/apiOperations.spec.ts @@ -494,7 +494,7 @@ describe("api operations in Modular", () => { if (result.status !== "200") { throw createRestError(result); } - + return result.body; } @@ -622,7 +622,7 @@ describe("api operations in Modular", () => { if (result.status !== "200") { throw createRestError(result); } - + return result.body; } @@ -761,7 +761,6 @@ describe("api operations in Modular", () => { if (result.status !== "200") { throw createRestError(result); } - return result.body; } @@ -789,7 +788,6 @@ describe("api operations in Modular", () => { if (result.status !== "200") { throw createRestError(result); } - return result.body; } diff --git a/packages/typespec-ts/test/modularUnit/modelsGenerator.spec.ts b/packages/typespec-ts/test/modularUnit/modelsGenerator.spec.ts index d9ecb8b29d..a53c569828 100644 --- a/packages/typespec-ts/test/modularUnit/modelsGenerator.spec.ts +++ b/packages/typespec-ts/test/modularUnit/modelsGenerator.spec.ts @@ -182,7 +182,6 @@ describe("modular encode test for property type datetime", () => { if (result.status !== "200") { throw createRestError(result); } - return { prop1: new Date(result.body["prop1"]), prop2: new Date(result.body["prop2"]), @@ -321,7 +320,6 @@ describe("modular encode test for property type datetime", () => { if (result.status !== "200") { throw createRestError(result); } - return { prop1: new Date(result.body["prop1"]), prop2: result.body["prop2"], @@ -406,7 +404,6 @@ describe("modular encode test for property type datetime", () => { if (result.status !== "200") { throw createRestError(result); } - return { prop1: new Date(result.body["prop1"]), prop2: result.body["prop2"], @@ -486,7 +483,6 @@ describe("modular encode test for property type datetime", () => { if (result.status !== "200") { throw createRestError(result); } - return { prop1: new Date(result.body["prop1"]), }; @@ -554,7 +550,6 @@ describe("modular encode test for property type duration", () => { if (result.status !== "200") { throw createRestError(result); } - return { prop1: result.body["prop1"], }; @@ -621,7 +616,6 @@ describe("modular encode test for property type duration", () => { if (result.status !== "200") { throw createRestError(result); } - return { prop1: result.body["prop1"], }; @@ -692,7 +686,6 @@ describe("modular encode test for property type duration", () => { if (result.status !== "200") { throw createRestError(result); } - return { prop1: result.body["prop1"], prop2: result.body["prop2"], @@ -774,7 +767,6 @@ describe("modular encode test for property type bytes", () => { if (result.status !== "200") { throw createRestError(result); } - return { prop1: typeof result.body["prop1"] === "string" @@ -845,7 +837,6 @@ describe("modular encode test for property type bytes", () => { if (result.status !== "200") { throw createRestError(result); } - return { prop1: typeof result.body["prop1"] === "string" @@ -916,7 +907,6 @@ describe("modular encode test for property type bytes", () => { if (result.status !== "200") { throw createRestError(result); } - return { prop1: typeof result.body["prop1"] === "string" @@ -1033,7 +1023,7 @@ describe("inheritance & polymorphism", () => { if (result.status !== "200") { throw createRestError(result); } - + return { name: result.body["name"], weight: result.body["weight"], @@ -1201,7 +1191,7 @@ describe("inheritance & polymorphism", () => { if (result.status !== "200") { throw createRestError(result); } - + return { kind: result.body["kind"], name: result.body["name"], @@ -1290,7 +1280,7 @@ describe("inheritance & polymorphism", () => { if (result.status !== "200") { throw createRestError(result); } - + return result.body; } diff --git a/packages/typespec-ts/test/modularUnit/operations.spec.ts b/packages/typespec-ts/test/modularUnit/operations.spec.ts index 586f794489..cb8f31d9bf 100644 --- a/packages/typespec-ts/test/modularUnit/operations.spec.ts +++ b/packages/typespec-ts/test/modularUnit/operations.spec.ts @@ -631,7 +631,6 @@ describe("operations", () => { if(result.status !== "200"){ throw createRestError(result); } - return { "lists": result.body["lists"] } @@ -699,7 +698,6 @@ describe("operations", () => { if(result.status !== "200"){ throw createRestError(result); } - return { "lists": result.body["lists"] }