Skip to content

[BUG] [kotlin-spring] sealed interfaces not supported by spring-declarative-http-interface #23548

@tempacc21

Description

@tempacc21

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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
openapi-generator version

latest

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: test
  description: examples
  version: 1.0.0
servers:
  - url: 'https'
paths:
  /users/{id}:
    get:
      operationId: getUser
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
      responses:
        "200":
          description: User found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserResponse'
        "400":
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    UserResponse:
      properties:
        name:
          type: string
    ErrorResponse:
      properties:
        feilmelding:
          type: string

Generates

@Validated
interface DefaultApi {

    @HttpExchange(
        // "/users/{id}"
        url = PATH_GET_USER,
        method = "GET"
    )
    fun getUser(
        @Parameter(description = "", required = true) @PathVariable("id") id: kotlin.Int
    ): ResponseEntity<UserResponse>


    companion object {
        //for your own safety never directly reuse these path definitions in tests
        const val BASE_PATH: String = ""
        const val PATH_GET_USER: String = "/users/{id}"
    }
}


package no.test.examples.models

/**
 * Sealed interface for all possible responses from getUser
 */
sealed interface GetUserResponse

data class UserResponse(

    @Schema(example = "null", description = "")
    @get:JsonProperty("name") val name: kotlin.String? = null
) : GetUserResponse {

}

ResponseType should be GetUserResponse, not UserResponse

Suggest a fix

I'll make a pr

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