From 5230bb72c7c7adb3285664a686910951a6693e21 Mon Sep 17 00:00:00 2001 From: xichen Date: Thu, 20 Aug 2020 12:59:10 +0800 Subject: [PATCH] skip content type request parameter --- powershell/autorest-configuration.md | 1 + powershell/llcsharp/operation/method.ts | 16 +++++++++------- powershell/plugins/create-commands-v2.ts | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/powershell/autorest-configuration.md b/powershell/autorest-configuration.md index 3426260430..3fe4418021 100644 --- a/powershell/autorest-configuration.md +++ b/powershell/autorest-configuration.md @@ -10,6 +10,7 @@ modelerfour: emit-yaml-tags: false lenient-model-deduplication: true additional-checks: false + always-create-content-type-parameter: false ``` > if the modeler is loaded already, use that one, otherwise grab it. diff --git a/powershell/llcsharp/operation/method.ts b/powershell/llcsharp/operation/method.ts index f20a51ef63..127dc877cc 100644 --- a/powershell/llcsharp/operation/method.ts +++ b/powershell/llcsharp/operation/method.ts @@ -348,13 +348,15 @@ export class NewOperationMethod extends Method { // add body paramter if there should be one. if (this.operation.requests && this.operation.requests.length && this.operation.requests[0].parameters && this.operation.requests[0].parameters.length) { // this request does have a request body. - const param = this.operation.requests[0].parameters[0]; - this.bodyParameter = new NewOperationBodyParameter(this, 'body', param.language.default.description, param.schema, param.required ?? false, this.state, { - // TODO: temp solution. We need a class like NewKnowMediaType - mediaType: knownMediaType(KnownMediaType.Json), - contentType: KnownMediaType.Json - }); - this.addParameter(this.bodyParameter); + const param = this.operation.requests[0].parameters.find((p) => !p.origin || p.origin.indexOf('modelerfour:synthesized') < 0); + if (param) { + this.bodyParameter = new NewOperationBodyParameter(this, 'body', param.language.default.description, param.schema, param.required ?? false, this.state, { + // TODO: temp solution. We need a class like NewKnowMediaType + mediaType: knownMediaType(KnownMediaType.Json), + contentType: KnownMediaType.Json + }); + this.addParameter(this.bodyParameter); + } } for (const response of [...values(this.operation.responses), ...values(this.operation.exceptions)]) { diff --git a/powershell/plugins/create-commands-v2.ts b/powershell/plugins/create-commands-v2.ts index 25f558d4d7..d1e71f4d10 100644 --- a/powershell/plugins/create-commands-v2.ts +++ b/powershell/plugins/create-commands-v2.ts @@ -408,7 +408,7 @@ export /* @internal */ class Inferrer { // the body parameter // xichen: How to handle if has multiple requests? - const body = (operation.requests && operation.requests[0].parameters) ? operation.requests[0].parameters[0] : null; + const body = operation.requests?.[0].parameters?.find((p) => !p.origin || p.origin.indexOf('modelerfour:synthesized') < 0) || null; // skip-for-time-being, looks x-ms-requestBody-name is not supported any more //const bodyParameterName = (operation.requestBody && operation.requestBody.extensions) ? operation.requestBody.extensions['x-ms-requestBody-name'] || 'bodyParameter' : ''; const bodyParameterName = body ? body.language.default.name : '';