OpenAPITools / OpenAPITools/openapi-generator

[REQ] Client:Python Add default parameters to function definition

Open
#4,668 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Python Enhancement: Feature Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

The original API declares a parameter with a default value. This value does not
show as default value in the python function definition. As a consequence I get less than optional IDE support for my functions and need to retype the value.

Describe the solution you'd like

If the openapi defnition contains a default field in the parameter schema section I would like it to be encoded in the python function header. e.g.
fun call_some_api_using_post(self, param=/default/, **kwargs):

Describe alternatives you've considered

  1. Server side modification
    I could make that parameter optionional and fill in the parameter on the server side if it is missing. This solution is frustrating, because there is little IDE support for it. I want automatic parameter completion (intellisense) and automated lists of available parameters.

  2. Including all optional parameters
    All optional parameters could be included in the python header with default None, e.g.
    fun call_some_api_using_post(self, optional_param1=None, optional_param2=None, **kwargs):

I rejected this solution because it would be more invasive and generate code that would be redundant for use cases that do not aim for optimized editor support.

Additional context

ide

If such a feature is welcome I would work on a pull request. I was trying to follow the guidelines form the README in this project.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests; begin by locating the Python client generator's parameter-schema handling and its generated function-signature tests. Done means an OpenAPI parameter default is emitted in the generated Python function definition without adding unrelated optional parameters, with coverage for the requested behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.