Skip to content

wrong url strings generated in rules when adding namespace with path "/"? #74

@gyre

Description

@gyre

Folks,

I've created a new namespace called base_api.
base_api = Namespace("base")

Have added routes to it with @base_api.route(...)

I want this to be the "root" namespace, so I
api.add_namespace(base_api, path="/")

The problem is now that I have two leading slashes in the url strings for the rules generated and not one.
I've tried leaving the path out or setting it to the empty string but it's replaced by the string "base".

I know I could use the api created by doing:
api = Api(...)
in the main module and put stuff into the default namespace, but I prefer to put all my routes in separate files and separate namespaces rather than cluttering up the main app.

Is there an way to get what I prefer, other than leaving off the leading slash on all the routes for the base namespace?

The following total kludge seems to fix it for me, but maybe I'm not understanding how things work too well :)

class CustomApi(Api):                                                                                    
    def ns_urls(self, ns, urls):                                                                         
        def fix(url):                                                                                    
            return url[1:] if url.startswith("//") else url                                              
                                                                                                         
        return [fix(url) for url in super().ns_urls(ns, urls)]     

Thanks :)

-- gyre --

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions