@api.route("/<string:subaccount>/user/<string:uniquename>")
How do I do stricter validation of uniquename much like parsing payloads? Do I do it all manually in my routine? Or is there something more strict than <string:varname>
?
I currently have problems with marshalling my Responses.
I am trying to do the following:
test_model = Model(
"Test",
{
"_id": fields.String,
"name": fields.String,
"location": fields.String,
"ip": fields.String,
},
)
success_model = Model(
"Success",
{"data": fields.List(
fields.Nested(test_model)
)
},
)
Without throwing any exception the data in the response is null
[{"status": "success", "data": null}']
Can somebody give me an advice?
input*
instead of just *
from flask import Flask
from flask_restx import Resource, Api, fields
api = Api()
app = Flask(__name__)
api.init_app(app)
input_model = api.model('Input', {
'type': fields.String,
'topic': fields.String,
})
output_model = api.model('Output', {
'type': fields.String,
'topic': fields.String,
})
@api.route('/input')
class Input(Resource):
@api.marshal_with(input_model, envelope='resource')
def get(self):
return {'hello': 'world'}
@api.route('/output')
class Output(Resource):
@api.marshal_with(output_model, envelope='resource')
def get(self):
return {'hello': 'world'}
control_model = api.model('Control', {
'name': fields.String,
'address': fields.String,
'inputs': fields.Wildcard(fields.Nested(input_model)),
'outputs': fields.Wildcard(fields.Nested(output_model)),
})
@api.route('/control')
class Control(Resource):
@api.marshal_with(control_model, envelope='resource')
def get(self):
return {'hello': 'world'}
if __name__ == '__main__':
app.run(debug=True)
*
have input*
and output*
, to accept a object likecontrol = {
'name': 'Main Control',
'address': '100.100.100.100',
'input1':{},
'input2':{},
'output1':{},
'output3':{},
}