Support passing of "title" attribute from views to the generated schema Links#5275
Support passing of "title" attribute from views to the generated schema Links#5275wrsulliv wants to merge 2 commits intoencode:masterfrom
Conversation
…instances. This is part of a proposed solution to core-api/python-openapi-codec#28
| Determine a title from a view instance. | ||
|
|
||
| If the 'title' attribute is not set on the view, then an empty title is returned. | ||
| """ |
There was a problem hiding this comment.
btw, this could be simplified as a simple getattr call.
return getattr(view, 'title', '')There was a problem hiding this comment.
Ah, thank you, I'll try to remember this in the future.
|
I'm going to close this. From 3.7 the correct way to handle this will be to subclass Something like: You can try this now installing |
|
Hi! Tried the 'TitledSchema' sample above, but I receive a "'Link' object doesn't support property assignment" error. Can you point some example code working in the latest version? Thanks UPDATE: Changed Django Rest Swagger for drf-yasg and it worked fine. |
As described by core-api/python-openapi-codec#28, the "name" field of the generated Swagger JSON is currently hard-coded to "data". When using swagger-codegen, the generated models are labeled <Data*> which breaks the reusability of the generated SDKs.
The proposed solution allows a user to set a "title" property on a view (or viewset) which is then used to generate the "name" field in this format: <Title><Action>Params.
For example, the "post" action of the following viewset will be given a name of "CommentPostParams" instead of "data".
This pull request has an associated pull request: core-api/python-openapi-codec#42, both of which act to drive further discussion on core-api/python-openapi-codec#28.
Assuming views and viewsets are named <ViewName>View and <ViewSetName>ViewSet, it would also be possible to extract the view name automatically with a small code change.
Related issue: marcgibbons/django-rest-swagger#595