Swagger文档的比较
博客专区 > Zuo_W 的博客 > 博客详情
Swagger文档的比较
Zuo_W 发表于6个月前
Swagger文档的比较
  • 发表于 6个月前
  • 阅读 35
  • 收藏 0
  • 点赞 0
  • 评论 0

新睿云服务器60天免费使用,快来体验!>>>   

GitHub源码地址 Swagger-diff:https://github.com/Sayi/swagger-diff

swagger-diff

自动生成API ChangeLog组件
用来比较两个由Swagger生成的API文档,对参数、返回类型、路径进行深度比较,并输出差异,适用于自动生成接口变更文档。

前提

jdk1.6+

特性

  • Support swagger1.x and swagger2.0
  • Support HTTP请求方法比较: get post put delete...
  • Support Requestbody参数比较
  • Support API文档的鉴权Auth读取
  • EL(Expression Language)表达式
  • HTML 渲染、markdown 渲染

Maven

<dependency>
        <groupId>com.deepoove</groupId>
        <artifactId>swagger-diff</artifactId>
	<version>1.1.0</version>
</dependency>

快速入门

SwaggerDiff可以从JSON文件或者HTTP URL中读取API-DOC。

final String SWAGGER_V2_DOC1 = "petstore_v2_1.json";
final String SWAGGER_V2_DOC2 = "http://petstore.swagger.io/v2/swagger.json";

SwaggerDiff diff = SwaggerDiff.compareV2(SWAGGER_V2_DOC1, SWAGGER_V2_DOC2);

Swagger版本

v1.x版本

SwaggerDiff.compareV1(SWAGGER_V1_DOC1, SWAGGER_V1_DOC2);

v2.0版本

SwaggerDiff.compareV2(SWAGGER_V2_DOC1, SWAGGER_V2_DOC2);

渲染

HTML

String html = new HtmlRender("Changelog",
        "http://deepoove.com/swagger-diff/stylesheets/demo.css")
                .render(diff);

try {
    FileWriter fw = new FileWriter(
            "testNewApi.html");
    fw.write(html);
    fw.close();

} catch (IOException e) {
    e.printStackTrace();
}

输入图片说明

Markdown

String render = new MarkdownRender().render(diff);
try {
    FileWriter fw = new FileWriter(
            "testDiff.md");
    fw.write(render);
    fw.close();
    
} catch (IOException e) {
    e.printStackTrace();
}
### What's New
---
* `GET` /pet/{petId} Find pet by ID

### What's Deprecated
---
* `POST` /pet/{petId} Updates a pet in the store with form data

### What's Changed
---
* `PUT` /pet Update an existing pet  
    Parameter

        Add body.newFeild //a feild demo by sayi
        Add body.category.newCatFeild
        Delete body.category.name
* `POST` /pet Add a new pet to the store  
    Parameter

        Add tags //add new query param demo
        Add body.newFeild //a feild demo by sayi
        Add body.category.newCatFeild
        Delete body.category.name
* `DELETE` /pet/{petId} Deletes a pet  
    Parameter

        Add newHeaderParam
* `POST` /pet/{petId}/uploadImage uploads an image for pet  
    Parameter

        petId change into not required Notes ID of pet to update change into ID of pet to update, default false
* `POST` /user Create user  
    Parameter

        Add body.newUserFeild //a new user feild demo
        Delete body.phone
* `GET` /user/login Logs user into the system  
    Parameter

        Delete password //The password for login in clear text
* `GET` /user/{username} Get user by user name  
    Return Type

        Add newUserFeild //a new user feild demo
        Delete phone
* `PUT` /user/{username} Updated user  
    Parameter

        Add body.newUserFeild //a new user feild demo
        Delete body.phone

标签: swagger diff 比较
  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 7
博文 15
码字总数 11457
×
Zuo_W
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: