The following code works:
@api.route('/properties')
@api.doc(security='Basic Auth')
class CameraProperties(Resource):
def get(self):
return Utils.convertToDictionary(Camera().camera)
@api.doc(body=camera_fields)
def put(self):
reqData = json.loads(request.data)
for a in reqData:
exec("Camera().camera." + a + "=reqData['" + a + "']")
@api.route('/stillshot')
@api.doc(security='Basic Auth')
class StillShot(Resource):
def put(self):
Camera().TakeStillShot()
However, in order to avoid repeating code, I would like to move the security decorator to the Namespace
decorators list like so:
api = Namespace('camera', description='Camera operations', security='Basic Auth', authorizations=authorizations)
api.decorators = [auth.login_required, api.doc(security='Basic Auth')]
But if I do that, when I run the app Swagger doesn't show the padlock by the side of the methods, i.e. the decorator is not working.
The auth.login_required
decorator does work, so I'm guessing this is something to do with the decorator parameters, but I can't figure out why it doesn't work.
The full code is here:
https://github.com/codewrite/PiCam1/tree/duplicated-swagger-decorator-does-work/py3/apis https://github.com/codewrite/PiCam1/blob/shared-swagger-decorator-not-working/py3/apis/camera.py