Swagger Codegen basePath 被忽略

Swagger Codegen basePath is being ignored

我正在尝试使用 Swagger Codegen » 2.2.1

生成一些 Web 服务定义

所有配置都在工作,类 由我的 .yaml 定义正确生成。

Why the property basePath is being ignored?


我的 @RestController 仅使用 paths 定义生成:

https://springboot-base-save-return.appdes.xnet/saveBackendReturn

预期(使用 basePathpaths 定义):

https://springboot-base-save-return.appdes.xnet/v1/saveBackendReturn

我做错了什么?我是不是忘记了什么?


我的.yaml合同:

swagger: '2.0'
info:
  description: My Project
  version: 1.0.0
  title: Save Backend Return
host: springboot-base-save-return.appdes.xnet
basePath: /v1
tags:
  - name: saveBackendReturn
    description: Save Backend Return
schemes:
  - https
paths:
  /saveBackendReturn:
    post:
      tags:
        - saveBackendReturn
      summary: Save Backend Return
      description: My Project
      operationId: saveBackendReturn
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: body
          name: body
          description: My Project
          required: true
          schema:
            $ref: '#/definitions/saveBackendReturnRequest'
      responses:
        '200':
          description: Ok
          schema:
            $ref: '#/definitions/saveBackendReturnResponse'
        '400':
          description: Bad Request
        '401':
          description: Unauthorized
        '500':
          description: Internal Server Error
          schema:
            $ref: '#/definitions/Error'
      security:
        - basicAuth: []

搜索更多相关信息,我找到了 issue

这是由 HugoMario (commit 于 2019 年 12 月 2 日引用)

修复的错误

并根据 Helen 建议,我更新了我的 Swagger Codegen:

  • 来自 » 2.2.1 » 旧版本(2016 年 8 月 7 日

  • 至 » 2.4.12 » 当前稳定版本2020 年 1 月 15 日

Summary: » It's a bug of an outdated version » Now works fine!


swagger-codegen-maven-plugin 的 Maven 依赖项:

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.4.12</version>
</dependency>

Maven 中央存储库检查新版本):


更新 Maven 项目Eclipse 快捷方式 F5)并制作一个清理构建:

mvn clean verify 
mvn install

参考: