swagger-api / swagger-api/swagger-codegen
[Python] client None value set query parameters into literal 'None'
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
With the generated Python API client, None value in the parameter with string type has been literally transformed to "None" and added to API call, because in Python string representation of None is "None"
But given that None in Python generally means a non-exist value, the expected behavior should not pass the value in query parameters or set the parameter value with a default value if specified.
Swagger-codegen version
2.4.17
Swagger declaration file content or url
If you post the code inline, please wrap it with
...
parameters: [{
"name": "test",
"in": "query",
"required": false,
"type": "string"
}]
...
-->
Command line used for generation
java -jar swagger-codegen-cli-2.4.17.jar generate -l python -i swagger.json
Steps to reproduce
We generated the swagger.json file using swagger annotation (@ApiParam) from a Dropwizard application written in Java.
Suggest a fix/enhancement
Add None check in api.mustache.
{{#queryParams}}
if '{{paramName}}' in params and params['{{paramName}}'] is not None:
query_params.append(('{{baseName}}', params['{{paramName}}'])){{#isListContainer}} # noqa: E501
{{/queryParams}}
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 with modules/swagger-codegen/src/main/resources/python/api.mustache and inspect how optional query parameters are appended in generated Python clients. Generate a client from a definition containing an optional string query parameter, then verify that passing None omits the parameter rather than sending the literal value "None".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100