Giter Site home page Giter Site logo

Comments (4)

atlithorn avatar atlithorn commented on July 30, 2024

Weird, could you provide me with a test case. Eg. zip of a barebones flask app where this behaviour is displayed?

from flask-swagger.

tommyjcarpenter avatar tommyjcarpenter commented on July 30, 2024

@atlithorn Here is a working example.

It happens when you want one resource to handle multiple routes. Note that if you try to curl -X POST localhost:5002/HelloWorld/ASDF you will get an error but curl -X POST localhost:5002/HelloWorld will succeed

from flask import Flask, jsonify
from flask_restful import Resource, Api
from flask_swagger import swagger

app = Flask(__name__)
api = Api(app)

class HelloWorld(Resource):
    def post(self):
        """
        Create a new user
        ---
        tags:
          - users
        definitions:
          - schema:
              id: Group
              properties:
                name:
                 type: string
                 description: the group's name
        parameters:
          - in: body
            name: body
            schema:
              id: User
              required:
                - email
                - name
              properties:
                email:
                  type: string
                  description: email for user
                name:
                  type: string
                  description: name for user
                address:
                  description: address for user
                  schema:
                    id: Address
                    properties:
                      street:
                        type: string
                      state:
                        type: string
                      country:
                        type: string
                      postalcode:
                        type: string
                groups:
                  type: array
                  description: list of groups
                  items:
                    $ref: "#/definitions/Group"
        responses:
          201:
            description: User created
        """
        return {'hello': 'world'}
    def get(self, session_id : str) -> "http response":
        return session_id

@app.route("/spec")
def spec():
    return jsonify(swagger(app))

api.add_resource(HelloWorld, '/HelloWorld', '/HelloWorld/<session_id>')

if __name__ == '__main__':
    app.run(debug=True, port = 5002)

from flask-swagger.

dmertl avatar dmertl commented on July 30, 2024

Running into this same issue in my app where we have one resource handling multiple routes. It's adding an operation per route rather than per resource. I'm not sure if there's a good solution though. How would you determine what route tied to what method?

from flask-swagger.

atlithorn avatar atlithorn commented on July 30, 2024

Finally had a look at it and @dmertl is right there is no easy solution without refactoring how flask_swagger discovers resources. It's probably doable but unfortunately not something I need or have time for at the moment. More than willing to review suggestions as always.

from flask-swagger.

Related Issues (20)

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.