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
  • #11132
Closed
Open
Issue created Dec 15, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][aspnetcore] FileParameters should be refactor to multimap and support content-type

Created by: joaocmendes

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Build fails for a request with multipart-form-data when there is multiple files for the same field. The client receives a List but this can't be handled by RequestOptions because it only accepts a single file for the same key.

The API consumed requires the content-type for the file sent (e.g. application/pdf, image/png). There is no way to achieve this with the actual generator.

openapi-generator version

openapi-generator-cli-5.3.0.jar

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "Test API",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "/ocrapis"
    }
  ],
  "paths": {
    "/api/v1/Documents/{entityName}": {
      "post": {
        "tags": [
          "Documents"
        ],
        "summary": "Returns Extraction Result of Your Request",
        "parameters": [
          {
            "name": "entityName",
            "in": "path",
            "description": "Tenant Name",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "UploadedFiles": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    },
                    "description": "Files to be Extracted"
                  },
                  "UploadedFileTypes": {
                    "type": "string",
                    "description": "File Type"
                  },
                  "ProjectName": {
                    "type": "string",
                    "description": "Project Name of Tenant"
                  }
                }
              },
              "encoding": {
                "UploadedFiles": {
                  "style": "form",
				          "contentType": "application/pdf"
                },
                "UploadedFileTypes": {
                  "style": "form"
                },
                "ProjectName": {
                  "style": "form"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfull Request",
            "content": {
              "application/json": {
                "schema": {
                "type": "object"	
                }
              }
            }
          }
        }
      }
    },
  }
}
Generation Details

java -jar openapi-generator-cli-5.3.0.jar generate -i swagger.json -g csharp-netcore -o testNew

Steps to reproduce

generate the code build the code it fails with Error CS1503 Argument 2: cannot convert from 'System.Collections.Generic.List<System.IO.Stream>' to 'System.IO.Stream'

Suggest a fix

Change on RequestOptions class the field FileParameters from Dictionary<string, Stream> to Multimap<string, Stream> would fix the issue as follows:

// Actual 
public Dictionary<string, Stream> FileParameters { get; set; }

// New 
public Multimap<string, Stream> FileParameters { get; set; }

This fix also requires a change at ApiClient to iterate the multiples files under the same key. Code block: image

FileParameters should support the defintion of a ContentType or the code could infer from the file extension (but it can be tricky not for the common types like pdf but for some ambiguous types). It's already supported by aspnetcore httpClient and RestSharp when creating file as follows:

public static FileParameter Create(string name, byte[] data, string filename, string contentType);
Assignee
Assign to
Time tracking