Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to determine if it is a Kotlin type #2556

Closed
mymx2 opened this issue Apr 1, 2024 · 4 comments
Closed

Unable to determine if it is a Kotlin type #2556

mymx2 opened this issue Apr 1, 2024 · 4 comments
Labels
invalid This doesn't seem right

Comments

@mymx2
Copy link

mymx2 commented Apr 1, 2024

Unable to determine if it is a Kotlin type

  • method: SpringDocKotlinConfiguration.nullableKotlinRequestParameterCustomizer
  • lineNum: 78
    image

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    • 3.2.4
  • What modules and versions of springdoc-openapi are you using?
    • 2.4.0
  • What is the actual and the expected result using OpenAPI Description (yml or json)?
    • kotlin type isMarkedNullable
  • Provide with a sample code (HelloController) or Test that reproduces the problem
interface AdminSysNoticePage {

  @Operation(summary = "adminSysNoticePage", description = "adminSysNoticePage")
  @GetMapping("adminSysNoticePage")
  fun adminSysNoticePage(
    @Validated request: AdminSysNoticePageRequest
  ): AdminSysNoticePageResponse
}

@Schema(description = "AdminSysNoticePageRequest")
data class AdminSysNoticePageRequest(

  @field:Schema(description = "id not required", example = "")
  var id: Long? = null,

  @field:Schema(description = "noticeTitle is required", example = "")
  var noticeTitle: String,
)

@Schema(description = " AdminSysNoticePageResponse")
data class AdminSysNoticePageResponse(

  @field:Schema(description = "id is required", example = "")
  var id: Long,

  @field:Schema(description = "updateBy is not required", example = "")
  var updateBy: String? = null,
)

Screenshots

  • wrong: KotlinDetector.isKotlinType(methodParameter.parameterType)
    image

  • right: KotlinDetector.isKotlinType(methodParameter.containingClass)
    image

  • fix: KotlinDetector.isKotlinType(methodParameter.containingClass)
    image

is this fix code right?

Additional context
id dont know what fix use methodParameter.toKParameter() ?

@bnasslahsen
Copy link
Collaborator

@mymx2,

See the follwing tests:

class DemoRequest (
@field:Schema(required = true, defaultValue = "a default value")
val requiredNullableDefault: String?,
@field:Schema(required = true)
val requiredNullableNoDefault: String?,
@field:Schema(required = true, defaultValue = "a default value")
val requiredNoNullableDefault: String,
@field:Schema(required = true)
val requiredNoNullableNoDefault: String,
@field:Schema(requiredMode = Schema.RequiredMode.REQUIRED, defaultValue = "a default value")
val requiredNullableDefault1: String?,
@field:Schema(requiredMode = Schema.RequiredMode.REQUIRED)
val requiredNullableNoDefault1: String?,
@field:Schema(requiredMode = Schema.RequiredMode.REQUIRED, defaultValue = "a default value")
val requiredNoNullableDefault1: String,
@field:Schema(requiredMode = Schema.RequiredMode.REQUIRED)
val requiredNoNullableNoDefault1: String,
@field:Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED, defaultValue = "a default value")
val noRequiredNullableDefault2: String?,
@field:Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)
val noRequiredNullableNoDefault2: String?,
@field:Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED, defaultValue = "a default value")
val noRequiredNoNullableDefault2: String,
@field:Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)
val noRequiredNoNullableNoDefault2: String,
@field:Schema(defaultValue = "a default value")
val noRequiredNullableDefault: String?,
@field:Schema
val noRequiredNullableNoDefault: String?,
@field:Schema(defaultValue = "a default value")
val noRequiredNoNullableDefault: String,
@field:Schema
val noRequiredNoNullableNoDefault: String,
)

Tests are following the test cases described here:

If you see any case, not respected, make sure you update the test and we can consider it.

@bnasslahsen bnasslahsen added the invalid This doesn't seem right label Apr 1, 2024
@codespearhead
Copy link
Contributor

codespearhead commented Apr 4, 2024

@mymx2 Try using JDK 17, because JDK 21 isn't yet supported as per #2442 .

@mymx2
Copy link
Author

mymx2 commented Apr 4, 2024

@mymx2 Try using JDK 17, because JDK 21 isn't yet supported as per #2442 .

i try add more cases...
image
more than:
image
this cases not include @Parameter annotaion

@codespearhead
Copy link
Contributor

I see.

I suggest forking this repository, updating the test suite so that there are failing tests and creating a draft PR linked to this issue, so we can take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants