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
      • scanPagedModels

        public static Map<String,​PagedModelScanUtils.DetectedPagedModel> scanPagedModels​(io.swagger.v3.oas.models.OpenAPI openAPI,
                                                                                               UnaryOperator<String> toModelName)
        Convenience overload that scans for paged-model schemas and immediately re-keys the resulting map by applying toModelName to every schema name.

        Generator classes must use this overload (passing this::toModelName) so that the registry keys match the model-name-processed values used at lookup time (e.g. codegenOperation.returnBaseType, objs keys). This ensures correctness when modelNameSuffix, modelNamePrefix, schemaMapping, or modelNameMapping are active.

        itemSchemaName inside each PagedModelScanUtils.DetectedPagedModel is intentionally left as the raw spec name because every call site already passes it through toModelName() at the point of use.

        Parameters:
        openAPI - the parsed OpenAPI document
        toModelName - name-transformation function supplied by the generator (typically this::toModelName)
        Returns:
        map from transformed schema name to PagedModelScanUtils.DetectedPagedModel
      • isPaginationSchema

        public static boolean isPaginationSchema​(io.swagger.v3.oas.models.media.Schema<?> schema)

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