swagger-api / swagger-api/swagger-codegen
[ PYTHON ] Bug generating url encoded form data
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Hey Swagger Team!
When setting up a client to send url encoded form data I am getting a strange bug where the python client code that is generated is not runnable because of syntax issues. Specifically it creates some if statements that have nothing inside of them. I'm new to Swagger so there is potential for a bug in my YAML, but I followed the docs closely and the swaggerhub linter flagged no errors. After reaching out to the swaggerhub team they suggested I come talk to you all.
Swagger-codegen version
I am downloading the client code using the Swagger Hub web tool
Swagger declaration file content or url
/preauth:
post:
tags:
- preauth
summary: Call to be made before authentication
description: Determine if a user should be prompted for 2fa
operationId: duopreauth
requestBody:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/preauth_request'
parameters:
- in: header
name: Date
schema:
type: string
format: date
- in: header
name: Host
schema:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/preauth_response'
'400':
description: Invalid status value
security:
- duo_auth_header: []
Here is the referenced component
components:
schemas:
preauth_request:
type: object
properties:
ipaddr:
type: string
username:
type: string
Command line used for generation
Generated via the swaggerhub website
Steps to reproduce
- Generate python client using the above yaml or something like it
- Grab the sample client code from the README
- Try to run that sample client
- Get the error about invalid syntax
Related issues/PRs
None that I could find
Suggest a fix/enhancement
The generated python code looks like this
form_params = []
local_var_files = {}
if 'ipaddr' in params:
# noqa: E501
if 'username' in params:
# noqa: E501
body_params = None
it seems like the form_params variable should be getting updated inside those if blocks but it's not. It also looks like some part of the code generation is expecting there to be a line there because it tried to turn linting off for it haha.
Let me know if there is any more information I can provide!
Xander
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided OpenAPI YAML and the generated Python client, then run the sample client from the README to confirm the syntax error. Inspect the Python generation templates or entry point responsible for url-encoded form data; done means the generated client is runnable and handles both form fields without empty conditional blocks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100