swagger-api / swagger-api/swagger-codegen
Swagger Codegen Not Generating Default Parameters In Python Client
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Hi, we've created a python client from our spring boot application using swagger-codegen. All of the APIs work well, except when it comes to calling the APIs that have optional parameters (required = False) in the yaml file.
We see that the default parameters set in the yaml is not being set in the generated api file. Hence, while calling the API with optional parameter, when we don't pass any value to the api parameter, it defaults to None from the python client (instead of the default value).
When I generate the api client in java however, I'm seeing that the default parameter values in getting set in the API call.
Is there some option that I need to pass while generating the python client to have the default parameters set ?
Swagger-codegen version
2.4.5
Swagger declaration file content or url
The yaml file below:
regionIdQueryParam:
name: regionId
in: query
description: Region ID of Cloud Provider
required: false
type: string
default: us-east-1
enum:
- ....
The gradle task used to generated the api client:
task genPythonClient(type: JavaExec) {
main = "io.swagger.codegen.SwaggerCodegen"
classpath = configurations.codeGenCli
inputs.files file("${swaggerSpecDir}")
outputs.dir file("${genPythonClient}")
args = ["generate", "--lang", "python", "--input-spec", "${swaggerSpecFile}",
"--config", "${SwaggerConfig}", "--artifact-version", "0.0.1-SNAPSHOT",
"--output", "${genPythonClient}"]
systemProperty "apiTests", "false"
systemProperty "apiDocs", "false"
systemProperty "modelTests", "false"
systemProperty "modelDocs", "false"
}
The Swagger codegen Config file:
{
"library": "resttemplate",
"artifactVersion": "__VERSION__",
"dateLibrary": "java8",
"apiTests": false,
"java8": true,
"serializableModel": true,
"useBeanValidation": true,
"performBeanValidation": true
}
Command line used for generation
Steps to reproduce
Related issues/PRs
https://stackoverflow.com/questions/68618774/avoid-optional-query-parameter-in-swagger-codegen-build
Suggest a fix/enhancement
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 the Gradle genPythonClient task and the generated Python API file described in the report, using the provided YAML parameter declaration as the reproduction case. Trace how the Python client handles an omitted optional query parameter, compare it with the Java client behavior, and verify that the generated client uses us-east-1 when no regionId is supplied.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100