Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with IFormFile and IFormFileCollection using AddOpenApiDocument() #2259

Open
skolmer opened this issue Jun 21, 2019 · 7 comments
Open

Comments

@skolmer
Copy link

skolmer commented Jun 21, 2019

Thanks for this great project!
Unfortunately I have some issues with the Open API document generator in ASP.NET Core.
If I use AddOpenApiDocument instead of AddSwaggerDocument, all IFormFile and IFormFileCollection parameters are exported as string or ICollection<string>.
If I switch to AddSwaggerDocument the generated document has the parameter type file and the generated client code uses FileParameter instead of string, which is the expected behavior.

Is this a limitation in the OpenAPI Spec or the implementation or did I miss some configuration detail?
thanks in advance.

@Znow
Copy link

Znow commented Jul 29, 2020

We are facing a similar issue, but here FileParameter is generated when we use IFormFile in C#. What is FileParameter? it is no existing class anywhere...

@jeremyVignelles
Copy link
Collaborator

On the controller side, you declare a Stream or a IFormFile parameter (Stream + file name). The Stream class doesn't serialize correctly into json, so you can't use it on the client side, so NSwag generates a FileParameter class.

@Znow
Copy link

Znow commented Jul 29, 2020

@jeremyVignelles The IFormFile is also generated as a FileParameter class... Which is nowhere to be found, not on any page on the internet. What is this class, why is it generated, and why can it not be found?

@jeremyVignelles
Copy link
Collaborator

If you can't serialize a Stream, you can't serialize something that contains a stream (IFormFile), so FileParameter is generated on your C# client file.

IFormFile -> FileParameter is the expected behavior, IFormFile -> string isn't.

@skolmer : Can you post a repro project somewhere? I've never seen such issue.

@Znow
Copy link

Znow commented Jul 29, 2020

@jeremyVignelles That didnt quite answer my question: "What is this class, why is it generated, and why can it not be found?" FileParameter does not exist anywhere...

@jeremyVignelles
Copy link
Collaborator

I mean that the class is in your C# generated code (if you are using the C# generator).
It is declared like this : https://www.github.com/RicoSuter/NSwag/tree/master/src%2FNSwag.CodeGeneration.CSharp%2FTemplates%2FFile.liquid#L32

It can't really be defined as such because:

  • It's not exactly the same class between C# and Typescript
  • It's a partial class, so you can add your own behavior
  • You can tell NSwag not to generate it and provide your own implementation.

As for the why it is being generated, I think I answered the question properly, but let me correct something. IFormFile is not serialized as JSON. That still stands:

  • IFormFile is an asp.net specific thing, you don't need to reference any part of asp.net to use the API, so you need something to represent the file
  • IFormFile contains the stream, a file name and a content type. you need a class to hold the two components

Why can't you find it anywhere? because of the usual issue with many projects : documentation.
Now the best thing you could do is contribute to the NSwag wiki page and explain that to others.

Now, please stop polluting the issue with your questions. Either come and chat on gitter, or open your own question. This discussion is unrelated to the initial topic.

@palapapa
Copy link

palapapa commented Dec 1, 2024

This is still a problem... The overall support for OpenAPI 3 is poor it seems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants