OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Java] [Spring] Field name 'example' as array generates wrong code

Open
#14,810 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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:

image

How the api file should be generated:

image

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

image

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.