Add Spring pagination with vendor extension x-spring-paginated#3357
Add Spring pagination with vendor extension x-spring-paginated#3357diyfr wants to merge 20 commits intoswagger-api:masterfrom diyfr:SpringPagination
Conversation
…odegen into SpringPagination
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-data-jpa</artifactId> |
There was a problem hiding this comment.
Include spring-data-commons instead
There was a problem hiding this comment.
@cbornet I think it is easier to change application.properties than change pom.xml.
If you need persistence (what project do not need) it will change pom for recommender dependency and application.properties for add datasource.
There was a problem hiding this comment.
A lot of projects don't use JPA !! Think about NoSQL, Mongo, Cassandra, ...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
ok @cbornet
Next action :
Change dependency to spring-data-common
SpringFox plugin parameter
But I have to leave , I could not go back to the code before mid-August
There was a problem hiding this comment.
Will you at least have access to your gh account ?
In that case I can PR to your fork and you will just have to merge.
There was a problem hiding this comment.
@cbornet via mobile only . no position with git client
Otherwise we demand the integration and adapts after you ?
TODO (for me :) ) update Wiki page for vendor extension...
There was a problem hiding this comment.
@cbornet if you want you can to directly modify the branch of my git repository (access contributor)
|
@wing328 The build failed with ruby implementation ? |
|
@diyfr I've restarted the job and all tests have passed. |
| @@ -1,5 +1,6 @@ | |||
| package io.swagger.api; | |||
|
|
|||
| @javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringCodegen", date = "2016-07-13T09:45:49.128+02:00") | |||
There was a problem hiding this comment.
generate the samples with hideGenerationTimestamps=true
There was a problem hiding this comment.
Where specifying this ?
…che to library profiles
|
Some of the commits (as shown in the Commits tab) are not linked to your Github account, which means this PR won't count as your contribution in https://github.com/swagger-api/swagger-codegen/graphs/contributors. Let me know if you need help fixing it. Ref: http://stackoverflow.com/questions/3042437/change-commit-author-at-one-specific-commit |
| @@ -1,3 +1,4 @@ | |||
| #Spring MVC swagger.properties | |||
| springfox.documentation.swagger.v2.path=/api-docs | |||
| server.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}} | |||
There was a problem hiding this comment.
server.contextPath is not used by spring-mvc. Must be removed
|
oups @wing328 my git took the overall configuration instead of the project |
…che to library profiles
…odegen into SpringPagination
|
@diyfr Another way to fix the commit authorship is to add that email address as secondary email in your Github account. |
|
@diyfr I hope you'd a great vacation. Please take your time. My understanding is that this PR is not a breaking change. Please let me know if that's not the case. |
|
@cbornet
/pets:
......
responses:
'200':
description: pet response
schema:
$ref: '#/definitions/pet'
default:
description: unexpected error
schema:
$ref: '#/definitions/errorModel' -> Generated annotation : @ApiResponse(code = 200, message = "pet response", response = Pet.class),
@ApiResponse(code = 200, message = "unexpected error", response = Pet.class) })There are several ways to treat it . Which you advise ? |
|
For ApiException change extends Exception to RuntimeException. throw new ApiException(000,"Can't send action code , number invalid or external service is unavailable");And for get the code in the JsonResponse need to add a custom ErrorAttribute @Bean
public ErrorAttributes errorAttributes() {
return new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(
RequestAttributes requestAttributes,
boolean includeStackTrace) {
Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
Throwable error = getError(requestAttributes);
if (error instanceof ApiException) {
errorAttributes.put("errorCode", ((ApiException)error).getErrorCode());
}
return errorAttributes;
}
};
} |
|
@diyfr I think the error management should be done in a distinct PR. This one is already too big with a messy commit history (maybe you could squash the commits). |
| 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}} { |
There was a problem hiding this comment.
Don't use ApiIgnore but configure .ignoredParameterTypes(Pageable.class) in the docket (only if not using the plugin)
|
Agreed with @cbornet to put other features in a separate PR. (I'll squash the commits when merging this PR) |
|
I thought to close this pull request. |
Fix [https://github.com//issues/3353](https://github.com/swagger-api/swagger-codegen/issues/3353]
x-spring-paginated
Add Spring pagination to API. Transform array of object to Spring Page [http://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Page.html], with pagination options : size, page, sort
Generate ApiImplicitParams and Pageable object to method.
in petstore.json
generate in PetApi.java
@cbornet I modified SpringCodeGen.java >>
application.properties generate swagger.properties for springmvc profil replaced by application.mustache.
and removed application.properties