From 516d3953861154934c5952098daf1c6b5d3f6659 Mon Sep 17 00:00:00 2001 From: xichen Date: Tue, 18 Aug 2020 11:28:00 +0800 Subject: [PATCH] fix header issue --- powershell/plugins/plugin-tweak-m4-model.ts | 7 ++++++- powershell/plugins/plugin-tweak-model.ts | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/powershell/plugins/plugin-tweak-m4-model.ts b/powershell/plugins/plugin-tweak-m4-model.ts index d3e54b796a..b9a7594206 100644 --- a/powershell/plugins/plugin-tweak-m4-model.ts +++ b/powershell/plugins/plugin-tweak-m4-model.ts @@ -25,7 +25,8 @@ async function tweakModel(state: State): Promise { } function addResponseHeaderSchema(model: CodeModel) { - // In remodler, each operations response headers will has its own scheam. Each header will be schema's property. But in m4, there won't be a schema for headers. + // In remodeler, each operations response headers will has its own scheam. Each header will be schema's property. + // But in m4, if 'schema' is not explicitly defined, even 'headers' is specified, there won't be a schema for headers. // To keep backward compatiable, we will create headers schema here model.operationGroups.forEach((group) => { @@ -34,6 +35,10 @@ function addResponseHeaderSchema(model: CodeModel) { return; } op.responses.forEach((resp) => { + if ((resp).schema) { + return; + } + const headers = resp.protocol.http?.headers as Array; if (headers === undefined) { return; diff --git a/powershell/plugins/plugin-tweak-model.ts b/powershell/plugins/plugin-tweak-model.ts index 5171af771d..ea298ffe5e 100644 --- a/powershell/plugins/plugin-tweak-model.ts +++ b/powershell/plugins/plugin-tweak-model.ts @@ -188,7 +188,7 @@ async function tweakModelV2(state: State): Promise { if ((response as any).schema.type === SchemaType.Object) { const respSchema = (response as any).schema as ObjectSchema; const curHeader = header as any; - const headerKey = curHeader as string; + const headerKey = curHeader.header as string; respSchema.language.default.hasHeaders = true; @@ -197,7 +197,7 @@ async function tweakModelV2(state: State): Promise { state.message({ Channel: Channel.Debug, Text: `Adding header property '${headerKey}' to model ${respSchema.language.default.name}` }); // create a property for the header value - const newProperty = new Property(headerKey, curHeader.description, curHeader.schema); + const newProperty = new Property(headerKey, curHeader.description || '', curHeader.schema); newProperty.language.default.required = false; // mark it that it's a header-only property