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

generated urls missing end / #89

Open
oppianmatt opened this issue Sep 3, 2014 · 5 comments
Open

generated urls missing end / #89

oppianmatt opened this issue Sep 3, 2014 · 5 comments

Comments

@oppianmatt
Copy link

In views.py we have:

class ResourcesView(TastypieApiMixin, SwaggerApiDataMixin, JSONView):
    """
    Provide a top-level resource listing for swagger

    This JSON must conform to https://github.com/wordnik/swagger-core/wiki/Resource-Listing
    """

    def get_context_data(self, *args, **kwargs):
        context = super(ResourcesView, self).get_context_data(*args, **kwargs)

        # Construct schema endpoints from resources
        apis = [{'path': '/%s' % name} for name in sorted(self.tastypie_api._registry.keys())]
        context.update({
            'basePath': self.request.build_absolute_uri(reverse('%s:schema' % self.kwargs.get('namespace'))),
            'apis': apis,
        })
        return context

it's creating links like /schema/resource

but in urls.py we have

url(r'^schema/(?P<resource>\S+)/$', SchemaView.as_view()),

note that it has a trailing slash

fix is to change the a line to:

apis = [{'path': '/%s/' % name} for name in sorted(self.tastypie_api._registry.keys())]

People aren't seeing the issue because there is usually middleware which adds a slash for when it 404s making it work.

@oppianmatt
Copy link
Author

problem with that though is that it's designed to display the endpoints without a slash so when it does have a slash it look like a list of /

but really you shouldn't be relying on a 302 redirect to get to the right place from some middleware that might not be enabled

@johnraz
Copy link
Contributor

johnraz commented Sep 3, 2014

Actually this is on purpose to match the swagger specifications
The real fix would be I guess to remove the trailing slash from the url conf.

@johnraz
Copy link
Contributor

johnraz commented Sep 3, 2014

Its not a matter of middleware btw but just a settings (APPEND_SLASH)
edit: well its a combinaison of the 2 but who wouldn't use common middleware in django anyway ?

@oppianmatt
Copy link
Author

you sir are correct. I found this issue when I put in a catch all that matches everything not matched by other urlconfs (because we needed to redirect old links) and that broke swagger. I've made it a negative match. If the url matched the url conf it wouldn't be affected. Looking at swagger when it works, you see a bunch of 301 redirects, so fixing this would improve performance slightly (and help others who have the setting off, or urls confs that will match)

@johnraz
Copy link
Contributor

johnraz commented Sep 3, 2014

We are open to PR ;)

jimlyndon added a commit to jimlyndon/django-tastypie-swagger that referenced this issue Jan 30, 2015
removed trailing slash to resolve tastypie endpoints correctly (not relying on append slash).
See issue concentricsky#89
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