OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] [spring] Examples are not being generated correctly - MIME type example not yet supported

Open
#16,595 3 comments 1 reaction 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 called Passenger as a part of my RequestBody, which has following example:

       Passenger:
            type: object
            additionalProperties: false
            description: |
                Minimal specification of a passenger.
            required:
                - externalRef
                - passengerType
            properties:
                externalRef:
                    description: |
                        A stable reference to a passenger from the caller system.
                        When received in the request, it must be returned in the response.
                    type: string
                    nullable: false
                    example: passenger1
                passengerType:
                    $ref: '#/components/schemas/PassengerType'
                dateOfBirth:
                    type: string
                    format: date
                    nullable: true
                age:
                    description: |
                        Age of the passenger at the date of travel. Less stable than the date of birth.
                    type: integer
                    format: int32
                    minimum: 0
                    exclusiveMinimum: true
                    nullable: true
                contactDetails:
                    $ref: '#/components/schemas/ContactDetails'
            example:
                externalRef: passenger1
                passengerType: PERSON
                dateOfBirth: 2001-01-01
                contactDetails:
                    firstName: Name
                    lastName: Lastname
                    eMail: name@test.com
                    preferredLanguage: en

After generating endpoints, examples are nowhere to be found, and after calling /v3/api-docs I'm geeting this:

image

So example values for ContactDeatils are being taken from Warning part

        Warning:
            type: object
            additionalProperties: false
            description: |
                This element can be used to pass non-blocking information or events.
                It is inspired on the JSON Problem structure.
            required:
                - type
            properties:
                type:
                    description: |
                        An absolute URI that identifies the warning type. When dereferenced,
                        it SHOULD provide human-readable documentation for the problem type
                        (e.g., using HTML).
                    type: string
                    format: uri
                    nullable: false
                    default: 'about:blank'
                    example: https://example.com/warns/price-updated
                detail:
                    description: |
                        A human readable explanation specific to this occurrence of the
                        warning.
                    type: string
                    nullable: true
                    example: The price of the given offer part has been updated during the booking operation

And in response from /v3/api-docs this looks like default example for all JsonNullableString:

               "JsonNullableString": {
   			"type": "object",
   			"properties": {
   				"present": {
   					"type": "boolean"
   				}
   			},
   			"description": "A human readable explanation specific to this occurrence of the warning. ",
   			"example": "The price of the given offer part has been updated during the booking operation"
   		}
openapi-generator version

6.2.1

expected output

when checking my source yaml file, examples look like this:
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

Start by reproducing the issue with the supplied Passenger, ContactDetails, and Warning schemas, then inspect the Java Spring example-generation path and generated /v3/api-docs output. Done means the Passenger and ContactDetails examples are preserved and the output no longer substitutes Warning or JsonNullableString example values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.