如何使用 Springfox 摆脱 "API must not have local definitions (i.e. only $refs are allowed)" Swaggerhub 标准化错误

How to get rid of "API must not have local definitions (i.e. only $refs are allowed)" Swaggerhub standardization error with Springfox

我有 SpringFox 生成的 swagger api-docs.json 定义。 以下最小可重现示例:

{
  "swagger": "2.0",
  "info": {
    "description": "Example REST API.",
    "version": "15.11.02",
    "title": "Example REST API",
    "contact": {
      "name": "ExampleTeam",
      "url": "https://example.com/",
      "email": "support@example.com"
    },
    "license": {
      "name": "Apache License 2.0",
      "url": "https://www.apache.org/licenses/LICENSE-2.0.txt"
    }
  },
  "host": "d01088db.ngrok.io",
  "basePath": "/cloud",
  "tags": [
    {
      "name": "All Endpoints",
      "description": " "
    }
  ],
  "paths": {
    "/api/v2/users/{userId}/jobs/{jobId}": {
      "get": {
        "tags": [
          "Builds",
          "All Endpoints"
        ],
        "summary": "Get job.",
        "operationId": "getJobUsingGET",
        "produces": [
          "*/*"
        ],
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "description": "jobId",
            "required": true,
            "type": "integer",
            "format": "int64"
          },
          {
            "name": "userId",
            "in": "path",
            "description": "userId",
            "required": true,
            "type": "integer",
            "format": "int64"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/APIPipelineJob"
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        },
        "deprecated": false
      }
    }
  },
  "definitions": {
    "APIPipelineJob": {
      "type": "object",
      "properties": {
        "archiveTime": {
          "type": "string",
          "format": "date-time",
          "example": "example"
        },
        "content": {
          "type": "string",
          "example": "example"
        },
        "createTime": {
          "type": "string",
          "format": "date-time",
          "example": "example"
        },
        "id": {
          "type": "integer",
          "format": "int64",
          "example": "example"
        },
        "name": {
          "type": "string",
          "example": "example"
        },
        "selfURI": {
          "type": "string",
          "example": "example"
        },
        "type": {
          "type": "string",
          "example": "example",
          "enum": [
            "BUILD",
            "DEPLOY"
          ]
        },
        "userId": {
          "type": "integer",
          "format": "int64",
          "example": "example"
        }
      },
      "title": "APIPipelineJob",
      "xml": {
        "name": "APIPipelineJob",
        "attribute": false,
        "wrapped": false
      }
    }
  }
}

当我将其导入 SwaggerHub 时出现标准化错误:

'definitions.*' not allowed -> API must not have local definitions (i.e. only $refs are allowed)

我找到了推荐的解决方案in SwaggerHub documentation

但我的问题是如何实现:

使用 Springfox

或者也许有另一种方法可以消除上述标准化错误?

如果您转到主页,然后将鼠标悬停在左侧的组织上并转到设置 > 标准化,您应该会看到一些选项。取消选择底部的 "API must not have local definitions (i.e. only $refs are allowed)"。

别忘了在右上角保存!