Skip to content

Path variable mapped improperly in swagger-ui #2028

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

Closed
matios13 opened this issue Jan 2, 2023 · 9 comments
Closed

Path variable mapped improperly in swagger-ui #2028

matios13 opened this issue Jan 2, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@matios13
Copy link

matios13 commented Jan 2, 2023

Describe the bug

I have simple controller in Kotlin

    @Operation(summary = "Get company details", description = "Get company details")
    fun getCompanyDetails(@PathVariable companyId: Long): ResponseEntity<CompanyDTO> {
        val company = companyService.getCompanyByIdOrException(companyId)
        return ResponseEntity.ok(company.toDto())
    }

After upgrading to Spring-boot 3.0.1 and springdoc-openapi 2.0.2
I see arg0 in swagger ui rather than companyId in the ui

image

And when trying it out i get 404:

  "message": "Failed to convert value of type 'java.lang.String' to required type 'long'; For input string: \"{companyId}\"",
  "path": "/api/evans-admin/companies/%7BcompanyId%7D/scheme-admins"

as you can see rather than using given value %7BcompanyId%7D string is being used

@singhbaljit
Copy link

I'm seeing the same issue, for both PathVariable and RequestParam.

@singhbaljit
Copy link

singhbaljit commented Jan 5, 2023

This actually looks like an issue with Spring Framework itself. I'm seeing arg0, etc. in Spring logs (i.e. spring-projects/spring-framework#29776). Using the -parameters compiler flag fixed the problem.

@KimDoubleB
Copy link

KimDoubleB commented Jan 15, 2023

It seems that the -parameters option does not solve this problem in Gradle.

  • Environment: Spring boot: 3.0.0, springdoc-openapi (starter webmvc ui): 2.0.2

I set build.gradle as follows.

plugins {
    id 'org.springframework.boot' version '3.0.0'
    id 'io.spring.dependency-management' version '1.1.0'
    id 'java'
}

...
  
tasks.withType(JavaCompile) {
    options.compilerArgs.add("-parameters")
}

Instead, the easy way to solve this problem is to clearly define the value (or name) of the @PathVariable annotation.

    @Operation(summary = "Get company details", description = "Get company details")
    fun getCompanyDetails(@PathVariable(value = "companyId") companyId: Long): ResponseEntity<CompanyDTO> {
        val company = companyService.getCompanyByIdOrException(companyId)
        return ResponseEntity.ok(company.toDto())
    }

In my application, there was the same issue when MutlipartFile was received as @RequestParam, and in this case, it was solved by clearly writing annoation value (or name).

There seems to be a problem that the current library cannot read this value.

@vojkny
Copy link

vojkny commented Jan 18, 2023

I guess this is the same issue as #2036

@bnasslahsen bnasslahsen added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Feb 4, 2023
@bnasslahsen
Copy link
Collaborator

bnasslahsen commented Feb 5, 2023

@matios13,

You might need to use -parameters.
I am adding an enhancement.
Please do not hesitate to share if this fixes the issue.

@vojkny
Copy link

vojkny commented Feb 16, 2023

Can you 🙏 release a new version with this fix? Can you specify details of You might need to use -parameters? This worked correctly until now with no -parameters field.

@bnasslahsen
Copy link
Collaborator

bnasslahsen commented Feb 16, 2023

@knyttl,

The release would be at the latest, by the end of this month. You can already do your tests with the latest SNAPSHOT.
The explanation of the might need to use -parameters, is related to the deprecation of LocalVariableTableParameterNameDiscoverer with spring-boot 3:

And in the new Default implementation is now:

@vojkny
Copy link

vojkny commented Feb 20, 2023

Hi, would you be able to release earlier? The sonatype snapshot repo is down today (returns 504) and we cannot build at all :/

@lukago
Copy link

lukago commented Aug 13, 2024

@bnasslahsen
In latest version it is still required to use -parameters compiler flag for proper mapping. It is also mentioned in docs.

Is this correct behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants