Class PagedModelScanUtils
- java.lang.Object
-
- org.openapitools.codegen.languages.PagedModelScanUtils
-
public final class PagedModelScanUtils extends Object
Language-agnostic utility for detecting OpenAPI schemas that represent paginated responses (SpringPagedModel-like DTOs) and should be substituted withorg.springframework.data.web.PagedModel<T>during code generation.Two structural patterns are recognised:
- Flat-object form — a plain
type: objectwith acontentarray property and a separate property whose$refpoints to a pagination-metadata schema (e.g.PageMetadata). - allOf form — a schema composed via
allOfwhere one entry is a$refto the pagination-metadata schema and another is an inline object with acontentarray property.
Detection heuristics deliberately avoid name-based matching and only trigger when structural conditions are all met, to minimise false positives.
Used by both
SpringCodegenandKotlinSpringServerCodegen. - Flat-object form — a plain
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPagedModelScanUtils.DetectedPagedModelCarries the result of a single detected paged-model schema.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisPaginationSchema(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.static Map<String,PagedModelScanUtils.DetectedPagedModel>scanPagedModels(io.swagger.v3.oas.models.OpenAPI openAPI)Scans all named schemas inopenAPI.components.schemasand returns those that match the paged-model pattern.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 applyingtoModelNameto every schema name.
-
-
-
Method Detail
-
scanPagedModels
public static Map<String,PagedModelScanUtils.DetectedPagedModel> scanPagedModels(io.swagger.v3.oas.models.OpenAPI openAPI)
Scans all named schemas inopenAPI.components.schemasand 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 ifcomponents/schemasis 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 applyingtoModelNameto 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,objskeys). This ensures correctness whenmodelNameSuffix,modelNamePrefix,schemaMapping, ormodelNameMappingare active.itemSchemaNameinside eachPagedModelScanUtils.DetectedPagedModelis intentionally left as the raw spec name because every call site already passes it throughtoModelName()at the point of use.- Parameters:
openAPI- the parsed OpenAPI documenttoModelName- name-transformation function supplied by the generator (typicallythis::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.
-
-