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

Urls not correctly "currled" #37

Closed
chgad opened this issue Jan 6, 2018 · 9 comments
Closed

Urls not correctly "currled" #37

chgad opened this issue Jan 6, 2018 · 9 comments
Assignees
Milestone

Comments

@chgad
Copy link

chgad commented Jan 6, 2018

Hi,

i encountered the following:

when clicking "try it out!" in one of my GET Endpoints the curl prompt beneath it states a wrong statement :curl -X GET "localhost://localhost:8000/api/myendpoint/(P101[0-9]+)" -H "accept: application/json" -H "X-CSRFToken: x4bdC0d9Chl2ZThQEpJCi1WzadO0NTIPVa5FXSqkIRvjJ9xvJvBzvZWZLvQ3viDC"

This is obviously a wrong behavior. The correct, and succesfull, curl should look like this :
curl -X GET "localhost:8000/api/myendpoint/101" -H "accept: application/json" -H "X-CSRFToken: x4bdC0d9Chl2ZThQEpJCi1WzadO0NTIPVa5FXSqkIRvjJ9xvJvBzvZWZLvQ3viDC"

my urls.py looks like this :

[...] url(r'^myendpoint/(?P<pk>[0-9]+)', myendpoint.as_view) [...]
This might be an "localhost" problem (I can not validate the issue for the production system, docs aren't online till now) , but still shouldn't ouccur.

@axnsan12
Copy link
Owner

axnsan12 commented Jan 7, 2018

Hello @chgad,

Does the "try it out" function work from the web UI? (I.e. is it just the curl URL which has problems?)

I tried, but can't manage to reproduce the issue. What python/rest-framework/Django versions are you using? Can you provide the generated swagger.yaml or .json spec for your api, or a minimal example which exhibits the issue?

Thanks.

@axnsan12 axnsan12 added the bug Bug report/fix label Jan 7, 2018
@axnsan12 axnsan12 self-assigned this Jan 7, 2018
@chgad
Copy link
Author

chgad commented Jan 7, 2018

Hi,

im running django 1.11.7 ,drf 3.7.7 on a python version 3.6.2.

swagger_wrong_curl

This is a screenshot of the wrong behavior. Im not sure what your saying about the .json/.yaml spec ? hwo would this help ?

@axnsan12
Copy link
Owner

axnsan12 commented Jan 7, 2018

I'm trying to figure out what happens, as I said, I can't manage to reproduce it. The json/yaml spec is the source of the documentation - you can get it by accessing ?format=openapi, or by using schema_view.without_ui().

Back to your problem, are you by any chance using path() instead of url() for routing your urls?

Does the app itself work?

@chgad
Copy link
Author

chgad commented Jan 7, 2018

Ah now i got it.

here is the spec:

e_flfA5q.txt

Nope i'm not using path() and yes my app works just fine. I can't geive feedback about "live behavior" since the docs aren't online yet.

@axnsan12
Copy link
Owner

axnsan12 commented Jan 7, 2018

Also how are you instantiating the schema view, and how are you accesing it in the browser? (i.e. the full URL) - it's strange to see that it picks up localhost as the URL scheme.

@chgad
Copy link
Author

chgad commented Jan 9, 2018

I instatiate it as it's said in the "Getting started", no customization. i acces it via localhost:8000/api/swagger.
All Api Endpoints are nested under api/

@axnsan12
Copy link
Owner

Hello,

I think I have some ideas:

  • your (terminal) pattern should end in $ - so r'^myendpoint/(?P<pk>[0-9]+)$' instead of r'^myendpoint/(?P<pk>[0-9]+)'
  • if you are manually providing a url to get_schema_view, it should be an absolute url with protocol - http://localhost:8000/ instead of localhost:8000/

@chgad
Copy link
Author

chgad commented Jan 10, 2018

Yeah!

The Problem was that i declared an incorrect url in the get_schema_view.

I declared localhost:8000/api/ instead of , what you said, http://localhost:8000/api/.

This fact of an absoulute url could be stated in the docs (?). It would definetly clarify it abit to prevent further Problems with the url.

Thanks for the fast and coninuous help.
I close this Issue for now.

@chgad chgad closed this as completed Jan 10, 2018
@axnsan12 axnsan12 added this to the 1.2.0 milestone Jan 11, 2018
@axnsan12
Copy link
Owner

Re-opening to remember to improve handling of this.

@axnsan12 axnsan12 reopened this Jan 11, 2018
@axnsan12 axnsan12 added enhancement and removed bug Bug report/fix labels Jan 11, 2018
axnsan12 added a commit that referenced this issue Jan 12, 2018
* added handling of basePath by taking into account SCRIPT_NAME and the longest common prefix
* improved handling of NamespaceVersioning by excluding URLs of differing versions
* added documentation and error messages for the problem reported in #37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants