【问题标题】:Swagger-UI Maximum call stack size exceeded -> BackreferenceSwagger-UI 超出最大调用堆栈大小-> 反向引用
【发布时间】:2017-05-02 12:11:47
【问题描述】:

从 swagger-ui 调用我的 swagger.json 时出现错误:

超过最大调用堆栈大小

我猜是因为我有

Token 的所有者类型为 User

User 的 Token 类型为 Token

当使用在线版本的 swagger 编辑器时,它可以解析类型。如何配置 swagger 以正确解析类型?

完整的swagger.json

{
    "swagger": "2.0",
    "info": {
        "description": "Descr",
        "version": "1.0.0",
        "title": "Skeleton"
    },
    "host": "1.1.1.1:11",
    "basePath": "/api",
    "tags": [{
            "name": "auth"
        }
    ],
    "schemes": ["http"],
    "paths": {
        "/auth/local": {
            "post": {
                "tags": ["auth"],
                "summary": "Authenticates User",
                "description": "This auths only local users",
                "operationId": "authenticateUser",
                "consumes": ["application/json"],
                "produces": ["application/json"],
                "parameters": [{
                        "in": "body",
                        "name": "body",
                        "required": false,
                        "schema": {
                            "$ref": "#/definitions/Credentials"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "successful operation",
                        "schema": {
                            "$ref": "#/definitions/AuthResponse"
                        }
                    }
                }
            }
        },
        "/auth/ldap": {
            "post": {
                "tags": ["auth"],
                "operationId": "authenticateLdapUser",
                "produces": ["application/json"],
                "parameters": [{
                        "in": "body",
                        "name": "body",
                        "required": false,
                        "schema": {
                            "$ref": "#/definitions/Credentials"
                        }
                    }
                ],
                "responses": {
                    "default": {
                        "description": "successful operation"
                    }
                }
            }
        }
    },
    "definitions": {
        "AuthResponse": {
            "type": "object",
            "properties": {
                "issued": {
                    "type": "string",
                    "format": "date-time"
                },
                "responseType": {
                    "type": "string",
                    "enum": ["RESPONSE", "ERROR", "UNAUTHORIZED", "OK"]
                },
                "responseDescription": {
                    "type": "string"
                },
                "accessToken": {
                    "$ref": "#/definitions/Token"
                },
                "resourceName": {
                    "type": "string"
                }
            }
        },
        "Note": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer",
                    "format": "int32"
                },
                "content": {
                    "type": "string"
                },
                "modified": {
                    "type": "string",
                    "format": "date-time"
                }
            }
        },
        "Token": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "string"
                },
                "expirationDate": {
                    "type": "string",
                    "format": "date-time"
                },
                "issued": {
                    "type": "string",
                    "format": "date-time"
                },
                "expired": {
                    "type": "boolean"
                },
                "owner": {
                    "$ref": "#/definitions/User"
                }
            }
        },
        "User": {
            "type": "object",
            "properties": {
                "username": {
                    "type": "string"
                },
                "password": {
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "displayName": {
                    "type": "string"
                },
                "notes": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Note"
                    }
                },
                "accessToken": {
                    "$ref": "#/definitions/Token"
                }
            }
        },
        "Credentials": {
            "type": "object",
            "properties": {
                "user": {
                    "type": "string"
                },
                "password": {
                    "type": "string"
                }
            }
        }
    }
}

【问题讨论】:

  • Swagger UI 和 Swagger Editor 有哪些版本?
  • 最新的,UI:v3.0.8 和在线的 Swagger 编辑器:editor.swagger.io/#
  • 这看起来像问题3012,它是“已修复,等待 swagger-js 的下一个版本。”
  • 我也有同样的问题,但使用了 Swashbuckle.AspNetCore nuget 包

标签: swagger swagger-ui


【解决方案1】:

我有同样的问题,我删除了 format: date-time 并且错误消失了。 我仍然不知道是什么导致了错误。但如果没有这种格式,一切都会好起来的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 2015-12-29
    • 2017-12-27
    • 2020-12-06
    • 2017-02-04
    • 2018-02-06
    相关资源
    最近更新 更多