4

我们使用 Swagger 2.0 作为我们的文档。我们正在以编程方式直接从我们的数据设计文档中创建 swagger 2.0 规范。

我们的模型非常复杂且嵌套。我想了解我们是否可以定义内联定义的嵌套数组对象。

例如:

{
    "definitions": {
        "user": {
            "type": "object",
            "required": ["name"],
            "properties": {
                "name": {
                    "type": "string"
                },
                "address": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "type": {
                                "type": "string",
                                "enum": ["home",
                                "office"]
                            },
                            "line1": {
                                "type": "string"
                            }
                        },
                        "Person": {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
} 

我们有很多在模型中遇到这种情况的情况,此时定义#ref 不是我们想要考虑的选项。我们需要这个来内联处理。

根据以下帖子:httpsenter code here ://github.com/swagger-api/swagger-editor/issues/603#even t-391465196 看起来它不支持处理内联定义的嵌套数组对象。

由于许多大企业的数据模型非常复杂,我们希望在 swagger 2.0 规范中支持此功能。

有没有想过要添加这个功能。

4

1 回答 1

3

您的文档只是无效的,这与嵌套数组无关:该属性Person在 Swagger 2.0 架构中是不允许的items

模式中唯一允许的属性是:$ref, format, title, description, default, multipleOf, maximum, exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, pattern, maxItems, minItems, uniqueItems, maxProperties, minProperties, required, enum, additionalProperties, type, items, allOf, properties, discriminator, readOnly, xml, externalDocs, example.

于 2015-09-29T12:46:56.363 回答