Skip to content

[BUG][Kotlin][Spring] When using interfaceOnly, Spring Boot 3 needs @RestController annotation at api interface #19156

@pstorch

Description

@pstorch

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

When using interfaceOnly generation, Spring Boot 3 needs @RestController annotation at api interface.

Sometimes it works without, but Spring wraps your Controller class in certain situations within a dynamic Proxy (e.g. when using security). Then your controller is not found resulting in a 404 error.

To fix this, the API Interface needs the @RestController annotation.

openapi-generator version

7.7.0

Generation Details
openApiGenerate {
    generatorName = "kotlin-spring"
    inputSpec = "$projectDir/src/main/resources/static/openapi.yaml"
    apiPackage = "com.example.adapter.web.api"
    modelPackage = "com.example.adapter.web.model"
    modelNameSuffix = "Dto"
    cleanupOutput = true
    configOptions.set(
        mapOf(
            "sourceFolder" to "",
            "useTags" to "true",
            "interfaceOnly" to "false",
            "delegatePattern" to "false",
            "documentationProvider" to "none",
            "useBeanValidation" to "true",
            "useSpringBoot3" to "true",
            "enumPropertyNaming" to "UPPERCASE",
            "requestMappingMode" to "none",
            "skipDefaultInterface" to "true",
        )
    )
}

Steps to reproduce

Generate an API with Kotlin Spring with interfaceOnly set to true, then the interfaces only have the @Validated annotation, but missing the @RestController annotation.

Related issues/PRs

There is a similar issue for the Java Spring generator: #18403

Suggest a fix

Add @RestController annotation at api interface.

I'll send a PR soon.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions