openapi-python-generator icon indicating copy to clipboard operation
openapi-python-generator copied to clipboard

"application/x-www-form-urlencoded" to add to operation_request_body_types in service_generator.py

Open defoortp opened this issue 1 year ago • 3 comments

Content-type "API application/x-www-form-urlencoded" is required for Access Token Request see RFC6749 (The OAuth 2.0 Authorization Framework) section 4.4.2 "Access Token Request"

Could you please add this content-type to operation_request_body_types in service_generator.py like below ?

operation_request_body_types = [
    "application/json",
    "text/plain",
    "multipart/form-data",
    "application/x-www-form-urlencoded" 
]

Thank you for your help !

defoortp avatar Feb 13 '24 14:02 defoortp

Hi there :) Sorry, i won't have much time currently. I'll gladly accept a PR though :)

MarcoMuellner avatar Feb 16 '24 16:02 MarcoMuellner

For anyone curious about the error message Exception: Unsupported request body type: <class 'openapi_schema_pydantic.v3.v????.request_body.RequestBody'>, this is the reason. Simply adding this to the list of operation_request_body_types does not appear to fix the issue, as the generated client still tries to set the Content-Type to application/json.

TheTwitchy avatar Mar 24 '24 01:03 TheTwitchy

We use openapi-python-generator package mainly for the models part. So of course, we had to correct in the services part the operation related to "OAUTH2 Get token" in order to have the good content-type. The change on service_generator.py is not enough even it unblock generation of models part. It could be completed by an issue on openapi_schema_pydantic package in order to added "application/x-www-form-urlencoded" on Content-type.

defoortp avatar May 01 '24 16:05 defoortp