Azure / autorest.csharp

Extension for AutoRest (https://github.com/Azure/autorest) that generates C# code
MIT License
142 stars 166 forks source link

[Bug] BuildObject with Multipart from ... #1283

Open janek9971 opened 3 years ago

janek9971 commented 3 years ago

I encountered an internal error in autorest for method in api called UploadPicture. Nswag did not have any problem with this.

I attach zipped Configuration.json and CodeModel.yaml Configuration.zip

Error message:

Exception: BuildObject with Multipart from UploadPicture at AutoRest.CSharp.Output.Builders.SerializationBuilder.BuildObject(KnownMediaType mediaType, ObjectSchema objectSchema, SchemaObjectType type) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Output\Builders\SerializationBuilder.cs:line 28 at AutoRest.CSharp.Output.Models.Types.SchemaObjectType.b__45_0(KnownMediaType type) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Output\Models\Types\SchemaObjectType.cs:line 333 at System.Linq.Enumerable.SelectEnumerableIterator2.ToArray() at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at AutoRest.CSharp.Output.Models.Types.SchemaObjectType.BuildSerializations() in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Output\Models\Types\SchemaObjectType.cs:line 328 at AutoRest.CSharp.Output.Models.Types.SchemaObjectType.get_Serializations() in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Output\Models\Types\SchemaObjectType.cs:line 66 at AutoRest.CSharp.Generation.Writers.SerializationWriter.WriteObjectSerialization(CodeWriter writer, SchemaObjectType model) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Generation\Writers\SerializationWriter.cs:line 34 at AutoRest.CSharp.Generation.Writers.SerializationWriter.WriteSerialization(CodeWriter writer, TypeProvider schema) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Common\Generation\Writers\SerializationWriter.cs:line 30 at AutoRest.CSharp.AutoRest.Plugins.DataPlaneTarget.Execute(GeneratedCodeWorkspace project, CodeModel codeModel, SourceInputModel sourceInputModel, Configuration configuration) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\DataPlane\AutoRest\DataPlaneTarget.cs:line 34 at AutoRest.CSharp.AutoRest.Plugins.CSharpGen.ExecuteAsync(Task`1 codeModelTask, Configuration configuration) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Common\AutoRest\Plugins\CSharpGen.cs:line 56 at AutoRest.CSharp.AutoRest.Plugins.CSharpGen.Execute(IPluginCommunication autoRest) in D:\a\1\s\autorest.csharp\src\AutoRest.CSharp\Common\AutoRest\Plugins\CSharpGen.cs:line 96

AlexGhiondea commented 3 years ago

@AlexanderSher could you take a look?

AlexanderSher commented 3 years ago

Minimal input to repro the issue:

openapi: "3.0.0"
info:
  title: Multipart
  version: 1.0.0
servers:
  - url: http://test.swagger.io/v1
paths:
  /op:
    post:
      operationId: testOp
      responses:
        '201':
          description: Null response
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                test:
                  type: object
                  properties:
                    nested:
                      type: integer
                fileName:
                  type: string
                  format: binary
AlexanderSher commented 3 years ago

This is an object schema that has serializationFormats that isn't supported.

  objects:
    - !ObjectSchema &ref_2
      type: object
      apiVersions:
        - !ApiVersion 
          version: 1.0.0
      properties:
        - !Property 
          schema: *ref_1
          serializedName: nested
          language: !Languages 
            default:
              name: nested
              description: ''
          protocol: !Protocols {}
      serializationFormats:
        - multipart
      usage:
        - input
      extensions:
        x-internal-autorest-anonymous-schema:
          anonymous: true
      language: !Languages 
        default:
          name: PostContentSchemaTest
          description: ''
          namespace: ''
      protocol: !Protocols {}
cfculhane commented 3 years ago

I had the same issue: https://github.com/Azure/autorest.csharp/issues/1455

It looks to be related to any multipart request body having more than one type?

AlexanderSher commented 3 years ago

Also maybe related to this one: https://github.com/Azure/autorest.csharp/issues/985