sample.py
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# coding=utf-8
#author: 4N
#createtime: 2020/8/27
#email: nheweijun@sina.com
from flask import current_app
import os
from app.util.component.ApiTemplate import ApiTemplate
from app.util.component.ModelVisitor import ModelVisitor
from app.util.component.StructuredPrint import StructurePrint
from app.models import Service,db
from sqlalchemy.orm import load_only
from flask import current_app
class Api(ApiTemplate):
def para_check(self):
if self.para.get("content") is None:
raise Exception("缺乏content参数")
def log(self):
current_app.logger.info('info log')
def process(self):
result=dict()
result.update(self.para)
services = Service.query.options(load_only('guid')).all()
result["root_path"] = os.path.dirname(current_app.instance_path)
result["services"] = ModelVisitor.objects_to_jsonarray(services)
return result
api_doc= {
"tags": ["测试接口"],
"description": "测试接口",
"parameters": [
{"name": "content",
"in": "query"}
],
"responses": {
200: {
"schema": {
"properties": {
"content": {
"type": "string",
"description": "The name of the user"
}
}
}
}
}
}