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

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

Closed
5 of 6 tasks
davidchaiken opened this issue Oct 18, 2022 · 0 comments · Fixed by #13723
Closed
5 of 6 tasks

Comments

@davidchaiken
Copy link
Contributor

  • 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,
davidchaiken pushed a commit to davidchaiken/openapi-generator that referenced this issue Oct 18, 2022
spacether pushed a commit that referenced this issue Oct 19, 2022
… data (#13723)

* fix for issue #13722: send body for application/x-www-form-urlencoded data

* fix python test_application_x_www_form_urlencoded_serialization

* x-www-form-urlencoded data needs to be percent encoded

* add verification endpoint test for x-www-form-urlencoded data

Co-authored-by: David Chaiken <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants