Skip to content

[REQ][kotlin-spring] Support Spring 7 API versioning #25845

Backlog

Description

@msamborski-orbis

Is your feature request related to a problem? Please describe.

The Java spring server generator supports Spring Framework 7 API versioning through springApiVersion and the operation-level x-spring-api-version extension, introduced by #22028 for #22027. The kotlin-spring server generator does not currently provide the equivalent behavior.

Checked against current master, commit ad0d57907d3a96a3c450a9b0c1ff6e8c623a5e78 (7.28.0). Kotlin already supports Spring Boot 4, but its generator options, supported extensions, and server @RequestMapping templates do not include API versioning. Searches of existing issues and pull requests did not find a Kotlin Spring request for this feature.

Describe the solution you'd like

Bring the existing Java Spring API-versioning feature to the spring-boot server library of kotlin-spring:

  • Add the optional string configuration option springApiVersion as the default operation mapping version.
  • Support the existing operation-level x-spring-api-version extension.
  • Preserve Java's precedence: an operation value overrides the global default; an explicitly empty string suppresses the default; an operation extension also works without a global option.
  • Generate the optional version attribute on @RequestMapping for normal controllers, interface-only output, and delegate mode, including reactive generation.
  • Leave unversioned generation unchanged.
  • Document the Spring Framework 7+ requirement and use Spring Boot 4 for a generated standalone application. Version resolver configuration remains application-owned.

Example generator configuration:

generatorName: kotlin-spring
library: spring-boot
additionalProperties:
  useSpringBoot4: true
  springApiVersion: "1.0"

An operation may override or suppress that default:

paths:
  /versioned:
    get:
      operationId: getVersioned
      x-spring-api-version: "2+"
      responses:
        '200':
          description: OK
  /unversioned:
    get:
      operationId: getUnversioned
      x-spring-api-version: ""
      responses:
        '200':
          description: OK

The first operation should generate @RequestMapping(..., version = "2+"); the second should omit the version attribute.

Describe alternatives you've considered

Customizing kotlin-spring/api.mustache and apiInterface.mustache using -t. This requires maintaining local templates and does not provide the global-default processing or discoverable generator option already available for Java Spring.

Additional context

I intend to contribute this as an opt-in parity change with regression tests, generated documentation, and a Spring Boot 4 sample. Header/query mapping constraints through x-version-param and declarative HTTP client versioning are outside this change.

Related: #22027, #22028.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions