Missing settings.SWAGGER_SETTINGS["DEFAULT_INFO"] #3169

Closed
opened 2025-12-29 18:26:18 +01:00 by adam · 4 comments
Owner

Originally created by @tortuegenialez on GitHub (Jan 16, 2020).

Environment

  • Python version: 3.5.4
  • NetBox version: 2.6.12

Steps to Reproduce

  1. Follow the install steps from the documentation (https://netbox.readthedocs.io/en/stable/installation/) and install from a downloaded release.
  2. generate swagger schema (python3 manage.py generate_swagger -f json)

Expected Behavior

Schema generated

Observed Behavior

  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.5/dist-packages/drf_yasg/management/commands/generate_swagger.py", line 120, in handle
    'settings.SWAGGER_SETTINGS["DEFAULT_INFO"] should be an '
django.core.exceptions.ImproperlyConfigured: settings.SWAGGER_SETTINGS["DEFAULT_INFO"] should be an import string pointing to an openapi.Info object
Originally created by @tortuegenialez on GitHub (Jan 16, 2020). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.5.4 * NetBox version: 2.6.12 ### Steps to Reproduce 1. Follow the install steps from the documentation (https://netbox.readthedocs.io/en/stable/installation/) and install from a downloaded release. 2. generate swagger schema (python3 manage.py generate_swagger -f json) <!-- What did you expect to happen? --> ### Expected Behavior Schema generated <!-- What happened instead? --> ### Observed Behavior ```Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 364, in execute output = self.handle(*args, **options) File "/usr/local/lib/python3.5/dist-packages/drf_yasg/management/commands/generate_swagger.py", line 120, in handle 'settings.SWAGGER_SETTINGS["DEFAULT_INFO"] should be an ' django.core.exceptions.ImproperlyConfigured: settings.SWAGGER_SETTINGS["DEFAULT_INFO"] should be an import string pointing to an openapi.Info object ```
adam added the status: acceptedtype: housekeeping labels 2025-12-29 18:26:18 +01:00
adam closed this issue 2025-12-29 18:26:18 +01:00
Author
Owner

@hSaria commented on GitHub (Jan 16, 2020):

The schema can be generated through the API through http://netbox/api/swagger.json. YAML is also supported with swagger.yaml.

I think it'd be good to move openapi.Info in netbox/urls.py to netbox/settings.py (value of settings.SWAGGER_SETTINGS['DEFAULT_INFO']) and then schema_view in netbox.urls.py would reference that instead.

Edit: noticed that we can't import openapi in settings.py due to AppRegistryNotReady, but setting the value of settings.SWAGGER_SETTINGS['DEFAULT_INFO'] in urls.py does work, but I'm not sure if that's a good practice or not (modifying settings outside of the module).

@hSaria commented on GitHub (Jan 16, 2020): The schema can be generated through the API through `http://netbox/api/swagger.json`. YAML is also supported with `swagger.yaml`. I think it'd be good to move `openapi.Info` in `netbox/urls.py` to `netbox/settings.py` (value of `settings.SWAGGER_SETTINGS['DEFAULT_INFO']`) and then `schema_view` in `netbox.urls.py` would reference that instead. Edit: noticed that we can't import openapi in settings.py due to `AppRegistryNotReady`, but setting the value of `settings.SWAGGER_SETTINGS['DEFAULT_INFO']` in `urls.py` does work, but I'm not sure if that's a good practice or not (modifying `settings` outside of the module).
Author
Owner

@kobayashi commented on GitHub (Jan 19, 2020):

I would accept this issue to implement.

From drf-yang docs, that one mentioned by @hSaria is an usual way.

in settings.py

SWAGGER_SETTINGS = {
    'DEFAULT_INFO': 'netbox.urls.openapi_info',

in urls.py

openapi_info = openapi.Info(
    title="NetBox API",
    default_version='v2',
    description="API to access NetBox",
    terms_of_service="https://github.com/netbox-community/netbox",
    license=openapi.License(name="Apache v2 License"),
)
schema_view = get_schema_view(
    openapi_info,
    validators=['flex', 'ssv'],
    public=True,
)

@kobayashi commented on GitHub (Jan 19, 2020): I would accept this issue to implement. From [drf-yang docs](https://drf-yasg.readthedocs.io/en/stable/rendering.html#management-command), that one mentioned by @hSaria is an usual way. in settings.py ``` SWAGGER_SETTINGS = { 'DEFAULT_INFO': 'netbox.urls.openapi_info', ``` in urls.py ``` openapi_info = openapi.Info( title="NetBox API", default_version='v2', description="API to access NetBox", terms_of_service="https://github.com/netbox-community/netbox", license=openapi.License(name="Apache v2 License"), ) schema_view = get_schema_view( openapi_info, validators=['flex', 'ssv'], public=True, ) ```
Author
Owner

@jeremystretch commented on GitHub (Jan 23, 2020):

manage.py generate_swagger is not a documented feature of NetBox. It's provided by the drf_yasg library but not explicitly supported, so first we would need a feature request to propose officially supporting the command (including the introduction of documentation for it).

Personally I don't see the benefit over just using the API (which can be accessed remotely) for this, but that's a matter for discussion in the feature request.

@jeremystretch commented on GitHub (Jan 23, 2020): `manage.py generate_swagger` is not a documented feature of NetBox. It's provided by the `drf_yasg` library but not explicitly supported, so first we would need a feature request to propose officially supporting the command (including the introduction of documentation for it). Personally I don't see the benefit over just using the API (which can be accessed remotely) for this, but that's a matter for discussion in the feature request.
Author
Owner

@hSaria commented on GitHub (Jan 23, 2020):

Oh, I figured it should’ve been there since the start, but was simply missed.

I personally wouldn’t even document it. As you mentioned, the API is the way to go for most people, but since this is an implementation of drf_yasg, people familiar with that project might know of manage subcommand and use it as a standard method of generating the schema in their environment. In other words, only those that understand the subcommand’s scope would use it; documenting it might steer people away from the native method, the API.

On 23 Jan 2020, at 4:10 pm, Jeremy Stretch notifications@github.com wrote:


manage.py generate_swagger is not a documented feature of NetBox. It's provided by the drf_yasg library but not explicitly supported, so first we would need a feature request to propose officially supporting the command (including the introduction of documentation for it).

Personally I don't see the benefit over just using the API (which can be accessed remotely) for this, but that's a matter for discussion in the feature request.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

@hSaria commented on GitHub (Jan 23, 2020): Oh, I figured it should’ve been there since the start, but was simply missed. I personally wouldn’t even document it. As you mentioned, the API is the way to go for most people, but since this is an implementation of drf_yasg, people familiar with that project might know of manage subcommand and use it as a standard method of generating the schema in their environment. In other words, only those that understand the subcommand’s scope would use it; documenting it might steer people away from the native method, the API. > On 23 Jan 2020, at 4:10 pm, Jeremy Stretch <notifications@github.com> wrote: > >  > manage.py generate_swagger is not a documented feature of NetBox. It's provided by the drf_yasg library but not explicitly supported, so first we would need a feature request to propose officially supporting the command (including the introduction of documentation for it). > > Personally I don't see the benefit over just using the API (which can be accessed remotely) for this, but that's a matter for discussion in the feature request. > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub, or unsubscribe.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3169