API Docs - Disable online swagger validator #1704

Closed
opened 2025-12-29 16:34:34 +01:00 by adam · 6 comments
Owner

Originally created by @Keyhaku on GitHub (Apr 27, 2018).

Issue type

[X] Feature request
[ ] Bug report
[ ] Documentation

Environment

  • Python version: 3.6.5
  • NetBox version: 2.3.3

Description

Hello,

Our instance of netbox is restricted to our internal network only, the problem is that when someone go to the API doc view (/api/docs/), the online swagger validator is triggered, and it delays the whole display of API endpoints to finally display a nice "error badge".

I don't get the point of this online validator on production environnement ...

Thank you

Originally created by @Keyhaku on GitHub (Apr 27, 2018). <!-- Before opening a new issue, please search through the existing issues to see if your topic has already been addressed. Note that you may need to remove the "is:open" filter from the search bar to include closed issues. Check the appropriate type for your issue below by placing an x between the brackets. For assistance with installation issues, or for any other issues other than those listed below, please raise your topic for discussion on our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please note that issues which do not fall under any of the below categories will be closed. Due to an excessive backlog of feature requests, we are not currently accepting any proposals which extend NetBox's feature scope. Do not prepend any sort of tag to your issue's title. An administrator will review your issue and assign labels as appropriate. ---> ### Issue type [X] Feature request <!-- An enhancement of existing functionality --> [ ] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> <!-- Please describe the environment in which you are running NetBox. (Be sure to verify that you are running the latest stable release of NetBox before submitting a bug report.) If you are submitting a bug report and have made any changes to the code base, please first validate that your bug can be recreated while running an official release. --> ### Environment * Python version: 3.6.5 * NetBox version: 2.3.3 <!-- BUG REPORTS must include: * A list of the steps needed for someone else to reproduce the bug * A description of the expected and observed behavior * Any relevant error messages (screenshots may also help) FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### Description Hello, Our instance of netbox is restricted to our internal network only, the problem is that when someone go to the API doc view (/api/docs/), the online swagger validator is triggered, and it delays the whole display of API endpoints to finally display a nice "error badge". I don't get the point of this online validator on production environnement ... Thank you
adam added the type: bugstatus: accepted labels 2025-12-29 16:34:34 +01:00
adam closed this issue 2025-12-29 16:34:34 +01:00
Author
Owner

@Keyhaku commented on GitHub (Apr 27, 2018):

It seems there is no way to customize Swagger settings, since you enforce configuration
https://github.com/digitalocean/netbox/blob/develop/netbox/netbox/settings.py#L250

@Keyhaku commented on GitHub (Apr 27, 2018): It seems there is no way to customize Swagger settings, since you enforce configuration https://github.com/digitalocean/netbox/blob/develop/netbox/netbox/settings.py#L250
Author
Owner

@bartdebruijn commented on GitHub (May 8, 2018):

I have the same issue, it would be nice if we could override the online validator setting from the main config file.

@bartdebruijn commented on GitHub (May 8, 2018): I have the same issue, it would be nice if we could override the online validator setting from the main config file.
Author
Owner

@jeremystretch commented on GitHub (May 22, 2018):

What is the exact change being proposed? How would you modify the configuration?

@jeremystretch commented on GitHub (May 22, 2018): What is the exact change being proposed? How would you modify the configuration?
Author
Owner

@bartdebruijn commented on GitHub (May 24, 2018):

@jeremystretch well according to https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md you can pass the following to Swagger-UI:

validatorUrl String="https://online.swagger.io/validator" OR null. By default, Swagger-UI attempts to validate specs against swagger.io's online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators (Validator Badge). Setting it to null will disable validation.

Not sure on how to implement that into Netbox. Perhaps if we can set that from configuration.py as an exported variable or something?

@bartdebruijn commented on GitHub (May 24, 2018): @jeremystretch well according to https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md you can pass the following to Swagger-UI: validatorUrl | String="https://online.swagger.io/validator" OR null. By default, Swagger-UI attempts to validate specs against swagger.io's online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators (Validator Badge). Setting it to null will disable validation. -- | -- Not sure on how to implement that into Netbox. Perhaps if we can set that from configuration.py as an exported variable or something?
Author
Owner

@rijalati commented on GitHub (Jun 25, 2018):

So this was an issue for me too, but you can set the validatorUrl via SWAGGER_SETTINGS in settings.py, here's what mine looks like:

