OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java][Spring] implicitHeaders replace the - in header name by a camelCased name

Open
#8,167 3 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

Using the maven plugin configuration with implicitHeaders and with this API specification :

openapi: 3.0.2
info:
  title: Whatever
  version: 1.0.0
paths:
  /Whatever:
    summary: Get Whatever
    parameters:
      - name: 'X-Whatever-Code'
        in: header
        required: true
        description: Whatever
        allowEmptyValue: false
        schema:
          type: string
    get:
      responses:
        '200':
          description: Whatever
          content:
            application/json:
              schema:
                type: string

The name of the implicit param is defined to xWhateverCode instead of X-Whatever-Code

  @ApiImplicitParams({
    @ApiImplicitParam(name = "xWhateverCode", value = "Whatever", required=true, dataType = "String", paramType = "header"),
    })
openapi-generator version

4.3.1

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  title: Whatever
  version: 1.0.0
paths:
  /Whatever:
    summary: Get Whatever
    parameters:
      - name: 'X-Whatever-Code'
        in: header
        required: true
        description: Whatever
        allowEmptyValue: false
        schema:
          type: string
    get:
      responses:
        '200':
          description: Whatever
          content:
            application/json:
              schema:
                type: string
Generation Details
<plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>4.3.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <output>${openapi.generation.directory}</output>
                            <inputSpec>src/main/resources/openapi.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <apiPackage>com.whatever.api.controller</apiPackage>
                            <modelPackage>com.whatever.api.model</modelPackage>
                            <generateSupportingFiles>false</generateSupportingFiles>
                            <configOptions>
                                <sourceFolder>.</sourceFolder>
                                <groupId>whatever</groupId>
                                <invokerPackage>com.whatever.api</invokerPackage>
                                <dateLibrary>java8</dateLibrary>
                                <artifactId>whatever-api</artifactId>
                                <artifactVersion>1.0.0</artifactVersion>
                                <configPackage>com.whatever.configuration</configPackage>
                                <basePackage>com.whatever</basePackage>
                                <reactive>true</reactive>
                                <interfaceOnly>true</interfaceOnly>
                                <skipDefaultInterface>true</skipDefaultInterface>
                                <implicitHeaders>true</implicitHeaders>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

Simply generate the source code with the configurations above

Related issues/PRs

Seems to be a similar problem with Kotlin generation : https://github.com/OpenAPITools/openapi-generator/issues/7322

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 Spring generator entry point used by the Maven plugin and trace how the implicitHeaders option converts the OpenAPI header name X-Whatever-Code. Reproduce the issue with the provided OpenAPI 3.0.2 specification and Spring configuration, then verify that generated @ApiImplicitParam metadata preserves the expected header name and add or update the relevant generator test if one is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.