OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] OpenAPI 3.x query parameters described with content vs schema don't generate - result is unknown parameter in generated code

Open
#2,687 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

In OpenAPI 3.0+ you can describe query parameters with a content: vs schema:
There's 2 issues

  1. The swagger core parser doesn't properly resolve query paramters specified with the content tag
  2. The openapi-generator doesn't have logic to generate the code even if the core parser did resolve the parameters
openapi-generator version

master

OpenAPI declaration file content or url

You can see the yample yaml in the issue I raised with swagger-parser
https://github.com/swagger-api/swagger-parser/issues/1078

Command line used for generation

Take yaml from https://github.com/swagger-api/swagger-parser/issues/1078

Command lline args: generate -g jaxrs-resteasy-eap -i example.yaml -o outputdir

Steps to reproduce

See Yaml from https://github.com/swagger-api/swagger-parser/issues/1078, and attempt to generate client/server code for it.

Related issues/PRs

https://github.com/swagger-api/swagger-parser/issues/1078

Suggest a fix

In org.openapitools.codegen.DefaultCodegen.fromParameter()
We need to do more than check for getSchema()!=null.

If it's null but there's a content specified (i.e. getContent()!=null, we need to pull the scema from the MediaType from the specified content.

Similar to how response bodies are generated with content specified.

But it still requires https://github.com/swagger-api/swagger-parser/pull/1079 in order for the schema objects to be resolved under the specified content/media-type section.
Without that fix, there will be no schema objects in the openAPI context to be able to generate the proper code.

I'm testing a full patch with added unit tests.
I'll submit a PR when I'm done.

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 in org.openapitools.codegen.DefaultCodegen.fromParameter() and compare parameter handling with response bodies that use content. Reproduce with the YAML from swagger-parser issue 1078 and the jaxrs-resteasy-eap command; consult parser PR 1079 for schema resolution. Done means generated code treats content-based query parameters as real parameters rather than unknown parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.