Skip to content

PathApiVersionResolver registered before MediaTypeParamApiVersionResolver in auto-configuration #49800

@srowatt

Description

@srowatt

Component: WebMvcAutoConfiguration.configureApiVersioningUse()

Issue: PathApiVersionResolver never returns null (as stated in its own Javadoc), so any resolvers added after it in the list are unreachable. Currently the media-type parameter resolver is added after the path-segment resolver.

Fix: Move map.from(use::getPathSegment).to(configurer::usePathSegment) to the end of the method, after the media-type parameter registration.

The following config will show the issue when the request is trying to use the media type to supply the API Version. Instead of trying the media type param resolver is tries the path resolver and then ends before trying the media type param resolve.

spring:
  mvc:   
    api-version:
      supported:
        - "1.0"
      use:
        header: "X-API-Version"
        query-parameter: "api-version"
        media-type-parameter:
          "[application/json]": "version"
          "[application/vnd.resource+json]": "version"
        path-segment: 0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions