OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java] [Spring] Field name 'example' as array generates wrong code
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I have a schema named CategoryDto that has a property called visibility. I added an example to this visibility with the value of a list of strings. When executing openApiValidate everything goes well, but when accessing the generated api class, the string with the example inserted in the example property is incorrect and generating errors, as in the image below:
CategoryDto:
type: object
properties:
id:
type: integer
format: int32
example: 10
description: Created category ID.
visibility:
type: string
example:
- PRIVATE
- PUBLIC
allOf:
- $ref: "#/components/schemas/CreateCategoryDto"
required:
- id
- visibility
How the api file is generated:

How the api file should be generated:

openapi-generator version
V6.3.0
Steps to reproduce
Just create any schema where the value of example is an array of strings.
Suggest a fix

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
Reproduce the Java/Spring generation using the CategoryDto YAML in the issue, focusing on the visibility property's array-valued example. Compare the generated API class with the expected output shown in the report; done means generation succeeds without an invalid example string and produces the intended array representation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100