Skip to content

PowerShell cmdlet generation fails if a parameter is named Pipeline #5092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
fzkhan opened this issue Mar 23, 2025 · 0 comments
Open
2 tasks done

PowerShell cmdlet generation fails if a parameter is named Pipeline #5092

fzkhan opened this issue Mar 23, 2025 · 0 comments

Comments

@fzkhan
Copy link
Member

fzkhan commented Mar 23, 2025

Before filling a bug

  • have you checked the faq for known issues.
  • have you checked existing issues

Describe the bug

Please provide as much information as you can. This would be:
- OpenAPI files having the issues
- Autorest command used

When I have a parameter named pipeline in the OpenAPI spec, trying to build PowerShell cmdlets fails with this error:

error CS0102: The type 'SetResource_Put' already contains a definition for 'Pipeline'

To reproduce, here is a minimal OpenAPI spec:

{
  "swagger": "2.0",
  "info": {
    "title": "Example Client",
    "description": "Example service client",
    "version": "2.0"
  },
  "host": "localhost:3456",
  "schemes": ["http"],
  "consumes": ["application/json"],
  "produces": ["application/json"],
  "paths": {
    "/examples": {
      "put": {
        "operationId": "putResource",
        "description": "Put a resource onto our servers",
        "parameters": [
          {
            "name": "pipeline",
            "in": "body",
            "description": "Parameter names Pipeline",
            "schema": {
              "$ref": "#/definitions/Resource"
            },
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "Received correct resource",
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "Error": {
      "type": "object",
      "properties": {
        "status": {
          "type": "integer",
          "format": "int32"
        },
        "message": {
          "type": "string"
        }
      }
    },
    "Resource": {
      "type": "object",
      "properties": {}
    }
  }
}

Sample README file:

input-file: ./example.json
powershell: true
output-folder: Output/generated
clear-output-folder: true

PS commands:

autorest .\README.md
Set-Location .\Output\generated
./build-module.ps1

This fails with the above mentioned error. The reason seems to be naming conflicts with the internal pipeline the generated code is using:

        /// <summary>
        /// The instance of the <see cref="Sample.API.Runtime.HttpPipeline" /> that the remote call will use.
        /// </summary>
        public Sample.API.Runtime.HttpPipeline Pipeline { get; set; }

        /// <summary>Anything</summary>
        [global::System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "Anything", ValueFromPipeline = true)]
        [Sample.API.Runtime.Info(
        Required = true,
        ReadOnly = false,
        Description = @"Anything",
        SerializedName = @"pipeline",
        PossibleTypes = new [] { typeof(Sample.API.Models.IAny) })]
        [global::Sample.API.Category(global::Sample.API.ParameterCategory.Body)]
        public Sample.API.Models.IAny Pipeline { get => this._pipeline; set => this._pipeline = value; }

Expected behavior
If we rename the parameter to anything other than pipeline, the module builds just fine.

Additional context
We have an ARM resource named pipeline and we would like to preserve the naming to maintain UX consistency.

Attached the erroring generated file for reference. (Sorry, GitHub does not allow .cs files, so renamed to .txt)
SetResource_Put.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant