OpenAPITools / OpenAPITools/openapi-generator

[discussion] defaultValue for client vs server models

Open
#2,260 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

General: Discussion
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

The following concern was raised in chat:


Writing a client generator: Do clients normally include the defaultValue for model vars? Shouldn't they be filled in by the server (the consumer) and so, not be included in client code?

The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schema-object

So, I'm thinking that "consumer of the input" is the server, not the generated client code, and so the defaultValue might be in a comment, but should not be sent to the server in requests and should not be automatically added to responses where the server didn't include it.


Should we consider an option to support a concept such as separating input vs response models? The idea would be to provide default values on server side input processing, but not for client side model construction (allowing server to provide default for any missing properties).

openapi-generator version

n/a

OpenAPI declaration file content or url
Command line used for generation

n/a

Steps to reproduce

n/a

Related issues/PRs

n/a

Suggest a fix/enhancement

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, tests, generator entry point, or concrete implementation target. Start with the linked OpenAPI 3.0.2 Schema Object definition and clarify whether the requested behavior is for generated clients, servers, or both before identifying a testable change.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.