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

All resources are grouped under / - not by resource.

Open seriousben opened this issue 10 years ago • 10 comments

Instead of showing all the resources under the root / path, let's group those by resourceName. Like the pet store example.

seriousben avatar Jul 28 '14 17:07 seriousben

Sounds OK, but to be honest - I hadn't worked on anything swagger in months - will it not break conventions or anything else at swagger? Anyway if not then cool.

rantav avatar Jul 29 '14 04:07 rantav

Hours looking why they are not splited and I see this. Anyone has the solution to get this? Group the resources by resourceName? Thanks!

mserralta avatar Jan 15 '15 13:01 mserralta

Hi @rantav and @mserralta , For my current project, i needed this kind of resources hierarchy in the resulted swagger html, so i created a patch on my fork. We've use this patch for about a month (seems to be stable up to now), i've just push it on my github account to share with you if you need it. https://github.com/lounagen/flask-restful-swagger/commit/88d3aeb9726fa56630431528f21a53d1afbc54a8

See the attached screenshot, associated to this code sample: flask_restful_swagger_hierarchy_screenshot

@swagger.resource(
    hierarchy_id='interfaces'
)
class InterfaceListView(Resource):
 [... my flask restful swagger payload for this class...]


@swagger.resource(
    hierarchy_id='interfaces'
)
class InterfaceView(Resource):
 [... my flask restful swagger payload for this class...]


@swagger.resource(
    hierarchy_id='devices'
)
class DeviceListView(Resource):
 [... my flask restful swagger payload for this class...]


@swagger.resource(
    hierarchy_id='devices'
)
class DeviceView(Resource):
 [... my flask restful swagger payload for this class...]

[... and so on with some other classes ...]

If someone need it, i can add a 'todo.py' sample integration file with such sample. Side effect of this pretty swagger hierarchy 'like the petstore website' is that the generated json is now splitted into multiple json (one per resource hierarchy). To keep backward compatibility in the patch below, i added a new endpoint to print all the resources in a flat json (the actual behaviour, so it should be transparent for existing apps)

Hope that could be usefull!

ps @rantav : great job you've done, i was new to flask and patch your project was a very interesting way to learn flask quickly :-)

lounagen avatar Jan 16 '15 19:01 lounagen

This is awesome, thank you!

lukas-gitl avatar Feb 16 '15 18:02 lukas-gitl

Yes. Awesome. I forgot to say we are using your fork and it is what we were looking for.

Thanks

mserralta avatar Feb 16 '15 18:02 mserralta

We have been using this for a very long time now and it's awesome!

We noticed that the json version is broken (http://localhost:8080/api/spec.json). The response is something like this:

{
    "swaggerVersion": "1.2", 
    "apis": [], 
    "models": {}, 
    "basePath": "http://localhost:8080", 
    "produces": [
        "application/json", 
        "text/html"
    ], 
    "resourcePath": "//default", 
    "apiVersion": "0.1"
}

Any idea how to best fix this? @lounagen @mserralta

lukas-gitl avatar Oct 27 '16 17:10 lukas-gitl

@lukas-gitl I am not sure if I understand what you mean. We have

{swaggerVersion": "1.2", "apiVersion": "1.0"}

apiVersion is defined by yourself in .docs() method.

SwaggerVersion we kept in 1.2 as we are still using this swagger specification. So I think we do not have anything broken. What do you mean by "json version"?

mserralta avatar Oct 28 '16 09:10 mserralta

@mserralta Instead of http://localhost:8080/api/spec.html we are accessing http://localhost:8080/api/spec.json (json instead of html). We are not seeing the sub pages listed and only get the response without any meaningful content (see what I posted above). Is this working for you?

lukas-gitl avatar Oct 28 '16 16:10 lukas-gitl

@lukas-gitl Oh I see. You're right. In api/spec.json I only get information about my defined models and, instead, the resources are defined in /api/spec/_/resource_list.json where in every listed URL are defined the final endpoint.

At least this is how we work with...

mserralta avatar Nov 02 '16 10:11 mserralta

@mserralta Ah/api/spec/_/resource_list.json is great. And then you can just access the resource as listed in there (without json ending). Thank you!

lukas-gitl avatar Nov 02 '16 17:11 lukas-gitl