OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] incorrect consumes for formData even though defined
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I have several OpenApi v2 files which consume both regular JSON-data and formData. Even though consumes is defined at root level via:
"consumes": [
"application/json",
"application/x-www-form-urlencoded"
]
I still get the following warning:
[main] WARN o.o.codegen.DefaultCodegen - The following schema has undefined (null) baseType. It could be due to form parameter defined in OpenAPI v2 spec with incorrect consumes. A correct 'consumes' for form parameters should be 'application/x-www-form-urlencoded' or 'multipart/?'
[main] WARN o.o.codegen.DefaultCodegen - codegenModel is null. Default to UNKNOWN_BASE_TYPE
Producing an unusable DefaultApi with calls containing UNKNOWN_BASE_TYPE as parameters where "in: formData" is defined.
openapi-generator version
openapi-generator-cli-4.2.2.jar
OpenAPI declaration file content or url
Simplified Example:https://gist.github.com/winterwurzel/f6b323eb558c3908653d25fb64cc7745#file-coupons-json
Command line used for generation
java -jar openapi-generator-cli-4.2.2.jar generate -g java -i coupons.json -o gensrc
java --version:
openjdk 11.0.4 2019-07-17 LTS
OpenJDK Runtime Environment (build 11.0.4+0-LTS-sapmachine)
OpenJDK 64-Bit Server VM (build 11.0.4+0-LTS-sapmachine, mixed mode)
Steps to reproduce
generate from provided swagger:
java -jar openapi-generator-cli-4.2.2.jar generate -g java -i coupons.json -o gensrc
Related issues/PRs
Could not find anything similar.
Suggest a fix/enhancement
None known.
As a workaround on the root level, simply swapping the consumes array order seems to fix it.
"consumes": [
"application/x-www-form-urlencoded",
"application/json"
]
Additionally, one could also define "application/x-www-form-urlencoded" in the specific paths which use formData.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Java generation command with the linked coupons.json example and compare the results when the root-level consumes entries are reordered. Trace the warning about UNKNOWN_BASE_TYPE for formData parameters. Done means the generated Java API handles the original consumes order without the warning or unusable parameter types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100