首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用source2swagger的静态API文档

使用source2swagger的静态API文档
EN

Stack Overflow用户
提问于 2013-03-01 02:36:11
回答 1查看 1.1K关注 0票数 0

source2swagger在一个json文件中生成一个包含所有apis的swagger spec。swagger-ui真的可以使用它吗?当我使用swagger-ui浏览生成的json文件时,它尝试从规范中的路径读取api描述,而不是使用单个json文件中的描述/操作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-01 23:40:11

Swagger-UI将处理将所有json放入一个文件中。不过,我还不确定是否可以有多个顶级资源列表。

下面是一个有效的示例:

代码语言:javascript
复制
{"basePath":"http://localhost:3001/", "resourcePath":"/", "swaggerVersion":"1.1", "apiVersion":"1.0", "apis":[
    {
        "path":"/pay",
        "format":"json",
        "description":"Create a transaction with the given amount and token.",
        "operations":[
            {
                "httpMethod":"GET",
                "tags":["production"],
                "nickname":"pay",
                "deprecated":false,
                "summary":"Create a transaction with the given amount and token.",
                "parameters":[
                    {
                        "name":"token",
                        "description":"The token representing the pay card",
                        "dataType":"string",
                        "allowMultiple":false,
                        "required":true,
                        "paramType":"query"
                    },
                    {
                        "name":"amount",
                        "description":"The amount to pay",
                        "dataType":"string",
                        "allowMultiple":false,
                        "required":true,
                        "paramType":"query"
                    }
                ]
            }
        ]
    },
    {
        "path":"/customer",
        "format":"json",
        "description":"Create an HTML form for adding a customer.",
        "operations":[
            {
                "httpMethod":"GET",
                "tags":["production"],
                "nickname":"createCustomerForm",
                "deprecated":false,
                "summary":"Create an HTML form for adding a customer.",
                "parameters":[
                    {
                        "name":"customerId",
                        "description":"Your customer id",
                        "dataType":"string",
                        "allowMultiple":false,
                        "required":true,
                        "paramType":"query"
                    }
                ]
            }
        ]
    },
    {
        "path":"/customer/{customerId}",
        "format":"json",
        "description":"Delete the customer info for given id.",
        "operations":[
            {
                "httpMethod":"DELETE",
                "tags":["production"],
                "nickname":"deleteCustomer",
                "deprecated":false,
                "summary":"Delete the customer info for given id.",
                "parameters":[
                    {
                        "name":"customerId",
                        "description":"the customer id to delete",
                        "dataType":"string",
                        "allowMultiple":false,
                        "required":true,
                        "paramType":"path"
                    }
                ]
            }
        ]
    },
    {
        "path":"/card",
        "format":"json",
        "description":"Create an HTML form for adding a credit card.",
        "operations":[
            {
                "httpMethod":"GET",
                "tags":["production"],
                "nickname":"createCardForm",
                "deprecated":false,
                "summary":"Create an HTML form for the given customer to add a credit card.",
                "parameters":[
                    {
                        "name":"customerId",
                        "description":"Your customer id",
                        "dataType":"string",
                        "allowMultiple":false,
                        "required":true,
                        "paramType":"query"
                    }
                ]
            }
        ]
    },
    {
        "path":"/card/{token}",
        "format":"json",
        "description":"Delete a card record by token.",
        "operations":[
            {
                "httpMethod":"DELETE",
                "tags":["production"],
                "nickname":"deleteCard",
                "deprecated":false,
                "summary":"Delete the card info for given token.",
                "parameters":[
                    {
                        "name":"token",
                        "description":"the token to delete",
                        "dataType":"string",
                        "allowMultiple":false,
                        "required":true,
                        "paramType":"path"
                    }
                ]
            }
        ]
    }
]}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15143068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档