OpenAPITools / OpenAPITools/openapi-generator

[Question][Kotlin-Spring-CLIENT] Examples are not showing up in nested classes

Open
#20,936 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Project setup:

  • Spring Boot (3.4.3)
  • OpenApi Generator (7.12.0)
  • springdoc-openapi-starter-webmvc-ui (2.8.5)

openapi generator setup:

openApiGenerate {
    generatorName.set("kotlin-spring")
    outputDir.set("${project.layout.buildDirectory.get()}/generated")
    inputSpec.set("$projectDir/src/main/resources/contract.yaml")
    apiPackage.set("generated.api")
    modelPackage.set("generated.model")
    additionalProperties.set(
        mapOf(
            "useBeanValidation" to "true",
            "delegatePattern" to "true",
            "annotationLibrary" to "swagger2",
            "interfaceOnly" to "true",
            "sourceFolder" to "",
            "useResponseEntity" to "true",
            "useSpringBoot3" to "true",
            "schemaExampleValues" to "true"
        )
    )
}

The issue that I'm running into is that I'm unable to get example to show up properly in the openapis definitions page when the class has nested classes in the schema.

For example:

User:
      allOf:
        - $ref: '#/components/schemas/Person'
        - type: object
          properties:
            id:
              type: string
              readOnly: true
            address:
              $ref: "#/components/schemas/Address"

The output on the Openapis definitions screen looks like below

{
  "firstName": "Test",
  "lastName": "Guy",
  "middleName": null,
  "address": null
}

Schema address has been setup properly with examples. When I use swagger editor it parses the example properly. Meaning instead of address values being null I'm able to get complete address object displayed with examples.

Is there something wrong with my setup or is this a default behavior of the Kotlin-Spring generator since it does not support the allOf

Thank you for your help!

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 with contract.yaml and the provided openApiGenerate configuration, then inspect the generated Kotlin-Spring output used by the OpenAPI definitions page. Compare handling of the allOf inheritance and nested Address schema with Swagger Editor. Done means the definitions page renders the nested address example instead of null, or documents the generator limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, openapi, spring, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.