Skip to content

Spring generator uses one-based API page default as zero-based Pageable default #25160

Description

@Pattrigue

After upgrading from 7.24.0 to 7.26.0, the Spring generator adds:

@PageableDefault(page = 1, size = 20)

Our OpenAPI spec defines page with minimum: 1 and default: 1. Spring is configured with:

spring.data.web.pageable.one-indexed-parameters: true

However, @PageableDefault.page is always zero-based. Requests without a page parameter now return the second page instead of the first.

We use x-spring-paginated: true. In 7.24.0, no annotation was generated and Spring’s defaults worked correctly.

Could the generator support one-based pagination, or provide an option to disable generated pagination defaults?

Activity

  1. Picazsoo commented on Oct 8, 2026

    @Picazsoo
    Contributor

    Hello @Pattrigue, thanks for the report. The cause is that the generator copies page.default from the spec straight into @PageableDefault(page = …). That annotation always counts pages from zero, and spring.data.web.pageable.one-indexed-parameters doesn't change it. So with default: 1 you get page index 1, which is the second page.

    Until there's a proper fix (for example, an option to turn off generated pageable defaults or to declare one-based pagination), you can get the 7.24.0 output back by overriding a single template.

    Workaround: override api.mustache via templateDir

    @PageableDefault (along with @SortDefault.SortDefaults, @ValidPageable and @ValidSort) comes from the x-pageable-extra-annotation vendor extension. api.mustache renders it right before the Pageable pageable parameter. Remove that fragment and the parameter is generated as plain final Pageable pageable again, so Spring's own defaults (which follow one-indexed-parameters) apply.

    1. Make a template directory in your project, e.g. src/main/openapi-templates/, and add a file named exactly api.mustache (full content below). Any template you don't override still comes from the built-in set.

    2. Point the generator at it:

    Maven:

    <plugin>
      <groupId>org.openapitools</groupId>
      <artifactId>openapi-generator-maven-plugin</artifactId>
      <version>7.26.0</version>
      <executions>
        <execution>
          <goals><goal>generate</goal></goals>
          <configuration>
            <generatorName>spring</generatorName>
            <templateDirectory>${project.basedir}/src/main/openapi-templates</templateDirectory>
            <!-- ... your existing configuration ... -->
          </configuration>
        </execution>
      </executions>
    </plugin>

    Gradle:

    openApiGenerate {
        generatorName = "spring"
        templateDir = "$projectDir/src/main/openapi-templates"
        // ... your existing configuration ...
    }

    CLI:

    openapi-generator-cli generate -g spring -t src/main/openapi-templates -i api.yaml -o out

    3. The edited api.mustache. The only change from the stock template is in the Pageable parameter line. This fragment was removed:

    -{{#vendorExtensions.x-pageable-extra-annotation}}{{{.}}} {{/vendorExtensions.x-pageable-extra-annotation}}
    Full api.mustache
    /*
     * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}).
     * https://openapi-generator.tech
     * Do not edit the class manually.
     */
    package {{package}};
    
    {{#imports}}import {{import}};
    {{/imports}}
    {{#swagger2AnnotationLibrary}}
    import io.swagger.v3.oas.annotations.ExternalDocumentation;
    import io.swagger.v3.oas.annotations.Operation;
    import io.swagger.v3.oas.annotations.Parameter;
    import io.swagger.v3.oas.annotations.Parameters;
    import io.swagger.v3.oas.annotations.media.ArraySchema;
    import io.swagger.v3.oas.annotations.media.Content;
    import io.swagger.v3.oas.annotations.media.Schema;
    import io.swagger.v3.oas.annotations.responses.ApiResponse;
    import io.swagger.v3.oas.annotations.security.SecurityRequirement;
    import io.swagger.v3.oas.annotations.tags.Tag;
    import io.swagger.v3.oas.annotations.enums.ParameterIn;
    import io.swagger.v3.oas.annotations.media.ExampleObject;
    {{/swagger2AnnotationLibrary}}
    {{#swagger1AnnotationLibrary}}
    import io.swagger.annotations.*;
    {{/swagger1AnnotationLibrary}}
    {{^isDelegate}}
    {{#jdk8-default-interface}}
    {{#virtualService}}
    import io.virtualan.annotation.ApiVirtual;
    import io.virtualan.annotation.VirtualService;
    {{/virtualService}}
    import org.springframework.http.HttpStatus;
    import org.springframework.http.MediaType;
    {{/jdk8-default-interface}}
    {{/isDelegate}}
    {{^useResponseEntity}}
    import org.springframework.http.HttpStatus;
    {{/useResponseEntity}}
    {{#useResponseEntity}}
    import org.springframework.http.ResponseEntity;
    {{/useResponseEntity}}
    {{#useSpringSecurityPreAuthorize}}
    import org.springframework.security.access.prepost.PreAuthorize;
    {{/useSpringSecurityPreAuthorize}}
    {{#useBeanValidation}}{{^useSpringBuiltInValidation}}import org.springframework.validation.annotation.Validated;{{/useSpringBuiltInValidation}}{{/useBeanValidation}}
    {{#useSpringController}}
    {{#useResponseEntity}}
    import org.springframework.stereotype.Controller;
    {{/useResponseEntity}}
    {{^useResponseEntity}}
    import org.springframework.web.bind.annotation.RestController;
    {{/useResponseEntity}}
    {{/useSpringController}}
    import org.springframework.web.bind.annotation.*;
    {{#jdk8-default-interface}}
        {{^isDelegate}}
            {{^reactive}}
    import org.springframework.web.context.request.NativeWebRequest;
            {{/reactive}}
        {{/isDelegate}}
    {{/jdk8-default-interface}}
    import org.springframework.web.multipart.MultipartFile;
    {{#includeHttpRequestContext}}
    {{#reactive}}
    import org.springframework.web.server.ServerWebExchange;
    {{/reactive}}
    {{^reactive}}
    import {{javaxPackage}}.servlet.http.HttpServletRequest;
    {{/reactive}}
    {{/includeHttpRequestContext}}
    {{#reactive}}
    import reactor.core.publisher.Flux;
    import reactor.core.publisher.Mono;
    import org.springframework.http.codec.multipart.Part;
    {{/reactive}}
    
    {{#useBeanValidation}}
    import {{javaxPackage}}.validation.Valid;
    import {{javaxPackage}}.validation.constraints.*;
    {{/useBeanValidation}}
    import java.util.List;
    import java.util.Map;
    {{^isDelegate}}
    import java.util.Optional;
    {{/isDelegate}}
    {{#isDelegate}}
    {{#useOptional}}
    import java.util.Optional;
    {{/useOptional}}
    {{/isDelegate}}
    {{#async}}
    import java.util.concurrent.CompletableFuture;
    {{/async}}
    {{#returnSuccessCode}}
    import java.util.concurrent.atomic.AtomicInteger;
    {{/returnSuccessCode}}
    import {{javaxPackage}}.annotation.Generated;
    
    {{>generatedAnnotation}}
    
    {{#useBeanValidation}}{{^useSpringBuiltInValidation}}@Validated{{/useSpringBuiltInValidation}}{{/useBeanValidation}}
    {{#useSpringController}}
    {{#useResponseEntity}}
    @Controller
    {{/useResponseEntity}}
    {{^useResponseEntity}}
    @RestController
    {{/useResponseEntity}}
    {{/useSpringController}}
    {{#swagger2AnnotationLibrary}}
    @Tag(name = "{{{tagName}}}", description = {{#tagDescription}}"{{{.}}}"{{/tagDescription}}{{^tagDescription}}"the {{{tagName}}} API"{{/tagDescription}})
    {{/swagger2AnnotationLibrary}}
    {{#swagger1AnnotationLibrary}}
    @Api(value = "{{{tagName}}}", description = {{#tagDescription}}"{{{.}}}"{{/tagDescription}}{{^tagDescription}}"the {{{tagName}}} API"{{/tagDescription}})
    {{/swagger1AnnotationLibrary}}
    {{#operations}}
    {{#virtualService}}
    @VirtualService
    {{/virtualService}}
    {{#useRequestMappingOnInterface}}
    {{=<% %>=}}
    @RequestMapping("${openapi.<%title%>.base-path:<%>defaultBasePath%>}")
    <%={{ }}=%>
    {{/useRequestMappingOnInterface}}
    public interface {{classname}} {
    {{#jdk8-default-interface}}
        {{^isDelegate}}
            {{^reactive}}
    
        default Optional<NativeWebRequest> getRequest() {
            return Optional.empty();
        }
            {{/reactive}}
        {{/isDelegate}}
        {{#isDelegate}}
    
        default {{classname}}Delegate getDelegate() {
            return new {{classname}}Delegate() {};
        }
        {{/isDelegate}}
    {{/jdk8-default-interface}}
    {{#operation}}
    
        String PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}} = "{{{path}}}";
        /**
         * {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}}
        {{#notes}}
         * {{.}}
        {{/notes}}
         *
        {{#allParams}}
         * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}
        {{/allParams}}
         * @return {{#responses}}{{message}} (status code {{code}}){{^-last}}
         *         or {{/-last}}{{/responses}}
        {{#isDeprecated}}
         * @deprecated
        {{/isDeprecated}}
        {{#externalDocs}}
         * {{description}}
         * @see <a href="{{url}}">{{summary}} Documentation</a>
        {{/externalDocs}}
         */
        {{#isDeprecated}}
        @Deprecated
        {{/isDeprecated}}
        {{#virtualService}}
        @ApiVirtual
        {{/virtualService}}
        {{#swagger2AnnotationLibrary}}
        @Operation(
            operationId = "{{{operationId}}}",
            {{#summary}}
            summary = "{{{.}}}",
            {{/summary}}
            {{#notes}}
            description = "{{{.}}}",
            {{/notes}}
            {{#isDeprecated}}
            deprecated = true,
            {{/isDeprecated}}
            {{#vendorExtensions.x-tags.size}}
            tags = { {{#vendorExtensions.x-tags}}"{{{tag}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} },
            {{/vendorExtensions.x-tags.size}}
            responses = {
                {{#responses}}
                @ApiResponse(responseCode = {{#isDefault}}"default"{{/isDefault}}{{^isDefault}}"{{{code}}}"{{/isDefault}}, description = "{{{message}}}"{{#baseType}}, content = {
                    {{#produces}}
                    @Content(mediaType = "{{{mediaType}}}", {{#isArray}}array = @ArraySchema({{/isArray}}schema = @Schema(implementation = {{{baseType}}}.class){{#isArray}}){{/isArray}}{{^isJson}}){{^-last}},{{/-last}}{{/isJson}}{{#isJson}}{{^examples.0}}){{^-last}},{{/-last}}{{/examples.0}}{{#examples.0}}, examples = {
                    {{#examples}}
                        @ExampleObject(
                            name = "{{{exampleName}}}",
                            value = "{{{exampleValue}}}"
                        ){{^-last}},{{/-last}}
                    {{/examples}}
                    {{#-last}}
                    })
                    {{/-last}}
                    {{^-last}}
                    }),
                    {{/-last}}{{/examples.0}}{{/isJson}}
                    {{/produces}}
                }{{/baseType}}){{^-last}},{{/-last}}
                {{/responses}}
            }{{#hasAuthMethods}},
            security = {
                {{#authMethods}}
                @SecurityRequirement(name = "{{name}}"{{#scopes.0}}, scopes={ {{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}} }{{/scopes.0}}){{^-last}},{{/-last}}
                {{/authMethods}}
            }{{/hasAuthMethods}}{{#externalDocs}},
            externalDocs = @ExternalDocumentation(description = "{{externalDocs.description}}", url = "{{externalDocs.url}}"){{/externalDocs}}
        )
        {{/swagger2AnnotationLibrary}}
        {{#swagger1AnnotationLibrary}}
        @ApiOperation(
            {{#vendorExtensions.x-tags.size}}
            tags = { {{#vendorExtensions.x-tags}}"{{{tag}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} },
            {{/vendorExtensions.x-tags.size}}
            value = "{{{summary}}}",
            nickname = "{{{operationId}}}",
            notes = "{{{notes}}}"{{#returnBaseType}},
            response = {{{.}}}.class{{/returnBaseType}}{{#returnContainer}},
            responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}},
            authorizations = {
            {{#authMethods}}
            {{#scopes.0}}
                @Authorization(value = "{{name}}", scopes = {
                {{#scopes}}
                    @AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}},{{/-last}}
                {{/scopes}}
                }){{^-last}},{{/-last}}
            {{/scopes.0}}
            {{^scopes.0}}
                @Authorization(value = "{{name}}"){{^-last}},{{/-last}}
            {{/scopes.0}}
            {{/authMethods}} }{{/hasAuthMethods}}
        )
        @ApiResponses({
            {{#responses}}
            @ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}
            {{/responses}}
        })
        {{/swagger1AnnotationLibrary}}
        {{#implicitHeadersParams.0}}
        {{#swagger2AnnotationLibrary}}
        @Parameters({
            {{#implicitHeadersParams}}
            {{>paramDoc}}{{^-last}},{{/-last}}
            {{/implicitHeadersParams}}
        })
        {{/swagger2AnnotationLibrary}}
        {{#swagger1AnnotationLibrary}}
        @ApiImplicitParams({
            {{#implicitHeadersParams}}
            {{>implicitHeader}}{{^-last}},{{/-last}}
            {{/implicitHeadersParams}}
        })
        {{/swagger1AnnotationLibrary}}
        {{/implicitHeadersParams.0}}
        @RequestMapping(
            method = RequestMethod.{{httpMethod}},
            value = {{classname}}.PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}}{{#singleContentTypes}}{{#hasProduces}},
            produces = { {{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }{{/hasProduces}}{{#hasConsumes}},
            consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}},
            produces = { {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }{{/hasProduces}}{{#hasConsumes}},
            consumes = { {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }{{/hasConsumes}}{{/singleContentTypes}}{{#hasVersionHeaders}},
            headers = { {{#vendorExtensions.versionHeaderParamsList}}"{{baseName}}{{#defaultValue}}={{{.}}}{{/defaultValue}}"{{^-last}}, {{/-last}}{{/vendorExtensions.versionHeaderParamsList}} } {{/hasVersionHeaders}}{{#hasVersionQueryParams}},
            params = { {{#vendorExtensions.versionQueryParamsList}}"{{baseName}}{{#defaultValue}}={{{.}}}{{/defaultValue}}"{{^-last}}, {{/-last}}{{/vendorExtensions.versionQueryParamsList}} } {{/hasVersionQueryParams}}{{#vendorExtensions.x-spring-api-version}}{{^empty}},
            version = "{{{vendorExtensions.x-spring-api-version}}}"{{/empty}}{{/vendorExtensions.x-spring-api-version}}
        )
        {{^useResponseEntity}}
        @ResponseStatus({{#springHttpStatus}}{{#responses.0}}{{{code}}}{{/responses.0}}{{/springHttpStatus}})
        {{/useResponseEntity}}
        {{#vendorExtensions.x-operation-extra-annotation}}
        {{{.}}}
        {{/vendorExtensions.x-operation-extra-annotation}}
        {{#vendorExtensions.x-spring-security-pre-authorize}}
        @PreAuthorize("{{{.}}}")
        {{/vendorExtensions.x-spring-security-pre-authorize}}
        {{#vendorExtensions.x-sse}}
        @ResponseBody
        {{/vendorExtensions.x-sse}}
        {{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{>responseType}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}(
            {{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}},
            {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}},
            {{/hasParams}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true){{/swagger2AnnotationLibrary}} final {{#reactive}}ServerWebExchange exchange{{/reactive}}{{^reactive}}HttpServletRequest servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}},
            {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}},{{/includeHttpRequestContext}}{{/hasParams}}{{#springDocDocumentationProvider}}@ParameterObject{{/springDocDocumentationProvider}} final Pageable pageable{{/vendorExtensions.x-spring-paginated}}{{#vendorExtensions.x-spring-provide-args}}{{#-first}}{{#hasParams}},
            {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}},{{/includeHttpRequestContext}}{{^includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}},{{/vendorExtensions.x-spring-paginated}}{{/includeHttpRequestContext}}{{/hasParams}}{{/-first}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true){{/swagger2AnnotationLibrary}} {{{.}}}{{^-last}},
            {{/-last}}{{/vendorExtensions.x-spring-provide-args}}
        ){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
            {{#delegate-method}}
            {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#reactive}}exchange{{/reactive}}{{^reactive}}servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}}{{#vendorExtensions.springProvideArgsNames}}{{#-first}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{^includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}, {{/vendorExtensions.x-spring-paginated}}{{/includeHttpRequestContext}}{{/hasParams}}{{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{/vendorExtensions.springProvideArgsNames}});
        }
    
        // Override this method
        {{#jdk8-default-interface}}default {{/jdk8-default-interface}} {{>responseType}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#reactive}}{{#isArray}}Flux<{{/isArray}}Part{{#isArray}}>{{/isArray}}{{/reactive}}{{^reactive}}{{#isArray}}List<{{/isArray}}MultipartFile{{#isArray}}>{{/isArray}}{{/reactive}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}} final {{#reactive}}ServerWebExchange exchange{{/reactive}}{{^reactive}}HttpServletRequest servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{/hasParams}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}{{#vendorExtensions.springProvideArgsDelegate}}{{#-first}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{^includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}, {{/vendorExtensions.x-spring-paginated}}{{/includeHttpRequestContext}}{{/hasParams}}{{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{/vendorExtensions.springProvideArgsDelegate}}){{#unhandledException}} throws Exception{{/unhandledException}} {
            {{/delegate-method}}
            {{^isDelegate}}
            {{>methodBody}}{{! prevent indent}}
            {{/isDelegate}}
            {{#isDelegate}}
            {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#reactive}}exchange{{/reactive}}{{^reactive}}servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}}{{#vendorExtensions.springProvideArgsNames}}{{#-first}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{^includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}, {{/vendorExtensions.x-spring-paginated}}{{/includeHttpRequestContext}}{{/hasParams}}{{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{/vendorExtensions.springProvideArgsNames}});
            {{/isDelegate}}
        }{{/jdk8-default-interface}}
    
    {{/operation}}
    }
    {{/operations}}

    Notes / caveats

    • Version match: this template is based on the current master copy of JavaSpring/api.mustache. If you're pinned to a different version, the safer option is to take that version's api.mustache and remove only the fragment shown in the diff above.
    • Everything in that extension is dropped: besides @PageableDefault, this also removes @SortDefault.SortDefaults and, if you enabled them, @ValidPageable/@ValidSort. That matches what 7.24.0 generated, but if you rely on any of them, you'll need to handle them another way for now.
    • Size default: without @PageableDefault, the page size comes from spring.data.web.pageable.default-page-size (default 20), not from the spec. Set it there if your spec uses a different value.
    • Leftover import: the org.springframework.data.web.PageableDefault import may still be generated but goes unused. It's harmless.
    • Remove the override after upgrading: a templateDir override hides later changes to that template. Once a fixed version is out, delete the override (or rebase it) so you don't miss future fixes. Thanks for reporting this bug! You are right about the issue. The cause is that the generator copies page.default from the spec straight into @PageableDefault(page = …). That annotation always counts pages from zero, and spring.data.web.pageable.one-indexed-parameters doesn't change it. So with default: 1 you get page index 1, which is the second page.

    Until there's a proper fix (for example, an option to turn off generated pageable defaults or to declare one-based pagination), you can get the 7.24.0 output back by overriding a single template.

    Workaround: override api.mustache via templateDir

    @PageableDefault (along with @SortDefault.SortDefaults, @ValidPageable and @ValidSort) comes from the x-pageable-extra-annotation vendor extension. api.mustache renders it right before the Pageable pageable parameter. Remove that fragment and the parameter is generated as plain final Pageable pageable again, so Spring's own defaults (which follow one-indexed-parameters) apply.

    1. Make a template directory in your project, e.g. src/main/openapi-templates/, and add a file named exactly api.mustache (full content below). Any template you don't override still comes from the built-in set.

    2. Point the generator at it:

    Maven:

    <plugin>
      <groupId>org.openapitools</groupId>
      <artifactId>openapi-generator-maven-plugin</artifactId>
      <version>7.26.0</version>
      <executions>
        <execution>
          <goals><goal>generate</goal></goals>
          <configuration>
            <generatorName>spring</generatorName>
            <templateDirectory>${project.basedir}/src/main/openapi-templates</templateDirectory>
            <!-- ... your existing configuration ... -->
          </configuration>
        </execution>
      </executions>
    </plugin>

    Gradle:

    openApiGenerate {
        generatorName = "spring"
        templateDir = "$projectDir/src/main/openapi-templates"
        // ... your existing configuration ...
    }

    CLI:

    openapi-generator-cli generate -g spring -t src/main/openapi-templates -i api.yaml -o out

    3. The edited api.mustache. The only change from the stock template is in the Pageable parameter line. This fragment was removed:

    -{{#vendorExtensions.x-pageable-extra-annotation}}{{{.}}} {{/vendorExtensions.x-pageable-extra-annotation}}
    Full api.mustache
    /*
     * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}).
     * https://openapi-generator.tech
     * Do not edit the class manually.
     */
    package {{package}};
    
    {{#imports}}import {{import}};
    {{/imports}}
    {{#swagger2AnnotationLibrary}}
    import io.swagger.v3.oas.annotations.ExternalDocumentation;
    import io.swagger.v3.oas.annotations.Operation;
    import io.swagger.v3.oas.annotations.Parameter;
    import io.swagger.v3.oas.annotations.Parameters;
    import io.swagger.v3.oas.annotations.media.ArraySchema;
    import io.swagger.v3.oas.annotations.media.Content;
    import io.swagger.v3.oas.annotations.media.Schema;
    import io.swagger.v3.oas.annotations.responses.ApiResponse;
    import io.swagger.v3.oas.annotations.security.SecurityRequirement;
    import io.swagger.v3.oas.annotations.tags.Tag;
    import io.swagger.v3.oas.annotations.enums.ParameterIn;
    import io.swagger.v3.oas.annotations.media.ExampleObject;
    {{/swagger2AnnotationLibrary}}
    {{#swagger1AnnotationLibrary}}
    import io.swagger.annotations.*;
    {{/swagger1AnnotationLibrary}}
    {{^isDelegate}}
    {{#jdk8-default-interface}}
    {{#virtualService}}
    import io.virtualan.annotation.ApiVirtual;
    import io.virtualan.annotation.VirtualService;
    {{/virtualService}}
    import org.springframework.http.HttpStatus;
    import org.springframework.http.MediaType;
    {{/jdk8-default-interface}}
    {{/isDelegate}}
    {{^useResponseEntity}}
    import org.springframework.http.HttpStatus;
    {{/useResponseEntity}}
    {{#useResponseEntity}}
    import org.springframework.http.ResponseEntity;
    {{/useResponseEntity}}
    {{#useSpringSecurityPreAuthorize}}
    import org.springframework.security.access.prepost.PreAuthorize;
    {{/useSpringSecurityPreAuthorize}}
    {{#useBeanValidation}}{{^useSpringBuiltInValidation}}import org.springframework.validation.annotation.Validated;{{/useSpringBuiltInValidation}}{{/useBeanValidation}}
    {{#useSpringController}}
    {{#useResponseEntity}}
    import org.springframework.stereotype.Controller;
    {{/useResponseEntity}}
    {{^useResponseEntity}}
    import org.springframework.web.bind.annotation.RestController;
    {{/useResponseEntity}}
    {{/useSpringController}}
    import org.springframework.web.bind.annotation.*;
    {{#jdk8-default-interface}}
        {{^isDelegate}}
            {{^reactive}}
    import org.springframework.web.context.request.NativeWebRequest;
            {{/reactive}}
        {{/isDelegate}}
    {{/jdk8-default-interface}}
    import org.springframework.web.multipart.MultipartFile;
    {{#includeHttpRequestContext}}
    {{#reactive}}
    import org.springframework.web.server.ServerWebExchange;
    {{/reactive}}
    {{^reactive}}
    import {{javaxPackage}}.servlet.http.HttpServletRequest;
    {{/reactive}}
    {{/includeHttpRequestContext}}
    {{#reactive}}
    import reactor.core.publisher.Flux;
    import reactor.core.publisher.Mono;
    import org.springframework.http.codec.multipart.Part;
    {{/reactive}}
    
    {{#useBeanValidation}}
    import {{javaxPackage}}.validation.Valid;
    import {{javaxPackage}}.validation.constraints.*;
    {{/useBeanValidation}}
    import java.util.List;
    import java.util.Map;
    {{^isDelegate}}
    import java.util.Optional;
    {{/isDelegate}}
    {{#isDelegate}}
    {{#useOptional}}
    import java.util.Optional;
    {{/useOptional}}
    {{/isDelegate}}
    {{#async}}
    import java.util.concurrent.CompletableFuture;
    {{/async}}
    {{#returnSuccessCode}}
    import java.util.concurrent.atomic.AtomicInteger;
    {{/returnSuccessCode}}
    import {{javaxPackage}}.annotation.Generated;
    
    {{>generatedAnnotation}}
    
    {{#useBeanValidation}}{{^useSpringBuiltInValidation}}@Validated{{/useSpringBuiltInValidation}}{{/useBeanValidation}}
    {{#useSpringController}}
    {{#useResponseEntity}}
    @Controller
    {{/useResponseEntity}}
    {{^useResponseEntity}}
    @RestController
    {{/useResponseEntity}}
    {{/useSpringController}}
    {{#swagger2AnnotationLibrary}}
    @Tag(name = "{{{tagName}}}", description = {{#tagDescription}}"{{{.}}}"{{/tagDescription}}{{^tagDescription}}"the {{{tagName}}} API"{{/tagDescription}})
    {{/swagger2AnnotationLibrary}}
    {{#swagger1AnnotationLibrary}}
    @Api(value = "{{{tagName}}}", description = {{#tagDescription}}"{{{.}}}"{{/tagDescription}}{{^tagDescription}}"the {{{tagName}}} API"{{/tagDescription}})
    {{/swagger1AnnotationLibrary}}
    {{#operations}}
    {{#virtualService}}
    @VirtualService
    {{/virtualService}}
    {{#useRequestMappingOnInterface}}
    {{=<% %>=}}
    @RequestMapping("${openapi.<%title%>.base-path:<%>defaultBasePath%>}")
    <%={{ }}=%>
    {{/useRequestMappingOnInterface}}
    public interface {{classname}} {
    {{#jdk8-default-interface}}
        {{^isDelegate}}
            {{^reactive}}
    
        default Optional<NativeWebRequest> getRequest() {
            return Optional.empty();
        }
            {{/reactive}}
        {{/isDelegate}}
        {{#isDelegate}}
    
        default {{classname}}Delegate getDelegate() {
            return new {{classname}}Delegate() {};
        }
        {{/isDelegate}}
    {{/jdk8-default-interface}}
    {{#operation}}
    
        String PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}} = "{{{path}}}";
        /**
         * {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}}
        {{#notes}}
         * {{.}}
        {{/notes}}
         *
        {{#allParams}}
         * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}
        {{/allParams}}
         * @return {{#responses}}{{message}} (status code {{code}}){{^-last}}
         *         or {{/-last}}{{/responses}}
        {{#isDeprecated}}
         * @deprecated
        {{/isDeprecated}}
        {{#externalDocs}}
         * {{description}}
         * @see <a href="{{url}}">{{summary}} Documentation</a>
        {{/externalDocs}}
         */
        {{#isDeprecated}}
        @Deprecated
        {{/isDeprecated}}
        {{#virtualService}}
        @ApiVirtual
        {{/virtualService}}
        {{#swagger2AnnotationLibrary}}
        @Operation(
            operationId = "{{{operationId}}}",
            {{#summary}}
            summary = "{{{.}}}",
            {{/summary}}
            {{#notes}}
            description = "{{{.}}}",
            {{/notes}}
            {{#isDeprecated}}
            deprecated = true,
            {{/isDeprecated}}
            {{#vendorExtensions.x-tags.size}}
            tags = { {{#vendorExtensions.x-tags}}"{{{tag}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} },
            {{/vendorExtensions.x-tags.size}}
            responses = {
                {{#responses}}
                @ApiResponse(responseCode = {{#isDefault}}"default"{{/isDefault}}{{^isDefault}}"{{{code}}}"{{/isDefault}}, description = "{{{message}}}"{{#baseType}}, content = {
                    {{#produces}}
                    @Content(mediaType = "{{{mediaType}}}", {{#isArray}}array = @ArraySchema({{/isArray}}schema = @Schema(implementation = {{{baseType}}}.class){{#isArray}}){{/isArray}}{{^isJson}}){{^-last}},{{/-last}}{{/isJson}}{{#isJson}}{{^examples.0}}){{^-last}},{{/-last}}{{/examples.0}}{{#examples.0}}, examples = {
                    {{#examples}}
                        @ExampleObject(
                            name = "{{{exampleName}}}",
                            value = "{{{exampleValue}}}"
                        ){{^-last}},{{/-last}}
                    {{/examples}}
                    {{#-last}}
                    })
                    {{/-last}}
                    {{^-last}}
                    }),
                    {{/-last}}{{/examples.0}}{{/isJson}}
                    {{/produces}}
                }{{/baseType}}){{^-last}},{{/-last}}
                {{/responses}}
            }{{#hasAuthMethods}},
            security = {
                {{#authMethods}}
                @SecurityRequirement(name = "{{name}}"{{#scopes.0}}, scopes={ {{#scopes}}"{{scope}}"{{^-last}}, {{/-last}}{{/scopes}} }{{/scopes.0}}){{^-last}},{{/-last}}
                {{/authMethods}}
            }{{/hasAuthMethods}}{{#externalDocs}},
            externalDocs = @ExternalDocumentation(description = "{{externalDocs.description}}", url = "{{externalDocs.url}}"){{/externalDocs}}
        )
        {{/swagger2AnnotationLibrary}}
        {{#swagger1AnnotationLibrary}}
        @ApiOperation(
            {{#vendorExtensions.x-tags.size}}
            tags = { {{#vendorExtensions.x-tags}}"{{{tag}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-tags}} },
            {{/vendorExtensions.x-tags.size}}
            value = "{{{summary}}}",
            nickname = "{{{operationId}}}",
            notes = "{{{notes}}}"{{#returnBaseType}},
            response = {{{.}}}.class{{/returnBaseType}}{{#returnContainer}},
            responseContainer = "{{{.}}}"{{/returnContainer}}{{#hasAuthMethods}},
            authorizations = {
            {{#authMethods}}
            {{#scopes.0}}
                @Authorization(value = "{{name}}", scopes = {
                {{#scopes}}
                    @AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{^-last}},{{/-last}}
                {{/scopes}}
                }){{^-last}},{{/-last}}
            {{/scopes.0}}
            {{^scopes.0}}
                @Authorization(value = "{{name}}"){{^-last}},{{/-last}}
            {{/scopes.0}}
            {{/authMethods}} }{{/hasAuthMethods}}
        )
        @ApiResponses({
            {{#responses}}
            @ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{.}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{.}}}"{{/containerType}}){{^-last}},{{/-last}}
            {{/responses}}
        })
        {{/swagger1AnnotationLibrary}}
        {{#implicitHeadersParams.0}}
        {{#swagger2AnnotationLibrary}}
        @Parameters({
            {{#implicitHeadersParams}}
            {{>paramDoc}}{{^-last}},{{/-last}}
            {{/implicitHeadersParams}}
        })
        {{/swagger2AnnotationLibrary}}
        {{#swagger1AnnotationLibrary}}
        @ApiImplicitParams({
            {{#implicitHeadersParams}}
            {{>implicitHeader}}{{^-last}},{{/-last}}
            {{/implicitHeadersParams}}
        })
        {{/swagger1AnnotationLibrary}}
        {{/implicitHeadersParams.0}}
        @RequestMapping(
            method = RequestMethod.{{httpMethod}},
            value = {{classname}}.PATH_{{#lambda.uppercase}}{{#lambda.snakecase}}{{{operationId}}}{{/lambda.snakecase}}{{/lambda.uppercase}}{{#singleContentTypes}}{{#hasProduces}},
            produces = { {{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }{{/hasProduces}}{{#hasConsumes}},
            consumes = "{{{vendorExtensions.x-content-type}}}"{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}},
            produces = { {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }{{/hasProduces}}{{#hasConsumes}},
            consumes = { {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }{{/hasConsumes}}{{/singleContentTypes}}{{#hasVersionHeaders}},
            headers = { {{#vendorExtensions.versionHeaderParamsList}}"{{baseName}}{{#defaultValue}}={{{.}}}{{/defaultValue}}"{{^-last}}, {{/-last}}{{/vendorExtensions.versionHeaderParamsList}} } {{/hasVersionHeaders}}{{#hasVersionQueryParams}},
            params = { {{#vendorExtensions.versionQueryParamsList}}"{{baseName}}{{#defaultValue}}={{{.}}}{{/defaultValue}}"{{^-last}}, {{/-last}}{{/vendorExtensions.versionQueryParamsList}} } {{/hasVersionQueryParams}}{{#vendorExtensions.x-spring-api-version}}{{^empty}},
            version = "{{{vendorExtensions.x-spring-api-version}}}"{{/empty}}{{/vendorExtensions.x-spring-api-version}}
        )
        {{^useResponseEntity}}
        @ResponseStatus({{#springHttpStatus}}{{#responses.0}}{{{code}}}{{/responses.0}}{{/springHttpStatus}})
        {{/useResponseEntity}}
        {{#vendorExtensions.x-operation-extra-annotation}}
        {{{.}}}
        {{/vendorExtensions.x-operation-extra-annotation}}
        {{#vendorExtensions.x-spring-security-pre-authorize}}
        @PreAuthorize("{{{.}}}")
        {{/vendorExtensions.x-spring-security-pre-authorize}}
        {{#vendorExtensions.x-sse}}
        @ResponseBody
        {{/vendorExtensions.x-sse}}
        {{#jdk8-default-interface}}default {{/jdk8-default-interface}}{{>responseType}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}(
            {{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}},
            {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}},
            {{/hasParams}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true){{/swagger2AnnotationLibrary}} final {{#reactive}}ServerWebExchange exchange{{/reactive}}{{^reactive}}HttpServletRequest servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}},
            {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}},{{/includeHttpRequestContext}}{{/hasParams}}{{#springDocDocumentationProvider}}@ParameterObject{{/springDocDocumentationProvider}} final Pageable pageable{{/vendorExtensions.x-spring-paginated}}{{#vendorExtensions.x-spring-provide-args}}{{#-first}}{{#hasParams}},
            {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}},{{/includeHttpRequestContext}}{{^includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}},{{/vendorExtensions.x-spring-paginated}}{{/includeHttpRequestContext}}{{/hasParams}}{{/-first}}{{#swagger2AnnotationLibrary}}@Parameter(hidden = true){{/swagger2AnnotationLibrary}} {{{.}}}{{^-last}},
            {{/-last}}{{/vendorExtensions.x-spring-provide-args}}
        ){{#unhandledException}} throws Exception{{/unhandledException}}{{^jdk8-default-interface}};{{/jdk8-default-interface}}{{#jdk8-default-interface}} {
            {{#delegate-method}}
            {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#reactive}}exchange{{/reactive}}{{^reactive}}servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}}{{#vendorExtensions.springProvideArgsNames}}{{#-first}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{^includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}, {{/vendorExtensions.x-spring-paginated}}{{/includeHttpRequestContext}}{{/hasParams}}{{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{/vendorExtensions.springProvideArgsNames}});
        }
    
        // Override this method
        {{#jdk8-default-interface}}default {{/jdk8-default-interface}} {{>responseType}} {{operationId}}({{#allParams}}{{^isFile}}{{^isBodyParam}}{{>optionalDataType}}{{/isBodyParam}}{{#isBodyParam}}{{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}Mono<{{{dataType}}}>{{/isArray}}{{#isArray}}Flux<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}{{/isFile}}{{#isFile}}{{#reactive}}{{#isArray}}Flux<{{/isArray}}Part{{#isArray}}>{{/isArray}}{{/reactive}}{{^reactive}}{{#isArray}}List<{{/isArray}}MultipartFile{{#isArray}}>{{/isArray}}{{/reactive}}{{/isFile}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}} final {{#reactive}}ServerWebExchange exchange{{/reactive}}{{^reactive}}HttpServletRequest servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{/hasParams}}final Pageable pageable{{/vendorExtensions.x-spring-paginated}}{{#vendorExtensions.springProvideArgsDelegate}}{{#-first}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{^includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}, {{/vendorExtensions.x-spring-paginated}}{{/includeHttpRequestContext}}{{/hasParams}}{{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{/vendorExtensions.springProvideArgsDelegate}}){{#unhandledException}} throws Exception{{/unhandledException}} {
            {{/delegate-method}}
            {{^isDelegate}}
            {{>methodBody}}{{! prevent indent}}
            {{/isDelegate}}
            {{#isDelegate}}
            {{^isVoid}}return {{/isVoid}}{{#isVoid}}{{#useResponseEntity}}return {{/useResponseEntity}}{{^useResponseEntity}}{{#reactive}}return {{/reactive}}{{/useResponseEntity}}{{/isVoid}}getDelegate().{{operationId}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#includeHttpRequestContext}}{{#hasParams}}, {{/hasParams}}{{#reactive}}exchange{{/reactive}}{{^reactive}}servletRequest{{/reactive}}{{/includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{/hasParams}}pageable{{/vendorExtensions.x-spring-paginated}}{{#vendorExtensions.springProvideArgsNames}}{{#-first}}{{#hasParams}}, {{/hasParams}}{{^hasParams}}{{#includeHttpRequestContext}}, {{/includeHttpRequestContext}}{{^includeHttpRequestContext}}{{#vendorExtensions.x-spring-paginated}}, {{/vendorExtensions.x-spring-paginated}}{{/includeHttpRequestContext}}{{/hasParams}}{{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{/vendorExtensions.springProvideArgsNames}});
            {{/isDelegate}}
        }{{/jdk8-default-interface}}
    
    {{/operation}}
    }
    {{/operations}}

    Notes / caveats

    • Version match: this template is based on the current master copy of JavaSpring/api.mustache. If you're pinned to a different version, the safer option is to take that version's api.mustache and remove only the fragment shown in the diff above.
    • Everything in that extension is dropped: besides @PageableDefault, this also removes @SortDefault.SortDefaults and, if you enabled them, @ValidPageable/@ValidSort. That matches what 7.24.0 generated, but if you rely on any of them, you'll need to handle them another way for now.
    • Size default: without @PageableDefault, the page size comes from spring.data.web.pageable.default-page-size (default 20), not from the spec. Set it there if your spec uses a different value.
    • Leftover import: the org.springframework.data.web.PageableDefault import may still be generated but goes unused. It's harmless.
    • Remove the override after upgrading: a templateDir override hides later changes to that template. Once a fixed version is out, delete the override (or rebase it) so you don't miss future fixes.
  2. Picazsoo commented on Oct 8, 2026

    @Picazsoo
    Contributor

    I will try to prepare a comprehensive fix for the issue. It is present in both java-spring and kotlin-spring generators.
    I think we should make it configurable via boolean generatePageableDefaults (default to true) to allow for skipping generation of any defaults annotations as well as to make the index configurable via boolean oneIndexedPageParameters (default to false). And we should warn during code generation, when we encounter page default or page min = 1, if the oneIndexedPageParameters is unset (and hence defaulting to false) as that is probably by accident. Setting oneIndexedPageParameters to either true or false explicitly will silence the warning.

  3. added a commit that references this issue on Oct 14, 2026
    e36db60
  4. Picazsoo commented on Nov 9, 2026

    @Picazsoo
    Contributor

    Hi @Pattrigue and @seonwooj0810, I've kept thinking about this bug and the fix we merged, and I'd like to propose a different approach. Also pinging @dfpatinoc and @wassuh0520, since you were both involved in the discussions around @ValidPageable and @PageableDefault.

    There are really two separate problems here:

    1. @PageableDefault(page = …) is always zero-based.
    2. @ValidPageable validates the Pageable after Spring has already converted it.

    Both currently depend on knowing whether the API is one-based. #25171 guesses this from minimum: 1, and my #25197 adds options for it. I think we can avoid the question entirely.

    1. Stop generating page in @PageableDefault

    I can't think of a realistic case where the default page should be anything other than "the first page". A default size makes sense; a default page really doesn't. If we never emit the page attribute, the Pageable defaults to index 0. That is the first page, whatever spring.data.web.pageable.one-indexed-parameters is set to. We can then drop all the logic that derives the page default from the spec. size and sort defaults would stay as they are.

    If a spec sets a page.default that is not its first page, we could log a warning that it is ignored.

    2. Validate the raw request values instead of the converted Pageable

    By the time the Pageable exists, Spring Data has already changed the incoming values. In PageableHandlerMethodArgumentResolverSupport#parseAndApplyBoundaries, it:

    • subtracts 1 when one-indexed-parameters=true,
    • turns negative numbers into 0,
    • caps the value at the upper limit,
    • turns non-numeric input into 0.

    So with one-based parameters, ?page=0 becomes -1, is then turned into 0, and looks like a perfectly valid first page. minPage can never reject it. Likewise, ?page=abc silently becomes page 0. However we shift the bounds, the validator only sees values that Spring has already adjusted.

    The spec's minimum/maximum describe the values sent over the wire, so that is what we should validate:

    • Spring MVC: the annotation can stay on the Pageable parameter. Internally, the validator gets the current HttpServletRequest from RequestContextHolder (a ThreadLocal) and checks the raw page/size query parameters. The generator only treats parameters named exactly page/size/sort as pageable, so the names are known. The spec bounds go into the annotation as they are, with no shifting and no dependence on one-indexed-parameters.
    • WebFlux: there is no ThreadLocal request, and the Pageable already holds converted values. Here I'd put @ValidPageable on the ServerWebExchange parameter and validate exchange.getRequest().getQueryParams(). includeHttpRequestContext already defaults to true for reactive. We would only need to force it, ideally with a warning, when a user explicitly set it to false and generatePageableConstraintValidation is on.

    Edge cases I'd handle:

    • No bound request (e.g. the method is called directly in a unit test): skip the check, as we do today for null.
    • Missing parameter: nothing to validate; the default applies.
    • Non-numeric value: report a violation instead of letting it silently become page 0.

    Result

    Does this make sense to you? I'd especially welcome feedback on the WebFlux part, since it moves the annotation onto ServerWebExchange.

  5. Picazsoo commented on Nov 9, 2026

    @Picazsoo
    Contributor

    A follow-up on the WebFlux part of my previous comment. Moving @ValidPageable onto ServerWebExchange works, but then where the annotation goes depends on the stack (Pageable for MVC, the exchange for WebFlux), and reactive needs includeHttpRequestContext forced on. Here's an alternative that keeps the annotation on the Pageable parameter for both stacks. The cost is one small piece of configuration.

    Variant B: the annotation only carries the bounds; a wrapping Pageable resolver does the checking

    The generated method signatures stay as they are today:

    ResponseEntity<Page> list(
        @ValidPageable(minPage = 1, maxPage = 100, minSize = 1, maxSize = 50)
        @ValidSort(allowedValues = {"name,asc", "name,desc"})
        Pageable pageable);

    What changes is who checks the values:

    1. A strict Pageable resolver checks the raw values, one per stack: MVC HandlerMethodArgumentResolver, WebFlux SyncHandlerMethodArgumentResolver.
      • It reads @ValidPageable/@ValidSort from the MethodParameter.
      • It checks the raw page/size/sort query values against them, taken from NativeWebRequest (MVC) or ServerWebExchange (WebFlux).
      • On a violation it throws ResponseStatusException(BAD_REQUEST) (400).
      • Otherwise it passes the call to Spring Data's own resolver, so one-indexed-parameters, max-page-size, @PageableDefault and prefixes keep working.
      • Both stacks share one framework-agnostic check: check(rawPage, rawSize, rawSorts, annotation).
    2. The annotations become plain metadata. @ValidPageable/@ValidSort don't need a @Constraint validator at all, because the resolver is the only thing that reads them.
    3. The generator generates the wiring alongside ValidPageable/ValidSort in configPackage:
      • a WebMvcConfigurer (servlet) that inserts the strict resolver at index 0, wrapping the PageableHandlerMethodArgumentResolver bean;
      • or a WebFluxConfigurer (reactive) that registers it via configureArgumentResolvers, wrapping a ReactivePageableHandlerMethodArgumentResolver.

    Why it might be worth it

    • The annotation stays in the same place everywhere (on the Pageable), with the same bounds copied from the spec, independent of includeHttpRequestContext.
    • The validation reads the raw request values in both stacks: no ThreadLocal in MVC, and no ServerWebExchange parameter needed in WebFlux.
    • The check runs before the controller method, which is where Spring rejects other bad input too.
    • Users who import their own ValidPageable/ValidSort via importMappings can use the same pattern without generated code changing.

    Costs / open questions

    • It isn't zero-config. The generated @Configuration must be picked up, either by component scanning of configPackage or by an @Import. If it isn't, the annotations do nothing, and nothing tells you.
    • WebFlux: as far as I know, Boot doesn't create a ReactivePageableHandlerMethodArgumentResolver bean. The generated config would have to create it, and users' customisations of it would need a hook.
    • More generated code: a resolver and a config class per stack, plus tests.

    Optional extension: fail loudly when the resolver isn't wired in

    The silent no-op above can be closed without any extra configuration:

    • The strict resolver returns a marker type, e.g. final class ValidatedPageRequest extends PageRequest. Extending PageRequest keeps existing instanceof PageRequest checks working.
    • @ValidPageable stays a @Constraint, but its validator only asserts that the Pageable it receives is that marker. If it isn't, it throws IllegalStateException("Strict pageable resolver is not registered; import <generated config>").
    • Spring's built-in method validation runs this validator in both MVC and WebFlux with no wiring, so a missing registration becomes an obvious error instead of silently skipped validation.

    What it costs:

    • The failure shows up on the first request to a paginated endpoint, not at startup. That's still better than never.
    • The resolver must always return the marker, including when Spring Data falls back to Pageable.unpaged(). Otherwise the guard has to allow unpaged explicitly.
    • It adds one more generated type, and the annotation keeps a validator whose only job is to check the wiring.

    It's separable: variant B works without it, and it could be added later, or behind a flag.

    My preference

    I still lean towards the simpler approach from my previous comment: the ThreadLocal in MVC and the exchange in WebFlux, both working out of the box. I'm posting variant B (with or without the guard) so we can compare. If maintainers prefer "the annotation always stays on Pageable" and accept generating a config class, I'm happy to implement it instead.

  6. Picazsoo commented on Nov 9, 2026

    @Picazsoo
    Contributor

    A short addendum to variant B: it's already possible today, with no generator changes, but #25171 gets in the way for one-based APIs.

    Variant B works with the current generator via importMappings

    The generator only writes the annotation usages (@ValidPageable(maxSize = …, minPage = …), @ValidSort(allowedValues = {…})) and resolves the classes through importMappings with putIfAbsent, so a user mapping wins:

    // build.gradle.kts (openApiGenerate)
    importMappings.set(mapOf(
        "ValidPageable" to "com.example.validation.ValidPageable",
        "ValidSort" to "com.example.validation.ValidSort",
    ))

    The user then provides their own ValidPageable/ValidSort (plain metadata, or with the guard), the strict resolver, and the WebMvcConfigurer/WebFluxConfigurer that registers it. The generated controllers stay exactly as they are.

    Things to watch out for:

    • Attribute names. The custom annotations must declare the attributes the generator writes: maxSize, maxPage, minSize, minPage and allowedValues.
    • Unused generated files. The generated ValidPageable/ValidSort sources are still written to configPackage, even with a custom mapping. Exclude them via .openapi-generator-ignore.
    • Flags. The annotations only appear with useBeanValidation, generatePageableConstraintValidation and generateSortValidation enabled.

    How #25171 affects this

    Zero-based specs (minimum: 0 or no minimum) aren't affected; there the bounds are copied unchanged.

    For one-based specs (page minimum: 1), the problem is that the annotation doesn't say whether it was shifted. @ValidPageable(minPage = 0, maxPage = 99) could come from a zero-based spec with maximum: 99, or from a one-based spec with minimum: 1, maximum: 100 shifted down by #25171. A check of the raw values has to know from somewhere else and add 1 back:

    • Reading Spring's one-indexed-parameters setting is the obvious source, but the generator decides from the spec's minimum: 1, not from that setting. If a spec says minimum: 1 and the app is zero-based, the bounds are shifted anyway and the compensation goes wrong.
    • Assuming a convention, e.g. "all our APIs are one-based", also works, but only by agreement.

    So #25171 makes the annotation correct for the stock validator, which checks the already-converted Pageable, but wrong for any check of the raw values, whether it's my original proposal or variant B. That's one more reason to copy the bounds unchanged: then the annotation always describes the value the client sends, and any implementation, generated or plugged in via importMappings, can use it directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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