[使用 Python、Flask、flask_restplus、Swagger]
我正在尝试schema model
使用flask_restplus
. yml 而非 python 中的原型模式:
我创建了,schema_model
但我不确定如何将它输入到代码中,以便它与 GET 调用配对。如何显示 schema_model?
import requests
from flask import Flask, request, json, jsonify, Blueprint
from flask_restplus import Resource, Api, reqparse, fields, SchemaModel
app = Flask(__name__)
api = Api(app, title='Function Test', doc='/FT')
rbt = api.namespace('RBT', description='Accessible by API')
address = api.schema_model('Address', {
'properties': {
'road': {
'type': 'string'
},
},
'type': 'object'
})
@rbt.route('/<string:resource>/<string:responder>/<string:tag>')
class RBT(Resource):
@rbt.doc(responses={
200: 'Success',
400: 'Validation Error',
500: 'Internal Server Error'
})
#@rbt.marshal_with(address)
def get(self, resource, responder, tag, **kwargs):
'''TC#1 Definition'''
url2 = 'http://' + host + port + '/' + resource + '?' +responder
print(url2)
url = 'http://httpbin.org/get'
parameters = {'resource': resource, 'responder':responder, 'tag': tag}
r = requests.get(url)
data = r.text
return data