flask-restplus icon indicating copy to clipboard operation
flask-restplus copied to clipboard

Params doc

Open vitor-tadashi opened this issue 6 years ago • 1 comments

It's possible to give options for the operation? Something like this: screenshot from 2018-10-24 16-08-31

I'm using restplus but I can't put default values ​​as documentation on the Swagger portal

My code is like this

from flask import Blueprint, url_for, request
from flask_restplus import Resource, Api, fields, reqparse
from services.domain.logic.CommonLandUnitLogic import CommonLandUnitDataLogic


# Fix of returning swagger.json on HTTP
@property
def specs_url(self):
    """
    The Swagger specifications absolute url (ie. `swagger.json`)

    :rtype: str
    """
    return url_for(self.endpoint('specs'), _external=False)


Api.specs_url = specs_url

common_land_unit_blueprint = Blueprint('common_land_unit_blueprint', __name__)
api = Api(common_land_unit_blueprint,
          title='Common Land Unit (CLU)',
          version='0.1.0',
          description='Common land unit data')

namespace = api.namespace('common-land-unit', description='Common Land Unit operations')


@namespace.route('/')
@namespace.response(404, 'Common Land Unit operation not found')
@api.doc(
    delete=False,
    post=False,
    put=False,
    responses={
        404: 'Common Land Unit operation not found'
    })
class CommonLandUnitApi(Resource):

    coordinate = api.model('coordinate', {
        'type': fields.String(readOnly=True, description='Geometric type', example='Polygon'),
        'coordinates': fields.List(fields.List(fields.List(fields.Float(readOnly=True, description='Geolocation point',
                                                                        example=41.8062234))))
    })

    get_querystring = api.model('cool')

    @staticmethod
    @namespace.marshal_list_with(coordinate, code=200, description='Success')
    @namespace.doc(
        responses={
            201: 'Success',
            400: 'Missing parameter',
            403: 'Insufficient permissions',
            500: 'Internal failure',
        },
        params={
            'south': 'South point of location',
            'west': 'West point of location',
            'north': 'North point of location',
            'east': 'East point of location'
        }
    )
    def get():
        parser = reqparse.RequestParser()
        parser.add_argument('south', required=True, help='South point cannot be blank.')
        parser.add_argument('west', required=True, help='West point cannot be blank.')
        parser.add_argument('north', required=True, help='North cannot be blank.')
        parser.add_argument('east', required=True, help='East point cannot be blank.')
        parser.add_argument('south', type=float, help='South point cannot be converted.')
        parser.add_argument('west', type=float, help='West point cannot be converted.')
        parser.add_argument('north', type=float, help='North cannot be converted.')
        parser.add_argument('east', type=float, help='East point cannot be converted.')
        args = parser.parse_args()

        south = args.get("south")
        west = args.get("west")
        north = args.get("north")
        east = args.get("east")

        return CommonLandUnitDataLogic.get_coordinates(south=south, west=west, north=north, east=east)

vitor-tadashi avatar Oct 24 '18 23:10 vitor-tadashi

Yes, I am also wondering why I am not able to add description for Query Parameters. There is no even argument for this. https://flask-restplus.readthedocs.io/en/stable/api.html#module-flask_restplus.reqparse

But Swagger support description for Query Parameters.

VolodyaEsk avatar Nov 28 '19 18:11 VolodyaEsk