OpenAPITools / OpenAPITools/openapi-generator

[REQ] Allow generators to override example creation when no examples are provided in the spec

Open
#8,229 0 comments 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.

We have a custom generator and the examples are used as mock data for testing. By default, if there are no examples provided in the spec, the generator creates examples based on the schema of the response. These automatically created examples aren't desirable to be used in this context.

Describe the solution you'd like

We would like to be able to customise (or, more specifically prevent) the creation of example data when it is not explicitly provided in the spec files.

Describe alternatives you've considered

We currently have a workaround that involves post-hoc filtering of the examples list, but this currently relies on the type of the generated example being the only way that a Map gets added to the list, which doesn't seem very reliable.

Additional context

I have created a draft PR (#8225) with a potential implementation.

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 by reviewing the draft implementation in PR #8225 and trace the generator path that creates examples from response schemas. Confirm how a custom generator can prevent automatic examples when the spec has none, while preserving explicitly provided examples; the existing post-hoc filtering workaround describes the current behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.