Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #13722
Closed
Open
Issue created Oct 18, 2022 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] python generator does not send body for application/x-www-form-urlencoded data

Created by: davidchaiken

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The python generator does not send the body in POST requests that require data encoded as application/x-www-form-urlencoded. Also, data serialized for application/x-www-form-urlencoded should not be prefixed with a question mark '?'.

openapi-generator version

6.2.1-SNAPSHOT (built from master)

OpenAPI declaration file content or url

The petstore.yaml specification used for tests in this repo can be used to reproduce this issue.

Generation Details

The normal tests in this repo can reproduce this issue:

./bin/generate-samples.sh ./bin/configs/python*
Steps to reproduce

I found this issue when using the /v5/oauth/token endpoint documented in https://github.com/pinterest/api-description but I'm pretty sure that doing a POST to the petstore /pet/{petId} endpoint using a client generated for python would also reproduce this bug.

Related issues/PRs

I don't understand issue #2411 completely, but it might be fixed when this issue is fixed.

Suggest a fix

I'll submit a pull request with this patch...

$ git diff modules
diff --git a/modules/openapi-generator/src/main/resources/python/api_client.handlebars b/modules/openapi-generator/src/main/resources/python/api_client.handlebars
index bdcd4519ff4..13f4e01ee51 100644
--- a/modules/openapi-generator/src/main/resources/python/api_client.handlebars
+++ b/modules/openapi-generator/src/main/resources/python/api_client.handlebars
@@ -293,7 +293,7 @@ class StyleFormSerializer(ParameterSerializerBase):
         prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator] = None
     ) -> str:
         if prefix_separator_iterator is None:
-            prefix_separator_iterator = PrefixSeparatorIterator('?', '&')
+            prefix_separator_iterator = PrefixSeparatorIterator('', '&')
         return self._ref6570_expansion(
             variable_name=name,
             in_data=in_data,
diff --git a/modules/openapi-generator/src/main/resources/python/rest.handlebars b/modules/openapi-generator/src/main/resources/python/rest.handlebars
index b1811396168..2ca16e1639e 100644
--- a/modules/openapi-generator/src/main/resources/python/rest.handlebars
+++ b/modules/openapi-generator/src/main/resources/python/rest.handlebars
@@ -139,6 +139,7 @@ class RESTClientObject(object):
                 elif headers['Content-Type'] == 'application/x-www-form-urlencoded':  # noqa: E501
                     r = self.pool_manager.request(
                         method, url,
+                        body=body,
                         fields=fields,
                         encode_multipart=False,
                         preload_content=not stream,
Assignee
Assign to
Time tracking