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

API Docs - Disable online swagger validator #2064

Closed
Keyhaku opened this issue Apr 27, 2018 · 6 comments
Closed

API Docs - Disable online swagger validator #2064

Keyhaku opened this issue Apr 27, 2018 · 6 comments
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@Keyhaku
Copy link

Keyhaku commented 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

@Keyhaku
Copy link
Author

Keyhaku commented 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 Keyhaku changed the title Disable online swagger validator API Docs - Disable online swagger validator Apr 27, 2018
@bartdebruijn
Copy link

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

@jeremystretch
Copy link
Member

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

@jeremystretch jeremystretch added the status: revisions needed This issue requires additional information to be actionable label May 22, 2018
@bartdebruijn
Copy link

@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?

@rijalati
Copy link

rijalati commented 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

@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation and removed status: revisions needed This issue requires additional information to be actionable labels Jul 2, 2018
@jeremystretch
Copy link
Member

Fixed in ef61c70

@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 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: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

4 participants