flask-restful-swagger icon indicating copy to clipboard operation
flask-restful-swagger copied to clipboard

compatible with swagger 2?

Open tommyjcarpenter opened this issue 9 years ago • 14 comments

When I stub out a new project according to the readme and head to http://localhost:5000/api/spec.html#!/spec, I don't see anything where the dropdown endpoints would show. I'm trying to debug this.

When I click raw, I get a json with all of the models and info I added using the decorators. When I paste that JSON into http://editor.swagger.io/#/, I get:

✖ Swagger Error
Missing required property: paths
Jump to line 0
Details
 Object
✖ Swagger Error
Missing required property: info
Jump to line 0
Details
 Object
✖ Swagger Error
Missing required property: swagger
Jump to line 0
Details
 Object

Any ideas?

tommyjcarpenter avatar Mar 21 '16 15:03 tommyjcarpenter

You are on top of our stuff, right now we only support swagger 1.2, which is kind of outdated. but we are building the new version for new versions also. Here's the link to keep you informed (it will be merged soon): https://github.com/flask-restful-swagger/flask-restful-swagger

When pasting to online validator, it validates against 2.0 specs. And fails for older ones.

sobolevn avatar Mar 21 '16 15:03 sobolevn

@sobolevn thanks for your response!

is there another way I can figure out what I did wrong then? On the main API page I just see: spec : test Show/Hide List Operations Expand Operations Raw [ base url: http://localhost:5000/api/spec/_/resource_list.json , api version: 0.1 ]

but when I click "Raw" I see models, APIs, the whole shebang.

tommyjcarpenter avatar Mar 21 '16 15:03 tommyjcarpenter

@tommyjcarpenter can you please upload a sceenshot?

sobolevn avatar Mar 21 '16 16:03 sobolevn

@sobolevn Here are screenshots:

http://s16.postimg.org/dgg4webd1/Screen_Shot_2016_03_22_at_8_37_14_AM.png

http://s16.postimg.org/tu4ptagw5/Screen_Shot_2016_03_22_at_8_37_19_AM.png

First screenshot is the missing swagger endpoints, second is what I see when I click raw.

The only thing I did to my project was add

###################################
# Wrap the Api with swagger.docs. It is a thin wrapper around the Api class that adds some swagger
# smarts
api = swagger.docs(Api(app), apiVersion='0.1')
###################################

And the example @swagger.operation annotation you have in your readme.

tommyjcarpenter avatar Mar 22 '16 12:03 tommyjcarpenter

What happens when you press Show/ Hide? Any errors in the console?

sobolevn avatar Mar 22 '16 12:03 sobolevn

Nothing happens, no errors. The only thing I can see is the url changes to http://localhost:5000/api/spec.html#!/spec instead of http://localhost:5000/api/spec.html

tommyjcarpenter avatar Mar 22 '16 12:03 tommyjcarpenter

Flask logs show all 200s

tommyjcarpenter avatar Mar 22 '16 12:03 tommyjcarpenter

A bit hasty to close issues with "invalid" on people trying to use your library there

On Mar 22, 2016, at 8:57 AM, Sobolev Nikita [email protected] wrote:

Reopened #94.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

tommyjcarpenter avatar Mar 22 '16 13:03 tommyjcarpenter

I guess, I have managed to repeat you issue. Here's my json, which I had when the issue was pretty similar to yours: http://pastie.org/10769893

As you can see, it's pretty similar. But, we are missing the dataType parameter. The difference is, that I'm having an issue in the console. http://i.imgur.com/1z1Nxbi.png

Fixed json: http://pastie.org/10769890#15 To fix your code, add this line:

@swagger.operation(
        ...
        parameters=[
            {
              ...
              "dataType": "string",  # here
           }

Does this help?

sobolevn avatar Mar 22 '16 13:03 sobolevn

Will try it out later, thanks. Yes you had something like ModelClass in the README but I didn't know what that referred to, and later you had ModelClass2, so I just removed those lines. Maybe add a note to the readme that this parameter is required and what ModelClass is.

Or maybe add string as a default for dataType?

tommyjcarpenter avatar Mar 22 '16 13:03 tommyjcarpenter

Thank you, sure.

sobolevn avatar Mar 22 '16 13:03 sobolevn

Still not seeing the API. My JSON now looks like:

{
    "apiVersion": "0.1",
    "apis": [
        {
            "description": "Describing elephants",
            "notes": null,
            "operations": [
                {
                    "method": "post",
                    "nickname": "upload",
                    "notes": "some really good notes",
                    "parameters": [
                        {
                            "allowMultiple": false,
                            "dataType": "string",
                            "description": "blueprint object that needs to be added. YAML.",
                            "name": "body",
                            "paramType": "body",
                            "required": true
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 201,
                            "message": "Created. The URL of the created blueprint should be in the Location header"
                        },
                        {
                            "code": 405,
                            "message": "Invalid input"
                        }
                    ],
                    "summary": null
                }
            ],
            "path": "/Docker"
        }
    ],
    "basePath": "http://localhost:5000",
    "description": "Auto generated API docs by flask-restful-swagger",
    "models": {},
    "produces": [
        "application/json"
    ],
    "resourcePath": "/",
    "spec_endpoint_path": "/api/spec",
    "swaggerVersion": "1.2"
}

tommyjcarpenter avatar Mar 22 '16 17:03 tommyjcarpenter

I have managed to create the same json, as you have: http://pastie.org/10770850

But, it is working for me. Please, show me the full code you have, maybe the issue is there.

sobolevn avatar Mar 23 '16 08:03 sobolevn

That is difficult, because this was part of a work application, which I cannot post here. I have switched to https://github.com/gangverk/flask-swagger in the meantime. I will re-read your documentation afterwards.

tommyjcarpenter avatar Mar 23 '16 18:03 tommyjcarpenter