Skip to content

get_schema_view arg url and SWAGGER_SETTINGS['DEFAULT_API_URL'] have no effect #933

@4frag

Description

@4frag

Bug Report

Description

Cannot change the base API URL for Swagger. Tried to set it via settings.py and in the arguments of the get_schema_view function:

SWAGGER_SETTINGS = {
    'DEFAULT_API_URL': 'http://localhost:8000/',
}
schema_view = get_schema_view(
   openapi.Info(
        title='Snippets API',
        default_version='v1',
        description='Test description',
        contact=openapi.Contact(email='<email>'),
        license=openapi.License(name='MIT License'),
    ),
    public=True,
    permission_classes=(permissions.AllowAny,),
    url='http://localhost:8000/',
)

The API URL displayed on the Swagger page did not change after these actions.

Image

The issue was resolved only after I added an API endpoint to the root urlconf, ensuring its URI and the URIs of other endpoints do not intersect.

Image

urlpatterns = [
    # Docs
    path('swagger<format>/', schema_view.without_ui(cache_timeout=0), name='schema-json'),
    path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),

    # Django admin
    path('admin/', admin.site.urls),
    # API endpoints of users app
    path('api/users/', include('users.urls')),

    path('health', test_view)
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions