Skip to content

[Python] ApiClient should encode '/' char for parameters (path parameters) #4391

@jhartlaub

Description

@jhartlaub
Description

When using PathParams containing a '/' character, the Python client does not encode the '/'. As a result, the / is interpreted as a path separator rather than a parameter value. PathSegments must encode the / character for proper transfer of information. e.g. 'my/string' should be encoded to 'my%2Fstring' for correct transmission of a PathParam argument. Path separators must only be used between path segments.

Swagger-codegen version

Not a regression, this is broken on the master HEAD.

Swagger declaration file content or url

Not a problem with the definition, problem with the template code.

Command line used for generation

python client code gen, vanilla

Steps to reproduce
  1. create a client using a path parameter
  2. attempt call the client using a string PathParam argument with a '/' in it.
  3. Notice that an error is returned from the server.
Related issues

Not reported.

Suggest a Fix

the ApiClient uses the urllib "quote" function which by default sets the '/' as a "safe" character, e.g. quote('my/string') -> 'my/string'.

However, setting the safe chars default arg to indicate no chars are safe yields the desired result: quote('my/string', safe='') ->'my%2Fstring'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions