OpenAPITools / OpenAPITools/openapi-generator

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

未关闭
#8,167 3 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Issue: Bug
主要语言
Java
星标
26.8k
派生
7.7k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Maven plugin 使用的 Spring generator 入口点开始,跟踪 implicitHeaders 选项如何转换 OpenAPI 标头名称 X-Whatever-Code。使用提供的 OpenAPI 3.0.2 规范和 Spring 配置复现该问题,然后验证生成的 @ApiImplicitParam 元数据是否保留预期的标头名称;如果找到相关的生成器测试,则添加或更新该测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
java, spring
领域
api, backend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。