SpringDoc-儿童课程没有添加到Swagger Spec Schema
我正在使用Spring-boot v2.6.7和Springdoc v1.6.8。以下是对象建模。我添加了一个端点,该端点将课程作为响应返回。我希望Swagger Spec会生成课程类型,而英语的孩子类型也有一个 itemport 字段字段,这是CourseItem的超级文字,并且有一个子类型,其中包括文件夹,课程,课程,课程,课程和测试。我希望Swagger规格包括所有子类型的适当架构定义。
package com.example.springdocdemo.domain
import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
import io.swagger.v3.oas.annotations.media.Schema
import java.util.UUID
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@JsonSubTypes(
value = [
JsonSubTypes.Type(value = EnglishCourse::class, name = "EnglishCourse")
]
)
abstract class Course {
abstract val id: UUID
abstract val name: String
abstract val code: String
}
class EnglishCourse(
val items: List<CourseItem>,
override val id: UUID,
override val code: String,
override val name: String,
) : Course()
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@JsonSubTypes(
value = [
JsonSubTypes.Type(value = Folder::class, name = "FOLDER"),
JsonSubTypes.Type(value = Lesson::class, name = "LESSON"),
JsonSubTypes.Type(value = Test::class, name = "TEST")
]
)
@Schema(discriminatorProperty = "type", allOf = [Folder::class, Lesson::class, Test::class])
interface CourseItem {
val type: CourseItemType
val id: UUID
}
@Schema
class Folder(
val items: List<CourseItem>,
override val id: UUID,
override val type: CourseItemType,
) : CourseItem {
fun items() = println(items)
}
class Lesson(
val name: String,
override val id: UUID,
override val type: CourseItemType,
) : CourseItem
class Test(
val name: String,
override val id: UUID,
override val type: CourseItemType,
) : CourseItem
enum class CourseItemType {
Folder, Lesson, Test
}
下面是文件夹类型的架构定义,
"Folder": {
"required": [
"id",
"type"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/CourseItem"
}
]
},
它不包含字段ID和项目。有什么解决方案吗?该代码可以在此处找到: https://github.com/bhaveshssppringdoc-springdoc-sissue-springdoc-sissue
I'm using spring-boot v2.6.7 and springdoc v1.6.8. Below is the object modeling. I have added one endpoint which returns the Course as the response. I am expecting swagger spec to generate the types for the Course and the Child type which is EnglishCourse also there's an items field on EnglishCourse which is supertype of CourseItem and there are subtypes for it which are Folder, Lesson, and Test. I expect swagger spec to include a proper schema definition for all the subtypes.
package com.example.springdocdemo.domain
import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
import io.swagger.v3.oas.annotations.media.Schema
import java.util.UUID
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@JsonSubTypes(
value = [
JsonSubTypes.Type(value = EnglishCourse::class, name = "EnglishCourse")
]
)
abstract class Course {
abstract val id: UUID
abstract val name: String
abstract val code: String
}
class EnglishCourse(
val items: List<CourseItem>,
override val id: UUID,
override val code: String,
override val name: String,
) : Course()
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@JsonSubTypes(
value = [
JsonSubTypes.Type(value = Folder::class, name = "FOLDER"),
JsonSubTypes.Type(value = Lesson::class, name = "LESSON"),
JsonSubTypes.Type(value = Test::class, name = "TEST")
]
)
@Schema(discriminatorProperty = "type", allOf = [Folder::class, Lesson::class, Test::class])
interface CourseItem {
val type: CourseItemType
val id: UUID
}
@Schema
class Folder(
val items: List<CourseItem>,
override val id: UUID,
override val type: CourseItemType,
) : CourseItem {
fun items() = println(items)
}
class Lesson(
val name: String,
override val id: UUID,
override val type: CourseItemType,
) : CourseItem
class Test(
val name: String,
override val id: UUID,
override val type: CourseItemType,
) : CourseItem
enum class CourseItemType {
Folder, Lesson, Test
}
and the below is the schema definition for the Folder type
"Folder": {
"required": [
"id",
"type"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/CourseItem"
}
]
},
It doesn't include fields id and items. Is there any solution for this? The code can be found here: https://github.com/BhaveshSuvalaka/springdoc-issue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许尝试
maybe try