首页 > 解决方案 > OpenAPI 规范中数组和对象查询参数的 URL 示例?

问题描述

在 OpenAPI 规范中使用数组和对象查询参数时,我对 URL 的最终结果的外观感到困惑。我阅读了以下文档,但并没有让我完全理解:https ://swagger.io/docs/specification/describing-parameters/#query-parameters

基于(特别)以下查询参数的 URL 的两个示例是什么?

示例 1 - 数组

{
"/pet/findByStatus": {
    "get": {
        "parameters": [{
            "in": "query",
            "name": "test",
            "description": "Pet object that needs to be added to the store",
            "schema": {
                "type": "array",
                "items": {
                    "properties": {
                        "id": {
                            "type": "integer",
                            "format": "int64"
                        },
                        "category": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "format": "int64"
                                },
                                "name": {
                                    "type": "string"
                                }
                            }
                        },
                        "name": {
                            "type": "string",
                            "example": "doggie"
                        },
                        "photoUrls": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        },
                        "tags": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer",
                                        "format": "int64"
                                    },
                                    "name": {
                                        "type": "string"
                                    }
                                }
                            }
                        },
                        "status": {
                            "type": "string",
                            "description": "pet status in the store",
                            "enum": ["available", "pending", "sold"]
                        }
                    }
                }
            }
        }]
    }
}

示例 2 - 对象

{
"/pet/findByStatus": {
    "get": {
        "parameters": [{
            "in": "query",
            "name": "test",
            "description": "Pet object that needs to be added to the store",
            "schema": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer",
                        "format": "int64"
                    },
                    "category": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "integer",
                                "format": "int64"
                            },
                            "name": {
                                "type": "string"
                            }
                        }
                    },
                    "name": {
                        "type": "string",
                        "example": "doggie"
                    },
                    "photoUrls": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    },
                    "tags": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "format": "int64"
                                },
                                "name": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "status": {
                        "type": "string",
                        "description": "pet status in the store",
                        "enum": ["available", "pending", "sold"]
                    }
                }
            }
        }]
    }
}

谢谢!

标签: swaggeropenapi

解决方案


推荐阅读