Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

django-hosts subdomains not detected #1334

Open
pitchopp opened this issue Nov 20, 2024 · 1 comment
Open

django-hosts subdomains not detected #1334

pitchopp opened this issue Nov 20, 2024 · 1 comment

Comments

@pitchopp
Copy link

Hello, i installed drf_spectacular in my project that uses django-hosts for handling multiple subdomains. spectacular doesn't detect any view because my ROOT_URLCONF is empty.

here is my django_hosts configuration

from django_hosts import patterns, host
from django.conf import settings

host_patterns = patterns('',
    host(r'', settings.ROOT_URLCONF, name=' '),
    host(r'api', 'api.urls', name='api'),
    host(r'admin', 'backend.admin_urls', name='admin')
)

my root urls is empty because my routes are located in "api" app

urlpatterns = []

here is the output of ./manage.py spectacular

> python manage.py spectacular

openapi: 3.0.3
info:
  title: Your Project API
  version: 1.0.0
  description: Your project description
paths: {}
components: {}

Am i missing a configuration to tell spectacular how to fetch other hosts urls ?

@tfranzel
Copy link
Owner

Hi, I was unaware of this library. Seems like it completely bypasses the regular urlconf and instead injects its own routes via middleware. Spectacular&DRF both know nothing about this "hack".

I guess you have to make spectacular aware of thos injected routes by customizing the generator:

'DEFAULT_GENERATOR_CLASS': 'drf_spectacular.generators.SchemaGenerator',

In fact you only want to set a customized Enumerator class and leave the rest as is:

endpoint_inspector_cls = EndpointEnumerator

You then subclass our enumerator and overwrite the __init__ and make it aware of those other routes.

https://github.com/encode/django-rest-framework/blob/dbac145638758413b966c3418fa5f3f651e3e02a/rest_framework/schemas/generators.py#L61

So basically one changed setting, 1 class with one changed attribute and 1 class with a patched init.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants