Skip to content

[BUG] [Spring] Invalid Interface generation when parameters are removed by x-spring-paginated #21274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 of 6 tasks
crossbone-magister opened this issue May 13, 2025 · 2 comments

Comments

@crossbone-magister
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The interface for an API that is annotated with x-spring-paginated and has no other query parameters than page and size is generated with a method parameter list that contains an extra comma (,), causing compilation errors.
The expected class should not have the extra comma.
Passing extra parameters, any empty array of parameters or no parameters at all doesn't cause the issue.
No validation problems.
It seems that is working on the latest master but don't see any changes to the spring generator classes done after release 7.13.0.

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.13.0).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */
package com.example.api;

import org.springframework.data.domain.Pageable;
import org.springdoc.core.annotations.ParameterObject;
import com.example.model.ResourceListResponseDto;
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;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.http.codec.multipart.Part;

import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import jakarta.annotation.Generated;

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2025-05-13T11:25:32.754714+02:00[Europe/Rome]", comments = "Generator version: 7.13.0")
@Validated
@Tag(name = "resource", description = "the resource API")
public interface ResourceApi {

    /**
     * GET /resource : Retrieves a resource with pagination parameters
     * Retrieves a resource with pagination parameters
     *
     * @return Successful operation (status code 200)
     */
    @Operation(
        operationId = "retrieveResource",
        summary = "Retrieves a resource with pagination parameters",
        description = "Retrieves a resource with pagination parameters",
        responses = {
            @ApiResponse(responseCode = "200", description = "Successful operation", content = {
                @Content(mediaType = "application/json", schema = @Schema(implementation = ResourceListResponseDto.class))
            })
        }
    )
    @RequestMapping(
        method = RequestMethod.GET,
        value = "/resource",
        produces = { "application/json" }
    )
    @ResponseStatus(HttpStatus.OK)
    
    Mono<ResourceListResponseDto> _retrieveResource(
        ,
        @Parameter(hidden = true) final ServerWebExchange exchange,
        @ParameterObject final Pageable pageable
    );

}

No validation issues for the spec:

java -jar .\openapi-generator-cli.jar validate -i .\src\main\resources\openapi\parameters-issue.yaml
Validating spec (.\src\main\resources\openapi\parameters-issue.yaml)
No validation issues detected.
openapi-generator version
  • Version 7.13 via openapi-generator-maven-plugin
OpenAPI declaration file content or url
openapi: 3.0.4
info:
  title: Parameter removal issue
  description: |-
    Demonstrating parameter removal issue when using x-spring-paginated: true
  version: 1.0.0
paths:
  /resource:
    get:
      x-spring-paginated: true
      summary: Retrieves a resource with pagination parameters
      description: Retrieves a resource with pagination parameters
      operationId: retrieveResource
      parameters:
        - $ref: "#/components/parameters/page"
        - $ref: "#/components/parameters/size"
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ResourceListResponse"
components:
  schemas:
    ResourceListResponse:
      type:
        object
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Resource"
    Resource:
      type: object
      properties:
        id:
          type: string
        createDate:
          type: string
          format: date-time
        updateDate:
          type: string
          format: date-time
  parameters:
    page:
      in: query
      required: false
      name: page
      description: Requested page in a list of data
      schema:
        type: integer
    size:
      in: query
      required: false
      name: size
      description: Requested page-size in a list of data
      schema:
        type: integer
Generation Details
  • Language: spring
  • Tool: openapi-generator-maven-plugin
    Configuration:
<build>
	<plugins>
		<plugin>
			<groupId>org.openapitools</groupId>
			<artifactId>openapi-generator-maven-plugin</artifactId>
			<version>${openapi-generator-maven-plugin.version}</version>
			<executions>
				<execution>
					<id>generate-parameters-issue-api</id>
					<goals>
						<goal>generate</goal>
					</goals>
					<configuration>
						<inputSpec>${project.basedir}/src/main/resources/openapi/parameters-issue.yaml</inputSpec>
						<generatorName>spring</generatorName>
						<apiPackage>com.example.api</apiPackage>
						<modelPackage>com.example.model</modelPackage>
						<modelNameSuffix>Dto</modelNameSuffix>
						<configOptions>
							<interfaceOnly>true</interfaceOnly>
							<skipDefaultInterface>true</skipDefaultInterface>
							<useSpringBoot3>true</useSpringBoot3>
							<reactive>true</reactive>
							<delegatePattern>true</delegatePattern>
							<dateLibrary>java8</dateLibrary>
							<useResponseEntity>false</useResponseEntity>
						</configOptions>
					</configuration>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>
Steps to reproduce
  1. Create a spring project
  2. Add the specs in file src/main/resources/openapi/parameters-issue.yaml
  3. Run the generator via mvn openapi-generator:generate@generate-parameters-issue-api
Related issues/PRs

I wasn't able to find any similar issue

Suggest a fix

Might it be that the way the pageable-related parameters are removed leaves the list in a state that is not considered completely empty by the template that renders the class?

@wing328
Copy link
Member

wing328 commented May 13, 2025

It seems that is working on the latest master but don't see any changes to the spring generator classes done after release 7.13.0.

so it's no longer an issue with the latest master?

so the issue was uncovered with v7.13.0 ?

@crossbone-magister
Copy link
Author

@wing328, so it seems.
v.7.13.0 is definitely affected, but master doesn't seem to. There's a slight difference in how the parameters are formatted (e.g. newlines) in the two ouput classes. (please see my latest test below).

I looked around issues and commits in the v7.13.0 to master diff but I guess I'm not familiar enough with the repo to understand what might have changed to remove the issue from master.

Test with v7.13.0

Command

 docker container run --rm -v "${pwd}:/local" openapitools/openapi-generator-cli:v7.13.0 generate -i /local/src/main/resources/openapi/parameters-issue.yaml -g spring -o /local/out -p interfaceOnly=true,skipDefaultInterface=true,useSpringBoot3=true,reactive=true,delegatePattern=true,dateLibrary=java8,useResponseEntity=false

Generated class

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.13.0).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */
package org.openapitools.api;

import org.springframework.data.domain.Pageable;
import org.springdoc.core.annotations.ParameterObject;
import org.openapitools.model.ResourceListResponse;
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;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.http.codec.multipart.Part;

import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import jakarta.annotation.Generated;

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2025-05-13T12:24:42.553318647Z[Etc/UTC]", comments = "Generator version: 7.13.0")
@Validated
@Tag(name = "resource", description = "the resource API")
public interface ResourceApi {

    /**
     * GET /resource : Retrieves a resource with pagination parameters
     * Retrieves a resource with pagination parameters
     *
     * @return Successful operation (status code 200)
     */
    @Operation(
        operationId = "retrieveResource",
        summary = "Retrieves a resource with pagination parameters",
        description = "Retrieves a resource with pagination parameters",
        responses = {
            @ApiResponse(responseCode = "200", description = "Successful operation", content = {
                @Content(mediaType = "application/json", schema = @Schema(implementation = ResourceListResponse.class))
            })
        }
    )
    @RequestMapping(
        method = RequestMethod.GET,
        value = "/resource",
        produces = { "application/json" }
    )
    @ResponseStatus(HttpStatus.OK)
    
    Mono<ResourceListResponse> _retrieveResource(
        ,
        @Parameter(hidden = true) final ServerWebExchange exchange,
        @ParameterObject final Pageable pageable
    );

}

Test with master

Command

docker container run --rm -v "${pwd}:/local" openapitools/openapi-generator-cli:latest generate -i /local/src/main/resources/openapi/parameters-issue.yaml -g spring -o /local/out -p interfaceOnly=true,skipDefaultInterface=true,useSpringBoot3=true,reactive=true,delegatePattern=true,dateLibrary=java8,useResponseEntity=false

Generated class

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.14.0-SNAPSHOT).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */
package org.openapitools.api;

import org.springframework.data.domain.Pageable;
import org.springdoc.core.annotations.ParameterObject;
import org.openapitools.model.ResourceListResponse;
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;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.http.codec.multipart.Part;

import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import jakarta.annotation.Generated;

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2025-05-13T12:23:10.289906160Z[Etc/UTC]", comments = "Generator version: 7.14.0-SNAPSHOT")
@Validated
@Tag(name = "resource", description = "the resource API")
public interface ResourceApi {

    /**
     * GET /resource : Retrieves a resource with pagination parameters
     * Retrieves a resource with pagination parameters
     *
     * @return Successful operation (status code 200)
     */
    @Operation(
        operationId = "retrieveResource",
        summary = "Retrieves a resource with pagination parameters",
        description = "Retrieves a resource with pagination parameters",
        responses = {
            @ApiResponse(responseCode = "200", description = "Successful operation", content = {
                @Content(mediaType = "application/json", schema = @Schema(implementation = ResourceListResponse.class))
            })
        }
    )
    @RequestMapping(
        method = RequestMethod.GET,
        value = "/resource",
        produces = { "application/json" }
    )
    @ResponseStatus(HttpStatus.OK)
    
    Mono<ResourceListResponse> _retrieveResource(
        @Parameter(hidden = true) final ServerWebExchange exchange,@ParameterObject final Pageable pageable
    );

}

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

No branches or pull requests

2 participants