feat: faker api: swagger

This commit is contained in:
Zhaolong
2022-02-07 22:16:52 +08:00
parent 5f56feffb2
commit 608dcae3ce
4 changed files with 214 additions and 11 deletions

View File

@@ -32,6 +32,8 @@ flask-sqlalchemy = "*"
pymysql = "*" pymysql = "*"
cryptography = "*" cryptography = "*"
deprecated = "*" deprecated = "*"
setuptools = "*"
flasgger = "*"
[dev-packages] [dev-packages]

115
Pipfile.lock generated
View File

@@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "23773f4bbfa489415484a32b77751e98de78d5a91ad30ac56bea7f0fe86c2ef5" "sha256": "9a94dd40b7d382b78f84e7ff24136ec2537b55efb11c31eeee80ab83a4bc8629"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@@ -16,6 +16,14 @@
] ]
}, },
"default": { "default": {
"attrs": {
"hashes": [
"sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4",
"sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==21.4.0"
},
"certifi": { "certifi": {
"hashes": [ "hashes": [
"sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872", "sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872",
@@ -161,6 +169,14 @@
"index": "pypi", "index": "pypi",
"version": "==3.4.2" "version": "==3.4.2"
}, },
"flasgger": {
"hashes": [
"sha256:0603941cf4003626b4ee551ca87331f1d17b8eecce500ccf1a1f1d3a332fc94a",
"sha256:6ebea406b5beecd77e8da42550f380d4d05a6107bc90b69ce9e77aee7612e2d0"
],
"index": "pypi",
"version": "==0.9.5"
},
"flask": { "flask": {
"hashes": [ "hashes": [
"sha256:7b2fb8e934ddd50731893bdcdb00fc8c0315916f9fcd50d22c7cc1a95ab634e2", "sha256:7b2fb8e934ddd50731893bdcdb00fc8c0315916f9fcd50d22c7cc1a95ab634e2",
@@ -262,6 +278,14 @@
"index": "pypi", "index": "pypi",
"version": "==3.0.3" "version": "==3.0.3"
}, },
"jsonschema": {
"hashes": [
"sha256:636694eb41b3535ed608fe04129f26542b59ed99808b4f688aa32dcf55317a83",
"sha256:77281a1f71684953ee8b3d488371b162419767973789272434bbc3f29d9c8823"
],
"markers": "python_version >= '3.7'",
"version": "==4.4.0"
},
"lxml": { "lxml": {
"hashes": [ "hashes": [
"sha256:0607ff0988ad7e173e5ddf7bf55ee65534bd18a5461183c33e8e41a59e89edf4", "sha256:0607ff0988ad7e173e5ddf7bf55ee65534bd18a5461183c33e8e41a59e89edf4",
@@ -403,13 +427,20 @@
"index": "pypi", "index": "pypi",
"version": "==2.0.1" "version": "==2.0.1"
}, },
"mistune": {
"hashes": [
"sha256:6bab6c6abd711c4604206c7d8cad5cd48b28f072b4bb75797d74146ba393a049",
"sha256:6fc88c3cb49dba8b16687b41725e661cf85784c12e8974a29b9d336dd596c3a1"
],
"version": "==2.0.2"
},
"pip": { "pip": {
"hashes": [ "hashes": [
"sha256:deaf32dcd9ab821e359cd8330786bcd077604b5c5730c0b096eda46f95c24a2d", "sha256:c146f331f0805c77017c6bb9740cec4a49a0d4582d0c3cc8244b057f83eca359",
"sha256:fd11ba3d0fdb4c07fbc5ecbba0b1b719809420f25038f8ee3cd913d3faa3033a" "sha256:f29d589df8c8ab99c060e68ad294c4a9ed896624f6368c5349d70aa581b333d0"
], ],
"markers": "python_version >= '3.6'", "markers": "python_version >= '3.7'",
"version": "==21.3.1" "version": "==22.0.3"
}, },
"pipenv": { "pipenv": {
"hashes": [ "hashes": [
@@ -442,6 +473,33 @@
"index": "pypi", "index": "pypi",
"version": "==1.0.2" "version": "==1.0.2"
}, },
"pyrsistent": {
"hashes": [
"sha256:0e3e1fcc45199df76053026a51cc59ab2ea3fc7c094c6627e93b7b44cdae2c8c",
"sha256:1b34eedd6812bf4d33814fca1b66005805d3640ce53140ab8bbb1e2651b0d9bc",
"sha256:4ed6784ceac462a7d6fcb7e9b663e93b9a6fb373b7f43594f9ff68875788e01e",
"sha256:5d45866ececf4a5fff8742c25722da6d4c9e180daa7b405dc0a2a2790d668c26",
"sha256:636ce2dc235046ccd3d8c56a7ad54e99d5c1cd0ef07d9ae847306c91d11b5fec",
"sha256:6455fc599df93d1f60e1c5c4fe471499f08d190d57eca040c0ea182301321286",
"sha256:6bc66318fb7ee012071b2792024564973ecc80e9522842eb4e17743604b5e045",
"sha256:7bfe2388663fd18bd8ce7db2c91c7400bf3e1a9e8bd7d63bf7e77d39051b85ec",
"sha256:7ec335fc998faa4febe75cc5268a9eac0478b3f681602c1f27befaf2a1abe1d8",
"sha256:914474c9f1d93080338ace89cb2acee74f4f666fb0424896fcfb8d86058bf17c",
"sha256:b568f35ad53a7b07ed9b1b2bae09eb15cdd671a5ba5d2c66caee40dbf91c68ca",
"sha256:cdfd2c361b8a8e5d9499b9082b501c452ade8bbf42aef97ea04854f4a3f43b22",
"sha256:d1b96547410f76078eaf66d282ddca2e4baae8964364abb4f4dcdde855cd123a",
"sha256:d4d61f8b993a7255ba714df3aca52700f8125289f84f704cf80916517c46eb96",
"sha256:d7a096646eab884bf8bed965bad63ea327e0d0c38989fc83c5ea7b8a87037bfc",
"sha256:df46c854f490f81210870e509818b729db4488e1f30f2a1ce1698b2295a878d1",
"sha256:e24a828f57e0c337c8d8bb9f6b12f09dfdf0273da25fda9e314f0b684b415a07",
"sha256:e4f3149fd5eb9b285d6bfb54d2e5173f6a116fe19172686797c056672689daf6",
"sha256:e92a52c166426efbe0d1ec1332ee9119b6d32fc1f0bbfd55d5c1088070e7fc1b",
"sha256:f87cc2863ef33c709e237d4b5f4502a62a00fab450c9e020892e8e2ede5847f5",
"sha256:fd8da6d0124efa2f67d86fa70c851022f87c98e205f0594e1fae044e7119a5a6"
],
"markers": "python_version >= '3.7'",
"version": "==0.18.1"
},
"python-dateutil": { "python-dateutil": {
"hashes": [ "hashes": [
"sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86", "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86",
@@ -450,6 +508,45 @@
"index": "pypi", "index": "pypi",
"version": "==2.8.2" "version": "==2.8.2"
}, },
"pyyaml": {
"hashes": [
"sha256:0283c35a6a9fbf047493e3a0ce8d79ef5030852c51e9d911a27badfde0605293",
"sha256:055d937d65826939cb044fc8c9b08889e8c743fdc6a32b33e2390f66013e449b",
"sha256:07751360502caac1c067a8132d150cf3d61339af5691fe9e87803040dbc5db57",
"sha256:0b4624f379dab24d3725ffde76559cff63d9ec94e1736b556dacdfebe5ab6d4b",
"sha256:0ce82d761c532fe4ec3f87fc45688bdd3a4c1dc5e0b4a19814b9009a29baefd4",
"sha256:1e4747bc279b4f613a09eb64bba2ba602d8a6664c6ce6396a4d0cd413a50ce07",
"sha256:213c60cd50106436cc818accf5baa1aba61c0189ff610f64f4a3e8c6726218ba",
"sha256:231710d57adfd809ef5d34183b8ed1eeae3f76459c18fb4a0b373ad56bedcdd9",
"sha256:277a0ef2981ca40581a47093e9e2d13b3f1fbbeffae064c1d21bfceba2030287",
"sha256:2cd5df3de48857ed0544b34e2d40e9fac445930039f3cfe4bcc592a1f836d513",
"sha256:40527857252b61eacd1d9af500c3337ba8deb8fc298940291486c465c8b46ec0",
"sha256:473f9edb243cb1935ab5a084eb238d842fb8f404ed2193a915d1784b5a6b5fc0",
"sha256:48c346915c114f5fdb3ead70312bd042a953a8ce5c7106d5bfb1a5254e47da92",
"sha256:50602afada6d6cbfad699b0c7bb50d5ccffa7e46a3d738092afddc1f9758427f",
"sha256:68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2",
"sha256:77f396e6ef4c73fdc33a9157446466f1cff553d979bd00ecb64385760c6babdc",
"sha256:819b3830a1543db06c4d4b865e70ded25be52a2e0631ccd2f6a47a2822f2fd7c",
"sha256:897b80890765f037df3403d22bab41627ca8811ae55e9a722fd0392850ec4d86",
"sha256:98c4d36e99714e55cfbaaee6dd5badbc9a1ec339ebfc3b1f52e293aee6bb71a4",
"sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c",
"sha256:9fa600030013c4de8165339db93d182b9431076eb98eb40ee068700c9c813e34",
"sha256:a80a78046a72361de73f8f395f1f1e49f956c6be882eed58505a15f3e430962b",
"sha256:b3d267842bf12586ba6c734f89d1f5b871df0273157918b0ccefa29deb05c21c",
"sha256:b5b9eccad747aabaaffbc6064800670f0c297e52c12754eb1d976c57e4f74dcb",
"sha256:c5687b8d43cf58545ade1fe3e055f70eac7a5a1a0bf42824308d868289a95737",
"sha256:cba8c411ef271aa037d7357a2bc8f9ee8b58b9965831d9e51baf703280dc73d3",
"sha256:d15a181d1ecd0d4270dc32edb46f7cb7733c7c508857278d3d378d14d606db2d",
"sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53",
"sha256:d4eccecf9adf6fbcc6861a38015c2a64f38b9d94838ac1810a9023a0609e1b78",
"sha256:d67d839ede4ed1b28a4e8909735fc992a923cdb84e618544973d7dfc71540803",
"sha256:daf496c58a8c52083df09b80c860005194014c3698698d1a57cbcfa182142a3a",
"sha256:e61ceaab6f49fb8bdfaa0f92c4b57bcfbea54c09277b1b4f7ac376bfb7a7c174",
"sha256:f84fbc98b019fef2ee9a1cb3ce93e3187a6df0b2538a651bfb890254ba9f90b5"
],
"markers": "python_version >= '3.6'",
"version": "==6.0"
},
"requests": { "requests": {
"hashes": [ "hashes": [
"sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61", "sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61",
@@ -460,11 +557,11 @@
}, },
"setuptools": { "setuptools": {
"hashes": [ "hashes": [
"sha256:2404879cda71495fc4d5cbc445ed52fdaddf352b36e40be8dcc63147cb4edabe", "sha256:07e97e2f1e5607d240454e98c75c7004560ac8417ca5ae1dbaa50811cb6cc95c",
"sha256:68eb94073fc486091447fcb0501efd6560a0e5a1839ba249e5ff3c4c93f05f90" "sha256:23aad87cc27f4ae704079618c1d117a71bd43d41e355f0698c35f6b1c796d26c"
], ],
"markers": "python_version >= '3.7'", "index": "pypi",
"version": "==60.5.0" "version": "==60.8.1"
}, },
"six": { "six": {
"hashes": [ "hashes": [

100
app.py
View File

@@ -3,11 +3,12 @@ import config
import utils.response as response import utils.response as response
import service.faker_data as faker import service.faker_data as faker
from base import db from base import db
from model import SexEnum from flasgger import Swagger, swag_from
app = Flask(__name__) app = Flask(__name__)
config.init_config(app) config.init_config(app)
db.init_app(app) db.init_app(app)
swagger = Swagger(app)
@app.route('/') @app.route('/')
@@ -17,43 +18,138 @@ def hello_world():
@app.route("/faker/railway/<number>") @app.route("/faker/railway/<number>")
def faker_railway(number): def faker_railway(number):
"""Faker Railway Datas
---
parameters:
- name: number
in: path
type: number
required: true
description: the number of to be generated
responses:
200:
description: A list of railway
"""
return response.succ(faker.faker_railways(int(number))) return response.succ(faker.faker_railways(int(number)))
@app.route("/faker/hotel/<number>") @app.route("/faker/hotel/<number>")
def faker_hotel(number): def faker_hotel(number):
"""Faker Hotel Datas
---
parameters:
- name: number
in: path
type: number
required: true
description: the number of to be generated
responses:
200:
description: A list of hotel
"""
return response.succ(faker.faker_hotels(int(number))) return response.succ(faker.faker_hotels(int(number)))
@app.route("/faker/contacts/<num_hotel>/<num_railway>") @app.route("/faker/contacts/<num_hotel>/<num_railway>")
def faker_contacts(num_hotel, num_railway): def faker_contacts(num_hotel, num_railway):
"""Faker Contacts Datas
---
parameters:
- name: num_hotel
in: path
type: number
required: true
description: the number of hotel to be generated
- name: num_railway
in: path
type: number
required: true
description: the number of railway to be generated
responses:
200:
description: the contacts and patient
"""
return response.succ(faker.faker_contacts(int(num_hotel), int(num_railway))) return response.succ(faker.faker_contacts(int(num_hotel), int(num_railway)))
@app.route("/query/patient") @app.route("/query/patient")
def query_patient(): def query_patient():
"""Query Patients
---
responses:
200:
description: A list of patients
"""
return response.succ(faker.query_patients()) return response.succ(faker.query_patients())
@app.route("/query/contacts/hotel/<identification>") @app.route("/query/contacts/hotel/<identification>")
def query_contacts_hotel(identification): def query_contacts_hotel(identification):
"""Query Hotel Contacts by Patient's Identification
---
parameters:
- name: identification
in: path
type: number
required: true
description: the identification of patient
responses:
200:
description: A list of contacts
"""
return response.succ(faker.query_contacts_hotel(identification)) return response.succ(faker.query_contacts_hotel(identification))
@app.route("/query/contacts/railway/<identification>") @app.route("/query/contacts/railway/<identification>")
def query_contacts_railway(identification): def query_contacts_railway(identification):
"""Query Railway Contacts by Patient's Identification
---
parameters:
- name: identification
in: path
type: number
required: true
description: the identification of patient
responses:
200:
description: A list of contacts
"""
return response.succ(faker.query_contacts_railway(identification)) return response.succ(faker.query_contacts_railway(identification))
@app.route("/query/contacts/classify/<identification>") @app.route("/query/contacts/classify/<identification>")
def query_contacts_classify(identification): def query_contacts_classify(identification):
"""Query Classified Hotel and Railway Contacts by Patient's Identification
---
parameters:
- name: identification
in: path
type: number
required: true
description: the identification of patient
responses:
200:
description: A list of contacts
"""
return response.succ(faker.query_contacts_classify(identification)) return response.succ(faker.query_contacts_classify(identification))
@app.route("/query/contacts/<identification>") @app.route("/query/contacts/<identification>")
def query_contacts(identification): def query_contacts(identification):
"""Query All Contacts by Patient's Identification
---
parameters:
- name: identification
in: path
type: number
required: true
description: the identification of patient
responses:
200:
description: A list of contacts
"""
return response.succ(faker.query_contacts(identification)) return response.succ(faker.query_contacts(identification))
if __name__ == '__main__': if __name__ == '__main__':
app.run() app.run(debug=True)

View File

@@ -10,8 +10,16 @@ SQLALCHEMY_DATABASE_URI = f'{DIALECT}+{DRIVER}://{USERNAME}:{PASSWORD}@{HOST}:{P
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ECHO = True SQLALCHEMY_ECHO = True
SWAGGER_CONFIG = {
"title": "nCovTrack-Faker",
"description": "API for nCovTrack-Faker",
'uiversion': 3,
"version": "0.0.1"
}
def init_config(app): def init_config(app):
app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI app.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SQLALCHEMY_ECHO"] = True app.config["SQLALCHEMY_ECHO"] = True
app.config["SWAGGER"] = SWAGGER_CONFIG