Springboot openapi 在 swagger 文档中生成重复的 api

问题描述 投票:0回答:1

爪哇:21

Springboot:3.2.1

OpenApi 依赖:

<dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
      <version>2.1.0</version>
    </dependency>

打开 api yaml 文件

openapi: 3.0.3
info:
  title: Example apis
  description: |-
    A simple collection of example APIs
  version: 1.0-SNAPSHOT
servers:
  - url: http://127.0.1:8091/api/v1
    description: Local server (uses test data)
  - url: https://example-dev.com/api/v1
    description: UAT server (uses test data)
  - url: https://example.com/api/v1
    description: Production server (uses live data)
tags:
  - name: example
    description: example apis
paths:
  /examples:
    get:
      summary: Get examples
      description: Get examples
      operationId: getExample
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Example'
        404:
          description: Leaderboard not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExampleNotFoundError'
  
components:
  schemas:
    Example:
      type: object
      properties:
        creatorId:
          type: string
        hipiCoins:
          type: number
    ExampleNotFoundError:
      type: object
      properties:
        creatorId:
          type: string
        hipiCoins:
          type: number
    

在swagger中,有两个api

一个是

GET /api/v1/examples
,另一个是
GET /examples

仅预期

GET /api/v1/examples

Stacker Flow中类似的问题很少,我在过去8小时内一一尝试,都没有解决问题。

spring-boot swagger openapi openapi-generator openapi-generator-maven-plugin
1个回答
0
投票

您可以将您的路径声明为:

paths:
  /api/v1/examples:
    get:
© www.soinside.com 2019 - 2024. All rights reserved.