Skip to content

Modules with operation objects that return enum type responses fail to build #973

@peombwa

Description

@peombwa

Given the following OpenAPI v3.0.1 document with an operation object that returns an enum type as its response:

paths:
  /deviceManagement/chromeOSOnboardingSettings/microsoft.graph.connect:
    post:
      tags:
        - deviceManagement.Actions
      summary: Invoke action connect
      operationId: deviceManagement.chromeOSOnboardingSettings_connect
      requestBody:
        description: Action parameters
        content:
          application/json:
            schema:
              type: object
              properties:
                ownerUserPrincipalName:
                  type: string
                  nullable: true
        required: true
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/microsoft.graph.chromeOSOnboardingStatus'
        default:
          $ref: '#/components/responses/error'
      x-ms-docs-operation-type: action
components:
  schemas:
    microsoft.graph.chromeOSOnboardingStatus:
      title: chromeOSOnboardingStatus
      enum:
        - unknown
        - inprogress
        - onboarded
        - failed
        - offboarding
        - unknownFutureValue
      type: string
      description: The onboarding status of the tenant.
      x-ms-enum:
        name: chromeOSOnboardingStatus
        modelAsString: false
        values:
          - value: unknown
            description: Unknown
            name: unknown
...(shortened)...

Current Behavior

The generated module fails with the following compilation error when running .\generated\build-module.ps1 script:

Creating isolated process...
Cleaning build folders...
Compiling module...
F:\temp\AutoREST.Test\generated\generated\api\DeviceManagementActions.cs(82,50): 
error CS1503: Argument 2: cannot convert from 'System.Threading.Tasks.Task<string>' to 'System.Threading.Tasks.Task<Sample.API.Support.ChromeOSOnboardingStatus>' [F:\temp\Aut 
oREST.Test\generated\DeviceActions.csproj]
Write-Error: F:\temp\AutoREST.Test\generated\build-module.ps1:76:5

Expected Behavior

The generated module should build successfully when an operation returns an enum type as its response.

Repro Steps

Sample OpenAPI document - https://gist.github.com/peombwa/b2758d2425205d0e51c9bf8cae1fbec7

#1. CD to output directory
#2. Generate module using sample OpenAPI document 
autorest --powershell --input-file:https://gist.githubusercontent.com/peombwa/b2758d2425205d0e51c9bf8cae1fbec7/raw/d6fb8178356c2cb9415de828a58450804391d269/DeviceManagement.yml
#3. Build generated module
.\generated\build-module.ps1
#4. Compilation error is thrown
cannot convert from 'System.Threading.Tasks.Task<string>' to 'System.Threading.Tasks.Task<Sample.API.Support.ChromeOSOnboardingStatus>'
Environment
AutoRest code generation utility [cli version: 3.6.2; node: v14.11.0]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
info    |    Loading AutoRest core      'C:\Users\peter\.autorest\@autorestcore@3.8.4\nodemodules\@autorest\core\dist' (3.8.4)
info    | 
The default version of @autorest/powershell has been bumped from 2.1+ to 3.0+.
 > If you still want to use 2.1+ version, please specify it with --use:@autorest/powershell@2.1.{x}, e.g 2.1.401.

info    |    Loading AutoRest extension '@autorest/powershell' (~3.0.0->3.0.485)
info    |    Loading AutoRest extension '@autorest/modelerfour' (4.15.414->4.15.414)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions