java Swagger UI把我的每个端点都放在“默认”组中,为什么它要这样做?

piwo6bdm  于 5个月前  发布在  Java
关注(0)|答案(1)|浏览(55)

Swagger UI将我的每一个端点放在“默认”组中
这里是它得到的JSON(不要问我是怎么得到的)。注意这里没有标签(我也尝试了空列表而不是Jackson没有序列化的null)

{
  "openapi": "3.0.3",
  "info": {
    "title": "Api Documentation",
    "description": "Api Documentation",
    "termsOfService": "urn:tos",
    "contact": {    },
    "license": {
      "name": "Apache 2.0",
      "url": "http://www.apache.org/licenses/LICENSE-2.0"
    },
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://localhost:8080",
      "description": "Api-Gateway-V2"
    }
  ],
  "paths": {
    "/api/v1/hello-world": {
      "get": {
        "summary": "getHelloWorld",
        "operationId": "getHelloWorldUsingGET",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessMessage",
                  "exampleSetFlag": false
                },
                "exampleSetFlag": false
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        }
      }
    },
    "/api/v1/joy": {
      "get": {
        "summary": "getMessageOfJoy",
        "operationId": "getMessageOfJoyUsingGET",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessMessage",
                  "exampleSetFlag": false
                },
                "exampleSetFlag": false
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        }
      }
    },
    "/api/v1/error": {
      "get": {
        "summary": "error",
        "operationId": "errorUsingGET",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/FailureMessage",
                  "exampleSetFlag": false
                },
                "exampleSetFlag": false
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        }
      },
      "put": {
        "summary": "error",
        "operationId": "errorUsingPUT",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/FailureMessage",
                  "exampleSetFlag": false
                },
                "exampleSetFlag": false
              }
            }
          },
          "201": {
            "description": "Created"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        }
      },
      "post": {
        "summary": "error",
        "operationId": "errorUsingPOST",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/FailureMessage",
                  "exampleSetFlag": false
                },
                "exampleSetFlag": false
              }
            }
          },
          "201": {
            "description": "Created"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        }
      },
      "delete": {
        "summary": "error",
        "operationId": "errorUsingDELETE",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/FailureMessage",
                  "exampleSetFlag": false
                },
                "exampleSetFlag": false
              }
            }
          },
          "204": {
            "description": "No Content"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      },
      "options": {
        "summary": "error",
        "operationId": "errorUsingOPTIONS",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/FailureMessage",
                  "exampleSetFlag": false
                },
                "exampleSetFlag": false
              }
            }
          },
          "204": {
            "description": "No Content"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      },
      "head": {
        "summary": "error",
        "operationId": "errorUsingHEAD",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/FailureMessage",
                  "exampleSetFlag": false
                },
                "exampleSetFlag": false
              }
            }
          },
          "204": {
            "description": "No Content"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      },
      "patch": {
        "summary": "error",
        "operationId": "errorUsingPATCH",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/FailureMessage",
                  "exampleSetFlag": false
                },
                "exampleSetFlag": false
              }
            }
          },
          "204": {
            "description": "No Content"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      },
      "trace": {
        "summary": "error",
        "operationId": "errorUsingTRACE",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/FailureMessage",
                  "exampleSetFlag": false
                },
                "exampleSetFlag": false
              }
            }
          },
          "204": {
            "description": "No Content"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "FailureMessage": {
        "title": "FailureMessage",
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "exampleSetFlag": false,
            "types": [
              "string"
            ]
          },
          "method": {
            "type": "string",
            "exampleSetFlag": false,
            "types": [
              "string"
            ],
            "enum": [
              "DELETE",
              "GET",
              "HEAD",
              "OPTIONS",
              "PATCH",
              "POST",
              "PUT",
              "TRACE"
            ]
          },
          "request_path": {
            "type": "string",
            "exampleSetFlag": false,
            "types": [
              "string"
            ]
          }
        },
        "exampleSetFlag": false,
        "types": [
          "object"
        ]
      },
      "SuccessMessage": {
        "title": "SuccessMessage",
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "exampleSetFlag": false,
            "types": [
              "string"
            ]
          }
        },
        "exampleSetFlag": false,
        "types": [
          "object"
        ]
      }
    },
    "extensions": {    }
  }
}

字符串
结果(它的UI因此截图):


的数据
我的Swagger依赖项是:

<!-- API Gateway -->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
            <version>2.0.4</version>
        </dependency>


网关:Java 17, Boot 3

<!-- microservice -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0</version>
        </dependency>


微服务:Java 17, Boot 2
我显然希望它按控制器分组,就像它通常所做的那样
斯威格为什么要这么做

to94eoyn

to94eoyn1#

这是我发现的
Swagger UI按标记对端点进行分组
如果没有添加自定义标记(使用@Tag),Swagger将自动为控制器类创建一个与类名匹配的标记(例如example-controller)。类级别的标记(包括Swagger创建的默认标记)将传播到该控制器类中声明的每个端点
如果一个控制器类或至少一个它的方法有自己的标签,Swagger将 * 不 * 为该类创建默认标签。即使你在将OpenApi对象提供给Swagger UI之前手动将自定义标签从OpenApi对象中删除,你仍然不会有默认标签。这意味着那些没有标签的端点将被分组到“默认”组中

相关问题