question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[C#] Autorest client not generated for endpoints with file parameters

See original GitHub issue

Problem

I have an endpoint that allows uploading a file. After updating to the latest version of Autorest, I can’t generate a client anymore and receive a generic error. I went through the issues here but didn’t find an answer. I’m still using OpenApi2.0 spec. According to the spec, I’m setting all the parameters needed. Running autorest with --verbose --debug parameters didn’t give me any additional info.

Failing example

{
  "swagger": "2.0",
  "info": {
    "title": "test",
    "description": "test",
    "version": "v1"
  },
  "paths": {
    "/logo": {
      "put": {
        "tags": [
          "test"
        ],
        "summary": "test",
        "description": "test",
        "operationId": "test",
        "consumes": [
          "multipart/form-data"
        ],
        "produces": [
        ],
        "parameters": [
          {
            "in": "formData",
            "name": "formFile",
            "description": "The file to upload.",
            "required": true,
            "type": "file"
          }
        ],
        "responses": {
          "204": {
            "description": "Success."
          }
        }
      }
    }
  },
  "definitions": {
  },
  "securityDefinitions": {
  }
}

Error details

FATAL: System.ArgumentNullException: Value cannot be null.
Parameter name: source
   at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable1 source, Func2 selector)
   at AutoRest.Modeler.Model.RequestBody.AsParameters() in /opt/vsts/work/1/s/src/Model/RequestBody.cs:line 38
   at AutoRest.Modeler.SwaggerModeler.Unwrap(SwaggerParameter swaggerParameter) in /opt/vsts/work/1/s/src/SwaggerModeler.cs:line 452
   at AutoRest.Modeler.OperationBuilder.BuildMethodParameters(Method method) in /opt/vsts/work/1/s/src/OperationBuilder.cs:line 255
   at AutoRest.Modeler.OperationBuilder.BuildMethod(HttpMethod httpMethod, String url, String methodName, String methodGroup) in /opt/vsts/work/1/s/src/OperationBuilder.cs:line 100
   at AutoRest.Modeler.SwaggerModeler.BuildMethod(HttpMethod httpMethod, String url, String name, Operation operation) in /opt/vsts/work/1/s/src/SwaggerModeler.cs:line 404
   at AutoRest.Modeler.SwaggerModeler.Build(ServiceDefinition serviceDefinition) in /opt/vsts/work/1/s/src/SwaggerModeler.cs:line 106
   at AutoRest.Modeler.Program.<ProcessInternal>d__2.MoveNext() in /opt/vsts/work/1/s/src/Program.cs:line 60
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NewPlugin.<Process>d__15.MoveNext()
/private/var/root/.autorest/@autorest_core@3.0.6262/node_modules/@autorest/core/dist/lib/pipeline/pipeline.js - FAILURE {}
Process() cancelled due to exception : Plugin imodeler1 reported failure. / Error: Plugin imodeler1 reported failure.
    at /private/var/root/.autorest/@autorest_core@3.0.6262/node_modules/@autorest/core/dist/lib/pipeline/plugins/external.js:26:19
    at async ScheduleNode (/private/var/root/.autorest/@autorest_core@3.0.6262/node_modules/@autorest/core/dist/lib/pipeline/pipeline.js:294:33)
  Error: Plugin imodeler1 reported failure.

Autorest version

autorest --info
AutoRest code generation utility [cli version: 3.0.6187; node: v12.13.0, max-memory: 8192 gb]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest


Showing All Installed Extensions

 Type       Extension Name                           Version      Location 
 core       @autorest/core                           3.0.6262     /var/root/.autorest/@autorest_core@3.0.6262
 extension  @microsoft.azure/autorest.csharp         2.3.84       /var/root/.autorest/@microsoft.azure_autorest.csharp@2.3.84
 extension  @microsoft.azure/autorest.modeler        2.3.55       /var/root/.autorest/@microsoft.azure_autorest.modeler@2.3.55

Maybe related issues:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ANovitskycommented, Jul 24, 2020

Why all issues about it closed? This is not resolved yet!.

We cannot use “in”: “formData”, every time error. For file or for string.

2reactions
nfidirkocommented, Apr 28, 2020

@OzBob, @fearthecowboy, thanks for your answers. unfortunately, it still doesn’t work with autorest v3.0.6262

Using:

"type": "object",
"format": "file"

causes another error:

ERROR: Schema violation: Data does not match any schemas from 'oneOf'

I ended up using an older version of autorest: 2.0.4413

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix Autorest Problems when Generating Client ... - Angela Evans
Problem 1 – FATAL: Error parsing swagger file. Error converting value False to type 'AutoRest.Modeler.Model.Schema' ... Reason: Autorest cannot ...
Read more >
c# - Autorest Failed resolving swagger.json against file when ...
json from local host into a file then I can generate the client. In startup.ConfigureServices I have services.AddSwaggerGen(c => { c.SwaggerDoc( ...
Read more >
Seven Tips For Using Swagger And AutoRest Together In ...
Swagger needs unique paths across all endpoints of your service/app. ... AutoRest will generate models for the client from the swagger ...
Read more >
How to Automatically Generate Clients for your REST API
In this guide, you'll learn how to set up AutoRest to leverage the OpenAPI specification, and to generate a client for you. We'll...
Read more >
Java Integration | Swagger Open Source
SwagDoc is a Delphi library to generate swagger.json file for Swagger Spec version 2.0. Create a public documentation REST API using Swagger 2.0...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found