Skip to content

using the Swagger-UI adds an additional "/api" to the request URL and is missing auth type in header #12410

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
zeddD1abl0 opened this issue May 1, 2023 · 3 comments · Fixed by #12419
Assignees
Labels
status: accepted This issue has been accepted for implementation topic: OpenAPI type: bug A confirmed report of unexpected behavior in the application

Comments

@zeddD1abl0
Copy link

NetBox version

v3.5.0

Python version

3.9

Steps to Reproduce

  1. Go to the Swagger UI for the API (https:///api/schema/swagger-ui/)
  2. Authorize using token to activate testing with Swagger UI
  3. On any resource, attempt to use the Swagger UI

Expected Behavior

Swagger should be able to perform the action as expected by the API request used. It should be able to display the response from the request made.

Observed Behavior

The URL for the request that Swagger generates has another "/api" in the path. Also, the "Authentication" header is missing the "Token " preceding the token string itself.

For Example:

image

curl -X 'GET' \
  'https://netbox/api/api/dcim/devices/?id=1' \
  -H 'accept: application/json' \
  -H 'Authorization: <token>'

Results in the default "Page not Found" error page

image

The following does work

curl -X 'GET' \
  'https://netbox/api/dcim/devices/?id=1' \
  -H 'accept: application/json' \
  -H 'Authorization: Token <token>'
@zeddD1abl0 zeddD1abl0 added the type: bug A confirmed report of unexpected behavior in the application label May 1, 2023
@jeremystretch jeremystretch self-assigned this May 1, 2023
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation topic: OpenAPI labels May 1, 2023
@jeremystretch
Copy link
Member

I was able to correct the base path in the 12410-openapi-fixes branch, however I'll need to dig more into resolving the missing token prefix for the authorization header. The drf-spectacular documentation suggests using OpenApiAuthenticationExtension to override the header, however this is the default format employed by DRF so I'm surprised it doesn't work out of the box.

@arthanson
Copy link
Collaborator

arthanson commented May 1, 2023

"Token" needs to be added when you enter the authentication details in the api/schema Authorize dialog (see screenshot below) if you do enter "Token xxx..." it works correctly. Not sure why spectacular does it this way, seems like they should be able to auto-generate that, but it is by design in spectacular.

Monosnap NetBox REST API 2023-05-01 12-40-40

@jeremystretch
Copy link
Member

Given that this isn't technically a bug, and that it's a separate issue from the base path problem, I'm going to close this as resolved by my work in the 12410-openapi-fixes branch. That said, I'm happy to entertain a separate FR with a proposal to improve the Swagger UI to make the authorization process more intuitive.

jeremystretch added a commit that referenced this issue May 2, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2023
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 topic: OpenAPI type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants