Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #2398
Closed
Open
Issue created Mar 14, 2019 by Administrator@rootContributor

[C#] aspnetcore / server: Property type binary generates Stream instead of IFormFile

Created by: jnnwnk

Description

I try to generate a ASP .NET Core server side library for file uploads. All examples I've seen so far are using the C# type IFormFile to receive file content. However if I declare an interface with content type multipart/form-data and a property of type string with format binary (see yaml snippet) openapi generates a method parameter of type `` System.IO.Stream. If I try uploading a file using this interface I am getting an exception:

System.InvalidOperationException: Could not create an instance of type 'System.IO.Stream'. Model bound complex types must not be abstract or value types and must have a parameterless constructor. Alternatively, give the 'image' parameter a non-null default value.
   at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ComplexTypeModelBinder.CreateModel(ModelBindingContext bindingContext)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.ComplexTypeModelBinder.BindModelCoreAsync(ModelBindingContext bindingContext)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()

Am I missing something or is there any kind of workaround (make System.IO.Stream working or forcing openapi to use IFormFile)?

openapi-generator version

3.3.4

OpenAPI declaration file content or url

openapi.yaml

Command line used for generation

java -jar openapi-generator-cli-3.3.4.jar generate -i openapi.yaml -g aspnetcore --model-name-suffix DTO

Steps to reproduce
  1. Use openapi.yaml to call command line.
  2. Have a look at the generated file FileUploadApiController.
  3. If you want to reproduce the exception in action: Create a small implementation an try posting a file to http://127.0.0.1/api/upload
Related issues/PRs

There is a similar issue #1381 about problems with files on client side in C#. And also one about generation of byte/binary body in C# aspdotnet service side: #1327

Suggest a fix/enhancement

In my opinion best / easiest would be if the generated method uses IFormFile. Other options could be to make this some how configurable or to generate additional code to make Stream work out of the box. I came acrose an example suggested on stackoverflow to make Stream working, but I guess this is .NET Framework. Anyway I'v not tested it yet.

Assignee
Assign to
Time tracking