Skip to content

@PathVariable with Spring Type Conversion loses @Schema definition with 2.8.15 #3213

@timomantyvaara

Description

@timomantyvaara

Describe the bug
After upgrading to 2.8.15, the generated OpenAPI specification is missing properties defined with @Schema for custom classes used as path variables. Worked with 2.8.14.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    3.5.10
  • What modules and versions of springdoc-openapi are you using?
    springdoc-openapi-starter-webmvc-ui 2.8.15
    springdoc-openapi-starter-common 2.8.15
  • Actual json
...
  "parameters": [
    {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
        "type": "string"
      }
    }
  ],
...
  • Expected json
...
  "parameters": [
    {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
        "type": "string",
        "format": "uuid",
        "description": "Unique item identifier",
        "example": "9d9d46e5-d41c-4774-885d-8e9dbc67735c"
      }
    }
  ],
...
  • Sample code
@RestController
@RequestMapping("/api/demo")
public class DemoController {

    @GetMapping("/items/{id}")
    public String getItems(@PathVariable ItemId id) {
        return id.value().toString();
    }
}
@Schema(
        type = "uuid",
        description = "Unique item identifier",
        example = "9d9d46e5-d41c-4774-885d-8e9dbc67735c")
public record ItemId(UUID value) {

    public static ItemId fromString(String uuid) {
        return new ItemId(UUID.fromString(uuid));
    }
}
@Component
public class ItemIdConverter implements Converter<String, ItemId> {

    @Override
    public ItemId convert(String source) {
        return ItemId.fromString(source);
    }
}

Expected behavior
@Schema properties are present in the generated spec.

Additional context
Minimal reproducible example: https://github.com/timomantyvaara/springdoc-pathvariable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions