Repository: netbox-community/netbox

Issue:
Missing settings.SWAGGER_SETTINGS["DEFAULT_INFO"]
<!--
    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
```


Discussion:
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).
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,
)

```


Resolving patch:
diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py
--- a/netbox/netbox/settings.py
+++ b/netbox/netbox/settings.py
@@ -503,6 +503,7 @@ def _setting(name, default=None):
         'utilities.custom_inspectors.IdInFilterInspector',
         'drf_yasg.inspectors.CoreAPICompatInspector',
     ],
+    'DEFAULT_INFO': 'netbox.urls.openapi_info',
     'DEFAULT_MODEL_DEPTH': 1,
     'DEFAULT_PAGINATOR_INSPECTORS': [
         'utilities.custom_inspectors.NullablePaginatorInspector',
diff --git a/netbox/netbox/urls.py b/netbox/netbox/urls.py
--- a/netbox/netbox/urls.py
+++ b/netbox/netbox/urls.py
@@ -9,14 +9,16 @@
 from users.views import LoginView, LogoutView
 from .admin import admin_site
 
+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(
-        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"),
-    ),
+    openapi_info,
     validators=['flex', 'ssv'],
     public=True,
 )


Test patch: