Exemple #1
0
 def test_response_description(self):
     doc = Doc()
     api = Api(title='test api', url='/test/', method='POST')
     api.response_description = 'return *user* info'
     doc.add_api(api)
     html = doc.build()
     self.assertIn('return <em>user</em> info', html)
Exemple #2
0
 def test_tips(self):
     doc = Doc()
     api = Api(title='test api', url='/test/', method='DELETE')
     api.tips = '## Be careful to destroy'
     doc.add_api(api)
     html = doc.build()
     self.assertIn('<div class="endpoint delete">', html)
     self.assertIn('<h2>Be careful to destroy</h2>', html)
Exemple #3
0
 def test_body_param(self):
     doc = Doc()
     api = Api(title='test api', url='/test/', method='POST')
     bp1 = BodyParam(name='username')
     bp2 = BodyParam()
     bp2.name = 'password'
     api.params = [bp1, bp2]
     doc.add_api(api)
     html = doc.build()
     self.assertIn('<div class="endpoint post">', html)
     self.assertIn('<td><code>username</code></td>', html)
     self.assertIn('<td><code>password</code></td>', html)
Exemple #4
0
 def test_language(self):
     doc = Doc()
     api = Api(title='test api', url='/test/', method='POST')
     api.body_example = '{}'
     doc.apis.append(api)
     html_en = doc.build()
     html_zh = doc.build(language='zh')
     self.assertIn('Contents', html_en)
     self.assertIn('Request Body Example', html_en)
     self.assertIn('Print This Document', html_en)
     self.assertIn('接口目录', html_zh)
     self.assertIn('示例请求数据', html_zh)
     self.assertIn('打印本文档', html_zh)
Exemple #5
0
    def test_body_example(self):
        doc = Doc()
        api = Api(title='test api', url='/test/', method='POST')
        api.body_example = """
{
    "username": "******",
    "password": "******"
}
"""
        doc.add_api(api)
        html = doc.build()
        self.assertIn('"username": "******"', html)
        self.assertIn('"password": "******"', html)
Exemple #6
0
 def test_query_param(self):
     doc = Doc()
     api = Api(title='test api', url='/test/', method='GET')
     qp1 = QueryParam()
     qp1.name = 'page'
     qp1.description = 'page number of list'
     qp1.default = 1
     api.params.append(qp1)
     doc.add_api(api)
     html = doc.build()
     self.assertIn('<td><code>page</code></td>', html)
     self.assertIn('<td>page number of list</td>', html)
     self.assertIn('<td>1</td>', html)
Exemple #7
0
 def test_path_param(self):
     doc = Doc()
     api = Api(title='test api', url='/test/<id>/', method='GET')
     pp1 = PathParam()
     pp1.name = 'id'
     pp1.description = 'resource id'
     pp1.example = 10
     api.params.append(pp1)
     doc.add_api(api)
     html = doc.build()
     self.assertIn('<td><code>id</code></td>', html)
     self.assertIn('<td>resource id</td>', html)
     self.assertIn('<td>10</td>', html)
Exemple #8
0
 def test_api(self):
     doc = Doc()
     api = Api()
     api.title = "first api"
     api.method = "GET"
     api.url = "/test1/<id>/"
     api.description = "this is the **first** api"
     doc.add_api(api)
     html = doc.build()
     self.assertIn('first api', html)
     self.assertIn('<div class="endpoint get">', html)
     self.assertIn('/test1/&lt;id&gt;/', html)
     self.assertNotIn('<id>', html)
     self.assertIn('<strong>first</strong>', html)
Exemple #9
0
2. 多端浏览
3. 方便维护
<br><br><br>
"""
doc.add_note(note)

note = Note(title='小结一下')
note.content = f"""
##### 编写文档对于每一个普通的开发人员来说,可能算是一种 “负担”
##### 但是在**前后端分离**大势所趋的今天
##### 能够编写一份**可读性高**、**方便传阅交流**的接口文档已成为每一位**后端开发者**的必备技能
##### 如果能有个工具来**自动**干这件事那就更棒了!
"""
doc.add_note(note)

api = Api(method='GET')
api.title = 'OpenAPI'
api.url = '/从 swagger2 /到 openapi3'
api.response_description = f"""
{img('2to3.png', 800)}
参考: https://stuff.rdme.io/swagger2to3

#### OpenAPI3 规范简要解读
```
# OpenAPI 规范版本号
openapi: 3.0.3

# API 元数据信息
info:

# 服务器连接信息