Class PagedModelScanUtils


  • public final class PagedModelScanUtils
    extends Object
    Language-agnostic utility for detecting OpenAPI schemas that represent paginated responses (Spring PagedModel-like DTOs) and should be substituted with org.springframework.data.web.PagedModel<T> during code generation.

    Two structural patterns are recognised:

    1. Flat-object form — a plain type: object with a content array property and a separate property whose $ref points to a pagination-metadata schema (e.g. PageMetadata).
    2. allOf form — a schema composed via allOf where one entry is a $ref to the pagination-metadata schema and another is an inline object with a content array property.

    Detection heuristics deliberately avoid name-based matching and only trigger when structural conditions are all met, to minimise false positives.

    Used by both SpringCodegen and KotlinSpringServerCodegen.

    • Method Detail

      • scanPagedModels

        public static Map<String,​PagedModelScanUtils.DetectedPagedModel> scanPagedModels​(io.swagger.v3.oas.models.OpenAPI openAPI)
        Scans all named schemas in openAPI.components.schemas and returns those that match the paged-model pattern.
        Parameters:
        openAPI - the parsed OpenAPI document
        Returns:
        map from schema name to PagedModelScanUtils.DetectedPagedModel; empty if none found or if components / schemas is absent
      • isPaginationSchema

        public static boolean isPaginationSchema​(io.swagger.v3.oas.models.media.Schema<?> schema)
        Returns true if the given schema looks like a pagination-metadata schema.

        The heuristic checks that at least 2 of the well-known field names (size, number, page, totalElements, totalPages) are present as direct properties.