Class SpringPageableScanUtils

    • Constructor Detail

      • SpringPageableScanUtils

        public SpringPageableScanUtils()
    • Method Detail

      • getAutoPaginationModeEnumValues

        public static Map<String,​String> getAutoPaginationModeEnumValues()
        Returns the accepted autoXSpringPaginated option values and their descriptions.
      • willBePageable

        public static boolean willBePageable​(io.swagger.v3.oas.models.Operation operation,
                                             SpringPageableScanUtils.AutoPaginationMode autoPaginationMode)
        Returns true if the given operation will have a Pageable parameter injected — either because it has x-spring-paginated: true explicitly, or because autoPaginationMode is not SpringPageableScanUtils.AutoPaginationMode.NONE and the operation has all of that mode's required pagination query parameters.
      • willBePageable

        public static boolean willBePageable​(io.swagger.v3.oas.models.OpenAPI openAPI,
                                             io.swagger.v3.oas.models.Operation operation,
                                             SpringPageableScanUtils.AutoPaginationMode autoPaginationMode)
        Returns true if the given operation will have a Pageable parameter injected, resolving component parameter references against the supplied OpenAPI document.
      • getXSpringPaginated

        public static Boolean getXSpringPaginated​(io.swagger.v3.oas.models.Operation operation)
        Returns the resolved `x-spring-paginated` flag.
        Returns:
        `Boolean.TRUE`/`Boolean.FALSE` when explicitly set, otherwise `null`
      • applyAutoXSpringPaginatedIfNeeded

        public static boolean applyAutoXSpringPaginatedIfNeeded​(io.swagger.v3.oas.models.Operation operation,
                                                                SpringPageableScanUtils.AutoPaginationMode autoPaginationMode)
        Auto-detects Pageable pagination query parameters and, when detected, mutates the operation by setting x-spring-paginated: true on its vendor extensions.

        Detection is delegated to willBePageable(OpenAPI, Operation, AutoPaginationMode). If the operation is already explicitly flagged (x-spring-paginated: true/false) this method is a read-only pass-through — it returns the explicit value without mutating extensions. Only auto-detected operations (those whose flag was null) have the extension written.

        This method centralises the "detect + mutate" logic shared by both SpringCodegen and KotlinSpringServerCodegen inside their fromOperation overrides. It must be called before super.fromOperation() so that the base codegen can pick up the extension when populating CodegenOperation.vendorExtensions.

        Parameters:
        operation - the raw OpenAPI Operation to inspect (and possibly mutate)
        autoPaginationMode - the auto-detection mode for this generator
        Returns:
        true if the operation is (or was just marked as) paginated
      • applyAutoXSpringPaginatedIfNeeded

        public static boolean applyAutoXSpringPaginatedIfNeeded​(io.swagger.v3.oas.models.OpenAPI openAPI,
                                                                io.swagger.v3.oas.models.Operation operation,
                                                                SpringPageableScanUtils.AutoPaginationMode autoPaginationMode)
        Auto-detects pagination parameters after resolving component parameter references against the supplied OpenAPI document.
        Parameters:
        openAPI - the OpenAPI document used to resolve parameter references
        operation - the raw OpenAPI Operation to inspect (and possibly mutate)
        autoPaginationMode - the auto-detection mode for this generator
        Returns:
        true if the operation is (or was just marked as) paginated
      • removePageableQueryParams

        public static void removePageableQueryParams​(CodegenOperation codegenOperation)
        Removes the three Spring Data Web default pagination query parameters (page, size, sort) from the given codegen operation's parameter lists.

        When an operation is marked with x-spring-paginated, Spring injects a single org.springframework.data.domain.Pageable parameter that internally handles page, size, and sort. The individual query parameters must therefore be removed from the generated method signature.

        Callers are responsible for ensuring this is only invoked for server-side library configurations (spring-boot) where Pageable injection actually takes place.

        Parameters:
        codegenOperation - the operation whose parameter lists should be pruned
      • applyPageableAnnotations

        public static void applyPageableAnnotations​(CodegenOperation codegenOperation,
                                                    boolean generatePageableConstraintValidation,
                                                    boolean useBeanValidation,
                                                    Map<String,​SpringPageableScanUtils.PageableConstraintsData> pageableConstraintsRegistry,
                                                    boolean generateSortValidation,
                                                    Map<String,​List<String>> sortValidationEnums,
                                                    Map<String,​SpringPageableScanUtils.PageableDefaultsData> pageableDefaultsRegistry,
                                                    SpringPageableScanUtils.AnnotationSyntax syntax)
        Builds and attaches the pageable-parameter annotations (@ValidPageable, @ValidSort, @PageableDefault, @SortDefault.SortDefaults) to the given codegen operation.

        The annotations and their imports are only added when the relevant feature flags (generatePageableConstraintValidation, generateSortValidation) are enabled and a matching entry exists in the corresponding registry for this operation. The result is stored under the x-pageable-extra-annotation vendor extension.

        Language-specific differences in annotation array syntax (Java {...} vs Kotlin [...]) are handled by the syntax parameter. SpringDoc-specific import additions remain in each calling codegen class since they differ between Java (ParameterObject) and Kotlin (PageableAsQueryParam + x-operation-extra-annotation mutation).

        Parameters:
        codegenOperation - the operation to annotate
        generatePageableConstraintValidation - whether to emit @ValidPageable
        useBeanValidation - whether bean validation is active
        pageableConstraintsRegistry - per-operationId constraint data
        generateSortValidation - whether to emit @ValidSort
        sortValidationEnums - per-operationId allowed sort values
        pageableDefaultsRegistry - per-operationId default page/size/sort data
        syntax - target language annotation syntax
      • applySpringDocPageableAnnotation

        public static void applySpringDocPageableAnnotation​(CodegenOperation codegenOperation,
                                                            SpringPageableScanUtils.AnnotationSyntax syntax,
                                                            boolean isSpringDoc)
        Applies SpringDoc-specific annotation handling for a pageable operation.

        When isSpringDoc is true:

        • Java: adds the ParameterObject import, which instructs SpringDoc to expose the individual pageable query parameters in the OpenAPI UI.
        • Kotlin: adds the PageableAsQueryParam import and prepends @PageableAsQueryParam to the operation's x-operation-extra-annotation vendor extension so the Mustache template renders it on the generated controller method.

        When isSpringDoc is false this method is a no-op.

        Parameters:
        codegenOperation - the operation to annotate
        syntax - target language annotation syntax
        isSpringDoc - whether the active documentation provider is SpringDoc
      • scanSortValidationEnums

        public static Map<String,​List<String>> scanSortValidationEnums​(io.swagger.v3.oas.models.OpenAPI openAPI,
                                                                             SpringPageableScanUtils.AutoPaginationMode autoPaginationMode)
        Scans all pageable operations for a sort parameter with enum values.
        Returns:
        map from operationId to list of allowed sort strings (e.g. ["id,asc", "id,desc"])