Azure / autorest.powershell

AutoRest PowerShell Generator
MIT License
113 stars 86 forks source link

Feature Request : support streams for non-json content payloads #206

Open TylerLeonhardt opened 5 years ago

TylerLeonhardt commented 5 years ago

I have the following openapi.yml:

openapi: 3.0.1
info:
  title: MtRainier
  description: Gets whether the mountain is out!
  version: 1.0.0
servers:
- url: https://themtn.azurewebsites.net/
paths:
  /:
    get:
      summary: Gets whether the mountain is out! 
      operationId: MtRainer_invoke
      responses:
        200:
          description: OK
          content:
            text/html:
              schema:
                type: string
  /api:
    get:
      summary: Gets whether the mountain is out! 
      operationId: MtRainer_get
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MtRainer"
components:
  schemas:
    MtRainer:
      type: object
      properties:
        result:
          type: boolean
        image:
          type: string

Note, the / route (ignore the /api route). It returns a:

text/html:
    schema:
        type: string

When I generate and run the command, I get an NullRef.:

❯❯❯ autorest --input-file=./openapi.yml --powershell

AutoRest code generation utility [version: 3.0.5166; node: v10.15.0]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
   Loading AutoRest core      '/Users/tyler/.autorest/@microsoft.azure_autorest-core@3.0.5402/node_modules/@microsoft.azure/autorest-core/dist' (3.0.5402)
   Loading AutoRest extension '@microsoft.azure/autorest.powershell' (beta->2.0.347)
   Loading AutoRest extension '@microsoft.azure/autorest.remodeler' (beta->2.0.213)
   Loading AutoRest extension '@microsoft.azure/autorest.csharp-v2' (beta->2.0.227)
--------------------------------------------------------------------

❯❯❯ cd ./generated/

❯❯❯ ./build-module.ps1 -Run

Creating isolated process...
Cleaning build folders...
Compiling module...
-------------Done-------------
Creating isolated process...

PS /Users/tyler/Code/PowerShell/AutoRest/IsTheMtnOut/generated [MtRainier]> Invoke-InvokeMtRainer

Invoke-InvokeMtRainer : Object reference not set to an instance of an object.
At line:1 char:1
+ Invoke-InvokeMtRainer
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Invoke-InvokeMtRainer], NullReferenceException
+ FullyQualifiedErrorId : Sample.API.Cmdlets.InvokeInvokeMtRainer

PS /Users/tyler/Code/PowerShell/AutoRest/IsTheMtnOut/generated [MtRainier]> $Error[0].Exception.StackTrace

   at Sample.API.Cmdlets.InvokeInvokeMtRainer.onOK(HttpResponseMessage responseMessage, Task`1 response) in /Users/tyler/Code/PowerShell/AutoRest/IsTheMtnOut/generated/generated/cmdlets/InvokeInvokeMtRainer.cs:line 269
   at Sample.API.MtRainier.MtRainerInvoke_Call(HttpRequestMessage request, Func`3 onOK, IEventListener eventListener, ISendAsync sender) in /Users/tyler/Code/PowerShell/AutoRest/IsTheMtnOut/generated/generated/api/MtRainier.cs:line 146
   at Sample.API.MtRainier.MtRainerInvoke_Call(HttpRequestMessage request, Func`3 onOK, IEventListener eventListener, ISendAsync sender) in /Users/tyler/Code/PowerShell/AutoRest/IsTheMtnOut/generated/generated/api/MtRainier.cs:line 161
   at Sample.API.MtRainier.MtRainerInvoke(Func`3 onOK, IEventListener eventListener, ISendAsync sender) in /Users/tyler/Code/PowerShell/AutoRest/IsTheMtnOut/generated/generated/api/MtRainier.cs:line 119
   at Sample.API.Cmdlets.InvokeInvokeMtRainer.ProcessRecordAsync() in /Users/tyler/Code/PowerShell/AutoRest/IsTheMtnOut/generated/generated/cmdlets/InvokeInvokeMtRainer.cs:line 226
   at Sample.API.Cmdlets.InvokeInvokeMtRainer.ProcessRecordAsync() in /Users/tyler/Code/PowerShell/AutoRest/IsTheMtnOut/generated/generated/cmdlets/InvokeInvokeMtRainer.cs:line 232
PS /Users/tyler/Code/PowerShell/AutoRest/IsTheMtnOut/generated [MtRainier]>

Side issue... I expected the cmdlet name to be Invoke-MtRainier not Invoke-InvokeMtRainer...

FWIW, the Get-MtRainier cmdlet works with the output type of object.

TylerLeonhardt commented 5 years ago
await onOk(_response,null /* deserializeFromResponse doesn't support '-none-' /Users/tyler/.autorest/@microsoft.azure_autorest.csharp-v2@2.0.227/node_modules/@microsoft.azure/autorest.csharp-v2/dist/schema/string.js*/);

null is passed into onOk it seems... I changed that to:

await onOk(_response,_response.Content.ReadAsStringAsync());

and the cmdlet worked as expected.

fearthecowboy commented 5 years ago

We don't currently handle response content type text/html . Probably will handle that when I get back to finishing streams.

TylerLeonhardt commented 5 years ago

I also get this with text/plain. Is that in the same boat?

fearthecowboy commented 5 years ago

Yes, given that we don't have content handling for anything other than JSON at the moment.

The serializer stuff is 'pluggable', but not fully complete yet.

TylerLeonhardt commented 5 years ago

Thanks for the info! I'm giving a talk today on AutoRest.powershell in Seattle and I'll be sure to call out that caveat.

fearthecowboy commented 5 years ago

Where Today?

TylerLeonhardt commented 5 years ago

This meetup downtown: https://www.meetup.com/Seattle-Web-App-Developers-Group/events/259603088/

eosfor commented 5 years ago

Hello @TylerLeonhardt , @fearthecowboy , @markcowl

is it supported now? what do I do if API returns just a plain text?

darrelmiller commented 4 years ago

@dolauli Do you have any status update on this item? There are a number of APIs in Graph that require us to send and receive non-json payloads.