This repository has been archived by the owner on Jan 11, 2021. It is now read-only.
Add basic schema_view and a default url that maps to it #493
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@marcgibbons, what would you think about adding a
schema_view
that does basically what the example shows directly to this package? I liked the old version, I see no reason to require the user to create a whole view just for Swagger (Or, OpenAPI). So I basically copied the exampleschema_view
and added a route to it in urls.py, so that you can I can include Swagger the same way we used to:The one difficulty was the fact that in your example, the title for the SchemaGenerator was hard-coded. So I played around with it, and found that there are two places to include Swagger:
Specified in App
In the first case, it's possible to programmatically get the name of the app, and then you could just insert that. Just remember to set your
app_name
in yoururls.py
by following one of the two examples shown here.Extending the example above, this then would look like (in increasing order of my personal preference):
or
(I also considered replacing
-
and_
characters in theapp_name
with spaces to generate the api title, just in case. What do you think?)Specified in Project
In the second case, I can't find anyplace that specifies a "name" of your Django project, so I just defaulted to grabbing the name of the Django project folder.
Title Set Explicitly
Alternatively, this
schema_view
implementation also accepts the title as an extra argument, as shown here.This method of finding a name for the schema seems OK for a first-go to me, but I'm not married to it. If you like this PR, I'd be happy to modify the documentation accordingly, but I'll wait for a thumbs-up before I go to that effort.