swagger-api / swagger-api/swagger-codegen

Java Client Generated by Swagger Codegen v2 has wrong parameter type for File parameters, should use InputStream not java.io.File

Open
#10,517 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Using Swagger v2, and Swagger Codegen v2, if you have an API which has a File parameter, Swagger Codegen will generate a function parameter that is of type system.io.File

However, this is basically useless because it means that you cannot pass in any type of Stream, such as an in-memory stream - you can ONLY pass in a java.io.File. Because system.io.File in Java can only be used to read a file from the file system, you cannot use non-filestream sources.

This is a huge oversight, and there does not seem to be a way to configure it to use InputStream or some other more abstract type that would be sane.

This is in contrast to the .NET Swagger Codegen which correctly uses the abstract stream type instead of hard-coding File.

Swagger-codegen version

2.4.14

Swagger declaration file content or url

https://api.cloudmersive.com/swagger/api/virus

Command line used for generation

Any will reproduce

Steps to reproduce

See above

Related issues/PRs

Could not find any

Suggest a fix/enhancement

Change the template for Java to generate InputStream instead of java.io.File for File parameter types

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Java client generation templates and reproduce the issue using the Cloudmersive virus API Swagger declaration with swagger-codegen 2.4.14. Check the generated method signatures for File parameters; done means those parameters use InputStream while the generated client remains usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.