Last active
June 11, 2018 11:58
-
-
Save isabelcosta/53638ab5fb04bc92742e0d9c59625bc4 to your computer and use it in GitHub Desktop.
Documenting Login API on Swagger with flask RESTPlus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import request | |
from flask_restplus import Resource, marshal | |
from flask_jwt import jwt_required, current_identity | |
# Resquest body model to document on Swagger | |
login_request_body_model = Model('Login data model', { | |
'username': fields.String(required=True, description='User\'s username'), | |
'password': fields.String(required=True, description='User\'s password') | |
}) | |
# User namespace used by flask RESTPlus | |
users_ns = api.namespace('Users', description='Operations related to users') | |
users_ns.models[login_request_body_model.name] = login_request_body_model | |
# Route /login | |
@users_ns.route('login') | |
class LoginUser(Resource): | |
@classmethod | |
@users_ns.doc('login') | |
@users_ns.expect(login_request_body_model) | |
def post(cls): | |
""" | |
Login user | |
""" | |
return jwt.request_handler() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment