Azure / autorest.powershell

AutoRest PowerShell Generator
MIT License
111 stars 76 forks source link

OpenAPI 3.0 parameterized host not being used in cmdlets for url #1211

Closed srtjohn closed 10 months ago

srtjohn commented 10 months ago

When using autorest/core 3.9.7, autorest/powershell 3.0.415 and the following OpenAPI

openapi": "3.0.1",
servers": [
{
    "url" : "{adminUrl}",
    "description" : "admin url",
      "variables": {
       "adminUrl": {
          "description": "My admin url",
          "default": "https://localhost:31443"
        }
      }
    }
  ],

The cmdlet's get generated with the parameter adminUrl however when it builds the URL the {adminUrl} variable is missing, this is the code generated

            // generate request object
            var _url = new global::System.Uri($"{pathAndQuery}");
            var request =  new global::System.Net.Http.HttpRequestMessage(Titan.API.Runtime.Method.Post, _url);

Am I missing something in the OpenAPI spec or perhaps some other custom attribute I need to set ? Thanks for any help.

dolauli commented 10 months ago

@srtjohn 3.0.415 is too old. Please upgrade to the latest version of 3.x (3.0.509). And the generated code should be as below.

var _url = new global::System.Uri($"{adminUrl}{pathAndQuery}");