flask-restful-swagger
flask-restful-swagger copied to clipboard
All resources are grouped under / - not by resource.
Instead of showing all the resources under the root /
path, let's group those by resourceName. Like the pet store example.
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.
Hours looking why they are not splited and I see this. Anyone has the solution to get this? Group the resources by resourceName? Thanks!
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:
@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 :-)
This is awesome, thank you!
Yes. Awesome. I forgot to say we are using your fork and it is what we were looking for.
Thanks
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 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 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 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 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!