-
Notifications
You must be signed in to change notification settings - Fork 6k
Add Spring pagination with vendor extension x-spring-paginated #3357
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
Changes from all commits
e908589
c788a32
a6e3194
a8a0953
1b483da
3d070b8
35dd54f
3fe3558
f89111c
5629d46
d8b7bb6
82ae76e
e464165
78cb757
2167b8d
4a61609
ea8b6ef
4d01ad4
a36d68f
96d37f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ import io.swagger.annotations.*; | |
| {{#java8}} | ||
| import org.springframework.http.HttpStatus; | ||
| {{/java8}} | ||
| import org.springframework.data.domain.Pageable; | ||
| import springfox.documentation.annotations.ApiIgnore; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
|
|
@@ -34,16 +36,27 @@ public interface {{classname}} { | |
| {{/hasMore}}{{/scopes}} | ||
| }{{/isOAuth}}){{#hasMore}}, | ||
| {{/hasMore}}{{/authMethods}} | ||
| }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} }) | ||
| @ApiResponses(value = { {{#responses}} | ||
| }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} }) | ||
| {{#vendorExtensions.x-spring-paginated}} | ||
| @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.") | ||
| }){{/vendorExtensions.x-spring-paginated}} | ||
| @ApiResponses(value = { {{#responses}} | ||
| @ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{returnType}}}.class){{#hasMore}},{{/hasMore}}{{/responses}} }) | ||
| @RequestMapping(value = "{{{path}}}",{{#singleContentTypes}} | ||
| produces = "{{{vendorExtensions.x-accepts}}}", | ||
| consumes = "{{{vendorExtensions.x-contentType}}}",{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}} | ||
| produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}} | ||
| consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}} | ||
| method = RequestMethod.{{httpMethod}}) | ||
| {{#java8}}default {{/java8}}{{#async}}{{^java8}}Callable{{/java8}}{{#java8}}CompletableFuture<{{/java8}}{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}){{^java8}};{{/java8}}{{#java8}} { | ||
| {{#java8}}default {{/java8}}{{#async}}{{^java8}}Callable{{/java8}}{{#java8}}CompletableFuture<{{/java8}}{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}{{#vendorExtensions.x-spring-paginated}}, @ApiIgnore final Pageable pageable{{/vendorExtensions.x-spring-paginated}}){{^java8}};{{/java8}}{{#java8}} { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use ApiIgnore but configure |
||
| // do some magic! | ||
| return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK){{#async}}){{/async}}; | ||
| }{{/java8}} | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #SpringBoot application.properties | ||
| springfox.documentation.swagger.v2.path=/api-docs | ||
| server.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}} | ||
| #server.port=8090 | ||
|
|
||
| #Remove this exclusion for use Jpa. But don't miss to declare datasource before... | ||
| spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>1.3.5.RELEASE</version> | ||
| <version>1.4.0.RELEASE</version> | ||
| </parent> | ||
| <build> | ||
| <sourceDirectory>src/main/java</sourceDirectory> | ||
|
|
@@ -44,6 +44,10 @@ | |
| <artifactId>spring-boot-starter-tomcat</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-data-jpa</artifactId> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include spring-data-commons instead
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cbornet I think it is easier to change application.properties than change pom.xml.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of projects don't use JPA !! Think about NoSQL, Mongo, Cassandra, ...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's less intrusive to let the user add spring-boot-starter-data-jpa if he needs JPA and it will not cause any problem to have spring-data-commons in parallel.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok @cbornet
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you at least have access to your gh account ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cbornet via mobile only . no position with git client TODO (for me :) ) update Wiki page for vendor extension...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cbornet if you want you can to directly modify the branch of my git repository (access contributor) |
||
| </dependency> | ||
| <!--SpringFox dependencies --> | ||
| <dependency> | ||
| <groupId>io.springfox</groupId> | ||
|
|
@@ -74,4 +78,4 @@ | |
| </dependency> | ||
| {{/java8}} | ||
| </dependencies> | ||
| </project> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| #Spring MVC swagger.properties | ||
| springfox.documentation.swagger.v2.path=/api-docs | ||
| server.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. server.contextPath is not used by spring-mvc. Must be removed |
||
| #server.port=8090 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,7 @@ | |
| "application/json", | ||
| "application/xml" | ||
| ], | ||
| "x-spring-pageable":true, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. x-spring-paginated |
||
| "parameters": [ | ||
| { | ||
| "name": "status", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a plugin would be nicer