Skip to content

springdoc does not respect @field:Schema(enumAsRef = true) on a kotlin data class property #3016

Closed
@damiankaplon

Description

@damiankaplon

Good morning, evening!

Having

@RestController
class HelloController {

	@GetMapping("/hello")
	fun hello() = Response(status = Response.Status.SUCCESS)
}

data class Response(@field:Schema(enumAsRef = true) val status: Status) {
	enum class Status {
		SUCCESS,
		ERROR
	}
}

generates response schema ⬇ :

"schemas":{"Response":{"type":"object","properties":{"status":{"type":"string","enum":["SUCCESS","ERROR"]}}}}

I expected ⬇ :

"schemas":{"Response":{"type":"object","properties":{"status":{"$ref":"#/components/schemas/Status"}}},"Status":{"type":"string","enum":["SUCCESS","ERROR"]}}}

It can be achieved annotating an enum class with Schema(enumAsRef = true) but I'd prefer to annotate a data class property instead) 🙏🏼

Here is a minimal, reproducible example

Versions:

                         <groupId>org.springframework.boot</groupId>
		        <artifactId>spring-boot-starter-parent</artifactId>
		        <version>3.5.0</version>

			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
			<version>2.8.0</version>

			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-starter-common</artifactId>
			<version>2.8.0</version>

	                 <groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-maven-plugin</artifactId>
			<version>1.4</version>

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions