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

Field Name Collision and incorrect Binding of Boolean Fields When Using isX in a data class #42221

Closed
moalshak opened this issue Jul 30, 2024 · 2 comments · Fixed by #41037
Closed
Labels
area/swagger-ui kind/bug Something isn't working
Milestone

Comments

@moalshak
Copy link

moalshak commented Jul 30, 2024

Describe the bug

In the swagger-ui schema generated for the /test/b endpoint, both isBoolean and boolean fields appear in the schema, even though only isBoolean should be present. This can cause confusion and unexpected behavior, such as setting one field inadvertently setting the other.

image

Expected behavior

Only isBoolean should be present

Actual behavior

The boolean field appears out of nowhere

How to Reproduce?

  1. Make a new project
  2. Create a Resource
  3. Create a datacalss with a boolean field with the name isSomething
  4. Run the application
  5. Visit the swagger UI
import com.fasterxml.jackson.annotation.JsonProperty
import jakarta.ws.rs.Consumes
import jakarta.ws.rs.GET
import jakarta.ws.rs.POST
import jakarta.ws.rs.Path
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType

@Path("/test")
class ExampleResource {

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/a")
    fun a(isBoolean: Boolean): String {
        return isBoolean.toString()
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/b")
    fun b(isBoolean: IsBooleanDataClass): String {
        return isBoolean.toString()
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/c")
    fun c(boolean: BooleanDataClass): String {
        return boolean.toString()
    }
}

data class IsBooleanDataClass(
    @JsonProperty("isBoolean")
    val isBoolean: Boolean)
data class BooleanDataClass(
    @JsonProperty("boolean")
    val boolean: Boolean)

Output of uname -a or ver

Ubuntu

Output of java -version

17

Quarkus version or git rev

3.12.3

Build tool (ie. output of mvnw --version or gradlew --version)

8.9

Additional information

No response

@moalshak moalshak added the kind/bug Something isn't working label Jul 30, 2024
Copy link

quarkus-bot bot commented Jul 30, 2024

/cc @MikeEdgar (swagger-ui), @phillip-kruger (swagger-ui)

@phillip-kruger
Copy link
Member

Thanks @MikeEdgar !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/swagger-ui kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants