Giter Club home page Giter Club logo

flask-restful-swagger-2.0's People

Contributors

aectann avatar akabraham avatar clems71 avatar dankilman avatar dasevilla avatar dekimsey avatar drorasaf avatar iam10k avatar jackwink avatar kumy avatar lavie avatar niall-byrne avatar nukemberg avatar rantav avatar richtera avatar simstre avatar soerface avatar tjakobsen avatar turbo87 avatar vsu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-restful-swagger-2.0's Issues

Custom URL Map Converter

I am having an issue with getting this to work with a custom url map converter.

Here is a snippet of what I'm trying to do:

import os

import flask
from flask_restful_swagger_2 import Api

from device_key import DeviceKeyConverter
from resources.device import Device, DeviceList


app = flask.Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

api = Api(app, api_version='0.0', 
        api_spec_url='/api', 
        produces=['application/json', 'text/html']
        )
app.url_map.converters['device_key'] = DeviceKeyConverter

api.add_resource(Device, '/devices/<device_key:device_key>')
api.add_resource(DeviceList, '/devices')

With the coverer looking like this:

from werkzeug.routing import BaseConverter
from special_serial_number import SpecialSerialNumber

class DeviceKeyConverter(BaseConverter):
    def to_python(self, value):
        if (isinstance(value, int)) or (':' not in value):
            return int(value)
        return SpecialSerialNumber(value)

    def to_url(self, value):
        if isinstance(value, int):
            return int(value)
        return str(value)

When I run my app I get an error on the line:

api.add_resource(Device, '/devices/<device_key:device_key>')

Here is the error:

Traceback (most recent call last):
  File "/home/tim/work/backend/venv/lib/python3.5/site-packages/flask_restful_swagger_2/swagger.py", line 268, in validate_operation_object
  validate_reference_object(parameter)
  File "/home/tim/work/backend/venv/lib/python3.5/site-packages/flask_restful_swagger_2/swagger.py", line 324, in validate_reference_object
  raise ValidationError('Invalid reference object. It may only contain key "$ref"')
  flask_restful_swagger_2.swagger.ValidationError: Invalid reference object. It may only contain key "$ref"

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "src/app.py", line 47, in <module>
    api.add_resource(Device, '/devices/<device_key:device_key>')
  File "/home/tim/work/backend/venv/lib/python3.5/site-packages/flask_restful_swagger_2/__init__.py", line 119, in add_resource
    validate_path_item_object(path_item)
  File "/home/tim/work/backend/venv/lib/python3.5/site-packages/flask_restful_swagger_2/swagger.py", line 232, in validate_path_item_object
    validate_operation_object(v)
  File "/home/tim/work/backend/venv/lib/python3.5/site-packages/flask_restful_swagger_2/swagger.py", line 270, in validate_operation_object
    validate_parameter_object(parameter)
    File "/home/tim/work/backend/venv/lib/python3.5/site-packages/flask_restful_swagger_2/swagger.py", line 295, in validate_parameter_object
    url='http://swagger.io/specification/#parameterObject'))
    flask_restful_swagger_2.swagger.ValidationError: Invalid parameter object. Unknown field "allowMultiple". See http://swagger.io/specification/#parameterObject

Does this package not support custom URL Map Converters?

Error: securityDefinitions

api = Api(
    app,
    errors=http_errors(),
    api_version='1.0.0',
    api_spec_url='/api/swagger',
    title='T',
    description='Api specifications T',
    contact={
        "name": "Sanju Sci",
        "email": "[email protected]",
        "url": "http://sanjusci.com"
      },
    host=SWAGGER_CONFIG.get('HOST', ""),
    schemes=[
        "http",
        "https",
    ],
    securityDefinitions={
        "Bearer": {
            "type": "apiKey",
            "name": "Authorization",
            "in": "header"
        }
    },
    consumes=[
        "application/json",
        'multipart/form-data'
    ],
    produces=[
        "application/json"
    ]
)
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1683, in <module>
    main()
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1677, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1087, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/sanju.sci/Documents/flask/app.py", line 54, in <module>
    "application/json"
  File "/Users/sanju.sci//Documents/lask/.env/lib/python3.6/site-packages/flask_restful_swagger_2/__init__.py", line 83, in __init__
    super(Api, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'securityDefinitions'

Error: when I define "securityDefinitions" in the configuration for Authorization.

html endpoint is returning JSON

Hello

I'm switching from using flask_restful_swagger to flask_restful_swagger 2

When I attempt to access the .html endpoint, I get the same JSON as the .json endpoint.

Unless I missed it, the documentation doesn't explicitly say that I should install swagger-ui separately. I presumed this would behave as flask_restful_swagger did, and have the swagger-ui support built in. Is this not the case, or have I missed a step?

Can't see the swagger ui

I tried running my api (flask_restful) with the following code and I couldn't get the swagger ui to show.

# Bootstrap api and engines
app = flask.Flask('__name__')
api = flask_restful_swagger_2.Api(app)

I get a 404 not found and I'm on python 3.6 and latest stable flask

How to use Reference Object

class Temp(Schema):
    type='object',
    properties = {
        'name': {
            'type': 'string'
        },
        'obj': {
            'type': 'object',
        }
    }
  @swagger.doc({
        'tags': ['labs'],
        'description': '123123123',
        'parameters': [
            {
                "name": "user",
                "in": "body",
                "description": "user to add to the system",
                "required": True,
                "schema": Temp.reference()
            }
        ],
.................

the Temp doesn't appear in the definitions

access to the post data

How do you access the post data inside a request? Given that the parser can only validate data from the POST this seems quite a missing feature.

Schema - dict instead of property?

Any reason why you made the schema a dict instead of making the properties actual python properties and stored as a named tuple? So after the user can refer to resp.magic, not just resp['magic']?

RequestParser support with custom validation function

I have a custom validation function for a RequestParser argument. And I use the parser object to pass its arguments to spec. But unfortunately, it seems that the library does not support custom types input types e.g

    def one_character_string(value):
        """One character string parameter validator"""
        if isinstance(value, str) and len(value) == 1:
            return value
        else:
            raise ValueError(
                "The parameter '{}' should be a single character length".format(
                   value))

.....
    from flask_restful import reqparse
    parser = reqparse.RequestParser()
    parser.add_argument(
        'customInput', type=one_character_string,
        help='String value expected', required=False)

I am getting the following exception

File "/usr/local/lib/python3.5/dist-packages/flask_restful_swagger_2/init.py", line 271, in get_swagger_arg_type
elif issubclass(type
, basestring):
TypeError: issubclass() arg 1 must be a class

url_prefix not used in swagger output

In the swagger output the url_prefix is not used.

Example:

    "info": {
        "description": "",
        "termsOfService": "",
        "title": "",
        "version": "1.0"
    },
    "paths": {
        "/board": {
            "get": {
                ....
            }
        },
        "/login": {
            "post": {
                .....
            }
        }
    },
    "swagger": "2.0"
}

/board should be /game/board

The only way around this is to not use the url prefix and manually add it to each endpoint.

Both of these do not work:

# Set up place endpoint
game_bp = Blueprint('game', __name__, url_prefix='/game')
# Register blueprints for Game
game_blueprint = get_place_blueprint()
app.register_blueprint(game_blueprint.blueprint, url_prefix='/game')

Inheriting Schema models

Hello,

Is it possible in the Schema classes to inherit the properties from another class somehow?

The use case I have is that I have a bunch of different lists. All the lists share some common properties for pagination, the only thing that is different is the schema reference for the items in that list.

So what I would like is to reuse all those properties.

class ListModel(Schema):
    type = "object"
    properties = {
        "count": {
            "description": "The total number of items in the list",
            "type": "int"
        },
        "limit": {
            "description": "The number of items to show per page",
            "type": "int"
        },
        "offset": {
            "description": "Number of items to offset the pagination",
            "type": "int"
        }
        # "items" goes here in the inherited
    }

And then have multiple specific schemas for the different types:

class SomeListModel(ListModel):
    # properties should now get "items": SomeModel.array() added to it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.