Skip to content

Missing settings.SWAGGER_SETTINGS["DEFAULT_INFO"] #3935

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

Closed
tortuegenialez opened this issue Jan 16, 2020 · 4 comments · Fixed by #3993
Closed

Missing settings.SWAGGER_SETTINGS["DEFAULT_INFO"] #3935

tortuegenialez opened this issue Jan 16, 2020 · 4 comments · Fixed by #3993
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user

Comments

@tortuegenialez
Copy link

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
@hSaria
Copy link
Contributor

hSaria commented 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).

@kobayashi
Copy link
Contributor

kobayashi commented Jan 18, 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 kobayashi added the type: housekeeping Changes to the application which do not directly impact the end user label Jan 18, 2020
@jeremystretch
Copy link
Member

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.

@hSaria
Copy link
Contributor

hSaria commented Jan 23, 2020 via email

@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Jan 27, 2020
jeremystretch added a commit that referenced this issue Jan 27, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants