Skip to content
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

[Java][Spring] Add Spring pagination with vendor extension x-spring-paginated #5022

Conversation

david1601
Copy link
Contributor

@david1601 david1601 commented Jan 17, 2020

PR detail
By setting of x-spring-paginated: true for an operation in the yaml file at the same level as operationId this pull request add a Spring Pageable (org.springframework.data.domain.Pageable) parameter if JavaSpring is used.

The idea for the solution based on: swagger-api/swagger-codegen#3357.

Spring Pageable: https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Pageable.html

In yaml-file:
operationId: findPetsByTags
x-spring-paginated: true

Created PetApi.java:

    @ApiOperation(value = "Finds Pets by tags", nickname = "findPetsByTags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List", authorizations = {
        @Authorization(value = "petstore_auth", scopes = {
            @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
            @AuthorizationScope(scope = "read:pets", description = "read your pets")
            })
    }, tags={ "pet", })
    @ApiImplicitParams({
        @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query",
                value = "Results page you want to retrieve (0..N)"),
        @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query",
                value = "Number of records per page."),
        @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                value = "Sorting criteria in the format: property(,asc|desc). " +
                        "Default sort order is ascending. " +
                        "Multiple sort criteria are supported.")
    })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"),
        @ApiResponse(code = 400, message = "Invalid tag value") })
    @RequestMapping(value = "/pet/findByTags",
        produces = { "application/xml", "application/json" }, 
        method = RequestMethod.GET)
    default ResponseEntity<List<Pet>> findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List<String> tags, @ApiIgnore final Pageable pageable) {

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under .\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

Technical committee for programming language Java:
@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10)

@david1601 david1601 changed the title JavaSpring Add Spring pagination with vendor extension x-spring-paginated [Java][Spring] Add Spring pagination with vendor extension x-spring-paginated Jan 27, 2020
@david1601
Copy link
Contributor Author

I executed the script ./bin/utils/ensure-up-to-date on my computer with no problem. The script showed “spring-all-petstore.sh successfully!”. But the check ci/circleci in the cloud showed the error “ERROR: Failed to run /home/circleci/OpenAPITools/openapi-generator/bin/spring-all-petstore.sh”. What is the reason for that?

@david1601 david1601 force-pushed the JavaSpring-Add-Spring-pagination-with-vendor-extension-x-spring-paginated branch from 498265a to 270cd37 Compare February 14, 2020 09:44
@wing328 wing328 added this to the 4.3.0 milestone Mar 1, 2020
@wing328 wing328 modified the milestones: 4.3.0, 4.3.1 Mar 27, 2020
@bilak
Copy link
Contributor

bilak commented Mar 31, 2020

@david1601 could you please rebase and run scripts?

@wing328 wing328 removed this from the 4.3.1 milestone May 6, 2020
@adavidhon
Copy link

@david1601 @wing328 do you have any news on this PR? Is the merge planned anytime in the near future?

@MathiasHi MathiasHi force-pushed the JavaSpring-Add-Spring-pagination-with-vendor-extension-x-spring-paginated branch 2 times, most recently from 43c5e20 to b5bbeec Compare September 22, 2020 15:10
@MathiasHi MathiasHi force-pushed the JavaSpring-Add-Spring-pagination-with-vendor-extension-x-spring-paginated branch from b5bbeec to 78d7c41 Compare September 23, 2020 08:03
Mathias Hinterndorfer and others added 3 commits September 23, 2020 14:37
…or-extension-x-spring-paginated

* master: (29 commits)
  [Core, HTML2] Rendered docs are incomplete (OpenAPITools#7510)
  [C][Client]Support data callback function (OpenAPITools#7467)
  [typescript-axios] replace optional chaining (OpenAPITools#7476)
  [typescript-axios] fix refining `query` (OpenAPITools#7475)
  [powershell] Updated the Api doc with httpsiging script snippet. (OpenAPITools#7499)
  [go][client] Fix API docs example generation (OpenAPITools#7489)
  [ci][test] Fix samples (OpenAPITools#7509)
  [bug][Java] Honor instantiationMap for default values for array, map, set (OpenAPITools#4982)
  Fix stringifying of ~= (OpenAPITools#7460)
  minor formatting change (OpenAPITools#7503)
  [ruby] Fix generation when generateAliasAsModel is enabled (OpenAPITools#7419)
  [sonar][ci] Fixes some new recommended "bug" fixes found via Sonar (OpenAPITools#7508)
  Add option to set recursion limit (OpenAPITools#7491)
  regenerate java pkmst petstore samples (OpenAPITools#7502)
  fix issue without http signature auth (OpenAPITools#7504)
  [ruby] Support for per-operation servers (OpenAPITools#7415)
  Add a link to react native tutorial (OpenAPITools#7505)
  update of Objective-C model-body.mustache to support discriminator.mappedModels (OpenAPITools#7471)
  update samples
  [ci] Sonar bug fixes (OpenAPITools#7497)
  ...
@samgurtman-zz
Copy link

samgurtman-zz commented Nov 24, 2020

So basically you've made everyone have to use Spring Data and Spring Fox. These are two big dependencies that have lots of transitive dependencies. You should not be forcing adding additional dependencies on people to satisfy a single use case. Please revert this.

@patst
Copy link
Contributor

patst commented Nov 26, 2020

This breaks our build as well because we don't use neither spring-data (therefore not have org.springframework.data.domain.Pageable on the classpath) nor springfox (therefore lacking springfox.documentation.annotations.ApiIgnore).

Can we revert this or make it at least optional?

@mercuriete
Copy link

mercuriete commented Dec 21, 2020

I have the same problem @patst
import org.springframework.data.domain.Pageable;
is generated but never used.
so I think is a bug.

apart from that.... I dont want to add

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

because my app is not using JPA at all.

my project: mercuriete/java-nurse-scheduling-problem#43

edited:

i just added this:

    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-commons</artifactId>
    </dependency>

and it works for me.

@amelnikoff
Copy link

Usually spring-data methods with Pageable support returns Page object.
Any chance this implemented too?

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

Successfully merging this pull request may close these issues.

None yet