OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.58k stars 6.52k forks source link

[BUG][JAVA] incorrect consumes for formData even though defined #4845

Open winterwurzel opened 4 years ago

winterwurzel commented 4 years ago
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.

auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

rseidlnc commented 4 years ago

are there any updates on this issue? thanks!