SWAGGER_SETTINGS = {
    'DEFAULT_FIELD_INSPECTORS': [
        'utilities.custom_inspectors.NullableBooleanFieldInspector',
        'utilities.custom_inspectors.CustomChoiceFieldInspector',
        'drf_yasg.inspectors.CamelCaseJSONFilter',
        'drf_yasg.inspectors.ReferencingSerializerInspector',
        'drf_yasg.inspectors.RelatedFieldInspector',
        'drf_yasg.inspectors.ChoiceFieldInspector',
        'drf_yasg.inspectors.FileFieldInspector',
        'drf_yasg.inspectors.DictFieldInspector',
        'drf_yasg.inspectors.SimpleFieldInspector',
        'drf_yasg.inspectors.StringDefaultFieldInspector',
    ],
    'DEFAULT_FILTER_INSPECTORS': [
        'utilities.custom_inspectors.IdInFilterInspector',
        'drf_yasg.inspectors.CoreAPICompatInspector',
    ],
    'DEFAULT_PAGINATOR_INSPECTORS': [
        'utilities.custom_inspectors.NullablePaginatorInspector',
        'drf_yasg.inspectors.DjangoRestResponsePagination',
        'drf_yasg.inspectors.CoreAPICompatInspector',
    ],
    'VALIDATOR_URL': None
}

which sets the UI's validatorUrl to Null. Here's what the swagger-settings json object looks like when I view the page source:

<script id="swagger-settings" type="application/json">{"docExpansion": "list", "deepLinking": false, "showExtensions": true, "defaultModelRendering": "model", "defaultModelExpandDepth": 3, "defaultModelsExpandDepth": 3, "showCommonExtensions": true, "supportedSubmitMethods": ["get", "put", "post", "delete", "options", "head", "patch", "trace"], "validatorUrl": null}</script>

Edit: I went digging through the drf-yasg docs to find this setting, it may be useful to refer to them in the Netbox docs or at least put the link in a comment in settings.py

https://drf-yasg.readthedocs.io/en/stable/settings.html#validator-url

@rijalati commented on GitHub (Jun 25, 2018): So this was an issue for me too, but you can set the validatorUrl via `SWAGGER_SETTINGS` in `settings.py`, here's what mine looks like: ```python SWAGGER_SETTINGS = { 'DEFAULT_FIELD_INSPECTORS': [ 'utilities.custom_inspectors.NullableBooleanFieldInspector', 'utilities.custom_inspectors.CustomChoiceFieldInspector', 'drf_yasg.inspectors.CamelCaseJSONFilter', 'drf_yasg.inspectors.ReferencingSerializerInspector', 'drf_yasg.inspectors.RelatedFieldInspector', 'drf_yasg.inspectors.ChoiceFieldInspector', 'drf_yasg.inspectors.FileFieldInspector', 'drf_yasg.inspectors.DictFieldInspector', 'drf_yasg.inspectors.SimpleFieldInspector', 'drf_yasg.inspectors.StringDefaultFieldInspector', ], 'DEFAULT_FILTER_INSPECTORS': [ 'utilities.custom_inspectors.IdInFilterInspector', 'drf_yasg.inspectors.CoreAPICompatInspector', ], 'DEFAULT_PAGINATOR_INSPECTORS': [ 'utilities.custom_inspectors.NullablePaginatorInspector', 'drf_yasg.inspectors.DjangoRestResponsePagination', 'drf_yasg.inspectors.CoreAPICompatInspector', ], 'VALIDATOR_URL': None } ``` which sets the UI's `validatorUrl` to `Null`. Here's what the `swagger-settings` json object looks like when I view the page source: ```html <script id="swagger-settings" type="application/json">{"docExpansion": "list", "deepLinking": false, "showExtensions": true, "defaultModelRendering": "model", "defaultModelExpandDepth": 3, "defaultModelsExpandDepth": 3, "showCommonExtensions": true, "supportedSubmitMethods": ["get", "put", "post", "delete", "options", "head", "patch", "trace"], "validatorUrl": null}</script> ``` Edit: I went digging through the drf-yasg docs to find this setting, it may be useful to refer to them in the Netbox docs or at least put the link in a comment in `settings.py` https://drf-yasg.readthedocs.io/en/stable/settings.html#validator-url
Author
Owner

@jeremystretch commented on GitHub (Jul 2, 2018):

Fixed in ef61c70a9d

@jeremystretch commented on GitHub (Jul 2, 2018): Fixed in ef61c70a9dc36969678691afed6b9dbedb33963c
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1704