OpenAPITools / OpenAPITools/openapi-generator

[REQ][Java] Set custom default parameter values in the client code

Open
#18,147 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
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.

It would be nice to allow for (global) client-specific default values for query parameters in the generated API.
This would allow a client to use e.g. a custom paging default pageSize, deviating from the API provided default.
E.g. the API supports a default value of 100, but the client wants to fetch 1.000 by default.

Describe the solution you'd like

Allow to define custom default values for specified parameter names.
e.g. parameter limit: defaultValue: 1000
(API: default: 100)

Use those defaults in the generated client API code.

Describe alternatives you've considered

An alternative solution is to create local helper classes doing the initialization of the default values.
This works nice if only few methods need the custom default value.
However, if all paging methods should use a custom default value, this gets cumbersome.

Questions / Hints

  • What would be the best place to add configuration for the custom default values?
  • Modify the api.mustache file and check if {{paramName}} == null and then set the default value if available?
  • Make sure this also works for API-specs using useSingleRequestParameter ("x-group-parameters": true)

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

Start with the Java client generation path and the api.mustache template mentioned in the issue. Compare how default parameter values are represented in generated methods, including APIs using useSingleRequestParameter ("x-group-parameters": true). Done means a client can configure global parameter defaults and generated paging methods use them without changing the API specification defaults.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.