From b87b8b9d9632b4df1fec536fe37d042a6502fd29 Mon Sep 17 00:00:00 2001 From: Xiaogang Date: Mon, 8 Jul 2024 14:52:13 +0800 Subject: [PATCH] Add 200 response for lro deletion if it is not defined (#1351) --- powershell/plugins/plugin-tweak-model-azure-v2.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/powershell/plugins/plugin-tweak-model-azure-v2.ts b/powershell/plugins/plugin-tweak-model-azure-v2.ts index a1d59331..36616b24 100644 --- a/powershell/plugins/plugin-tweak-model-azure-v2.ts +++ b/powershell/plugins/plugin-tweak-model-azure-v2.ts @@ -9,7 +9,7 @@ import { keys, length, values } from '@azure-tools/linq'; import { Channel, AutorestExtensionHost as Host } from '@autorest/extension-base'; import { ModelState } from '../utils/model-state'; import { PwshModel } from '../utils/PwshModel'; -import { getAllProperties, ObjectSchema, Response, SchemaType, Schema } from '@autorest/codemodel'; +import { getAllProperties, ObjectSchema, Response, SchemaType, Schema, Protocols, Protocol } from '@autorest/codemodel'; import { serialize } from '@azure-tools/codegen'; type State = ModelState; @@ -117,6 +117,16 @@ export async function tweakModel(state: State): Promise { operation.responses = (>(operation.responses)).filter(each => each.protocol.http?.statusCodes[0] !== '201' && each.protocol.http?.statusCodes[0] !== '202'); //delete operation.responses['201']; //delete operation.responses['202']; + + // for lro deletion, we need to add the 200 response if it's not already there. + if (operation.requests && operation.requests[0].protocol.http?.method === 'delete') { + if (!operation.responses.find(each => each.protocol.http?.statusCodes[0] === '200')) { + const response = new Response(); + response.protocol.http = response.protocol.http ?? new Protocol(); + response.protocol.http.statusCodes = ['200']; + operation.responses.push(response); + } + } } } }