OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Spring] [Spring-Boot] Exploded query parameters are not correctly serialized in controller

Open
#14,860 10 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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating code with an exploded query parameter, the spring generator with the spring-boot library does not correctly resolve the supplied parameters. Some experimentation suggests that the serialization is using the name of the field in the Java object, not the name of the field in the OpenAPI specification.

openapi-generator version

6.4.0

OpenAPI declaration file content or url

https://github.com/GregDThomas/openapi-generator-spring-boot-example/blob/main/specs/explode-query-parameter.yaml

Generation Details

Using the OpenAPI Generator Gradle Plugin with

    generatorName = "spring"
    library = 'spring-boot'
Steps to reproduce

See the sample project at https://github.com/GregDThomas/openapi-generator-spring-boot-example and more specifically the tests in ExampleControllerTest

Specifically -

  • the fields in the exploded object that match the name of the field in the POJO (someCamelString) are correctly serialized.
  • the fields in the exploded object that do no match the name of the field in the POJO are not correctly serialized.
    -- some-kebab-string / someKebabString
    -- some_snake_string / someSnakeString
Related issues/PRs
Suggest a fix

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 sample project's specs/explode-query-parameter.yaml and ExampleControllerTest, then reproduce generation with the spring generator and spring-boot library. Trace the generated controller and parameter handling for fields whose OpenAPI names use kebab-case or snake_case. Done means exploded query fields serialize using their specification names as well as matching Java field names.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.