Skip to content

[Java][Spring] Fix spring cloud client due to enhancement in adding server example responses. #5497

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

Merged
merged 4 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ public void processOpts() {
if (!additionalProperties.containsKey(SINGLE_CONTENT_TYPES)) {
additionalProperties.put(SINGLE_CONTENT_TYPES, "true");
this.setSingleContentTypes(true);

}
additionalProperties.put("useSpringCloudClient", true);

} else {
apiTemplateFiles.put("apiController.mustache", "Controller.java");
Expand Down
11 changes: 11 additions & 0 deletions modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
{{#useSpringCloudClient}}
import java.io.IOException;
{{/useSpringCloudClient}}

import java.util.List;
{{#async}}
Expand Down Expand Up @@ -52,11 +54,20 @@ public interface {{classname}} {
produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}}
consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}}
method = RequestMethod.{{httpMethod}})
{{#useSpringCloudClient}}
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}){{^jdk8}};{{/jdk8}}{{#jdk8}} {
// do some magic!
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK){{#async}}){{/async}};
}{{/jdk8}}

{{/useSpringCloudClient}}
{{^useSpringCloudClient}}
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}},{{/allParams}} @RequestHeader("Accept") String accept){{#examples}}{{#-first}} throws IOException{{/-first}}{{/examples}}{{^jdk8}};{{/jdk8}}{{#jdk8}} {
// do some magic!
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK){{#async}}){{/async}};
}{{/jdk8}}

{{/useSpringCloudClient}}
{{/operation}}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
{{^useSpringCloudClient}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spring cloud client doesn't generate the apiController so I guess this is not needed...

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
{{/useSpringCloudClient}}

import java.util.List;
{{#async}}
Expand Down Expand Up @@ -52,6 +54,25 @@ public class {{classname}}Controller implements {{classname}} {
public {{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}},
{{/allParams}}@RequestHeader("Accept") String accept){{#examples}}{{#-first}} throws IOException{{/-first}}{{/examples}} {
// do some magic!
{{#useSpringCloudClient}}
{{^isDelegate}}
{{^async}}
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
{{/async}}
{{#async}}
return new Callable<ResponseEntity<{{>returnTypes}}>>() {
@Override
public ResponseEntity<{{>returnTypes}}> call() throws Exception {
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);
}
};
{{/async}}
{{/isDelegate}}
{{#isDelegate}}
return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{/isDelegate}}
{{/useSpringCloudClient}}
{{^useSpringCloudClient}}
{{^isDelegate}}
{{^async}}
{{#examples}}
Expand All @@ -75,6 +96,7 @@ public class {{classname}}Controller implements {{classname}} {
{{#isDelegate}}
return delegate.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
{{/isDelegate}}
{{/useSpringCloudClient}}
}

{{/operation}}
Expand Down
6 changes: 1 addition & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,6 @@
<module>samples/client/petstore/jaxrs-cxf-client</module>
<module>samples/client/petstore/java/resttemplate</module>
<module>samples/client/petstore/scala</module>
<!-- only test java-related projects
<module>samples/client/petstore/akka-scala</module>
<module>samples/client/petstore/ruby</module>
<module>samples/client/petstore/android/volley</module>
Expand All @@ -818,7 +817,6 @@
<module>samples/client/petstore/typescript-angular</module>
<module>samples/client/petstore/typescript-node/npm</module>
<module>samples/client/petstore/typescript-jquery/npm</module>
-->
<!--module>samples/client/petstore/objc/SwaggerClientTests</module-->
<!--module>samples/client/petstore/swift/SwaggerClientTests</module-->
<!-- servers -->
Expand All @@ -833,15 +831,13 @@
<module>samples/server/petstore/jaxrs-resteasy/joda</module>
<module>samples/server/petstore/scalatra</module>
<module>samples/server/petstore/spring-mvc</module>
<!-- comment out due to change in method signature
<module>samples/client/petstore/spring-cloud</module> -->
<module>samples/client/petstore/spring-cloud</module>
<module>samples/server/petstore/springboot</module>
<module>samples/server/petstore/springboot-beanvalidation</module>
<module>samples/server/petstore/jaxrs-cxf</module>
<module>samples/server/petstore/jaxrs-cxf-annotated-base-path</module>
<module>samples/server/petstore/jaxrs-cxf-cdi</module>
<module>samples/server/petstore/jaxrs-cxf-non-spring-app</module>

<!--<module>samples/server/petstore/java-msf4j</module> note: JDK8 only -->
</modules>
</profile>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml.circleci
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,8 @@
<module>samples/client/petstore/java/retrofit2rx</module>
<module>samples/client/petstore/jaxrs-cxf-client</module>
<module>samples/client/petstore/java/resttemplate</module>
<module>samples/client/petstore/scala</module>
<!-- only test java-related projects
<module>samples/client/petstore/scala</module>
<module>samples/client/petstore/akka-scala</module>
<module>samples/client/petstore/ruby</module>
<module>samples/client/petstore/android/volley</module>
Expand Down Expand Up @@ -831,7 +831,7 @@
<module>samples/server/petstore/jaxrs-resteasy/eap</module>
<module>samples/server/petstore/jaxrs-resteasy/eap-joda</module>
<module>samples/server/petstore/jaxrs-resteasy/joda</module>
<module>samples/server/petstore/scalatra</module>
<!--<module>samples/server/petstore/scalatra</module>-->
<module>samples/server/petstore/spring-mvc</module>
<!-- comment out due to change in method signature
<module>samples/client/petstore/spring-cloud</module> -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public interface PetApi {
}, tags={ "pet", })
@ApiResponses(value = {
@ApiResponse(code = 405, message = "Invalid input", response = Void.class) })

@RequestMapping(value = "/pet",
produces = "application/json",
consumes = "application/json",
Expand All @@ -47,7 +46,6 @@ public interface PetApi {
}, tags={ "pet", })
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid pet value", response = Void.class) })

@RequestMapping(value = "/pet/{petId}",
produces = "application/json",
consumes = "application/json",
Expand All @@ -64,12 +62,11 @@ public interface PetApi {
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Pet.class),
@ApiResponse(code = 400, message = "Invalid status value", response = Pet.class) })

@RequestMapping(value = "/pet/findByStatus",
produces = "application/json",
consumes = "application/json",
method = RequestMethod.GET)
com.netflix.hystrix.HystrixCommand<ResponseEntity<List<Pet>>> findPetsByStatus( @NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @RequestParam(value = "status", required = true) List<String> status) throws IOException;
com.netflix.hystrix.HystrixCommand<ResponseEntity<List<Pet>>> findPetsByStatus( @NotNull@ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @RequestParam(value = "status", required = true) List<String> status);


@ApiOperation(value = "Finds Pets by tags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List", authorizations = {
Expand All @@ -81,12 +78,11 @@ public interface PetApi {
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Pet.class),
@ApiResponse(code = 400, message = "Invalid tag value", response = Pet.class) })

@RequestMapping(value = "/pet/findByTags",
produces = "application/json",
consumes = "application/json",
method = RequestMethod.GET)
com.netflix.hystrix.HystrixCommand<ResponseEntity<List<Pet>>> findPetsByTags( @NotNull @ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags) throws IOException;
com.netflix.hystrix.HystrixCommand<ResponseEntity<List<Pet>>> findPetsByTags( @NotNull@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags);


@ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = {
Expand All @@ -96,12 +92,11 @@ public interface PetApi {
@ApiResponse(code = 200, message = "successful operation", response = Pet.class),
@ApiResponse(code = 400, message = "Invalid ID supplied", response = Pet.class),
@ApiResponse(code = 404, message = "Pet not found", response = Pet.class) })

@RequestMapping(value = "/pet/{petId}",
produces = "application/json",
consumes = "application/json",
method = RequestMethod.GET)
com.netflix.hystrix.HystrixCommand<ResponseEntity<Pet>> getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId) throws IOException;
com.netflix.hystrix.HystrixCommand<ResponseEntity<Pet>> getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId);


@ApiOperation(value = "Update an existing pet", notes = "", response = Void.class, authorizations = {
Expand All @@ -114,7 +109,6 @@ public interface PetApi {
@ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class),
@ApiResponse(code = 404, message = "Pet not found", response = Void.class),
@ApiResponse(code = 405, message = "Validation exception", response = Void.class) })

@RequestMapping(value = "/pet",
produces = "application/json",
consumes = "application/json",
Expand All @@ -130,7 +124,6 @@ public interface PetApi {
}, tags={ "pet", })
@ApiResponses(value = {
@ApiResponse(code = 405, message = "Invalid input", response = Void.class) })

@RequestMapping(value = "/pet/{petId}",
produces = "application/json",
consumes = "application/x-www-form-urlencoded",
Expand All @@ -146,11 +139,10 @@ public interface PetApi {
}, tags={ "pet", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse.class) })

@RequestMapping(value = "/pet/{petId}/uploadImage",
produces = "application/json",
consumes = "multipart/form-data",
method = RequestMethod.POST)
com.netflix.hystrix.HystrixCommand<ResponseEntity<ModelApiResponse>> uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId,@ApiParam(value = "Additional data to pass to server" ) @RequestParam(value="additionalMetadata", required=false) String additionalMetadata,@ApiParam(value = "file detail") @RequestParam("file") MultipartFile file) throws IOException;
com.netflix.hystrix.HystrixCommand<ResponseEntity<ModelApiResponse>> uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId,@ApiParam(value = "Additional data to pass to server" ) @RequestParam(value="additionalMetadata", required=false) String additionalMetadata,@ApiParam(value = "file detail") @RequestParam("file") MultipartFile file);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public interface StoreApi {
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid ID supplied", response = Void.class),
@ApiResponse(code = 404, message = "Order not found", response = Void.class) })

@RequestMapping(value = "/store/order/{orderId}",
produces = "application/json",
consumes = "application/json",
Expand All @@ -39,36 +38,33 @@ public interface StoreApi {
}, tags={ "store", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Integer.class) })

@RequestMapping(value = "/store/inventory",
produces = "application/json",
consumes = "application/json",
method = RequestMethod.GET)
com.netflix.hystrix.HystrixCommand<ResponseEntity<Map<String, Integer>>> getInventory() throws IOException;
com.netflix.hystrix.HystrixCommand<ResponseEntity<Map<String, Integer>>> getInventory();


@ApiOperation(value = "Find purchase order by ID", notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", response = Order.class, tags={ "store", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Order.class),
@ApiResponse(code = 400, message = "Invalid ID supplied", response = Order.class),
@ApiResponse(code = 404, message = "Order not found", response = Order.class) })

@RequestMapping(value = "/store/order/{orderId}",
produces = "application/json",
consumes = "application/json",
method = RequestMethod.GET)
com.netflix.hystrix.HystrixCommand<ResponseEntity<Order>> getOrderById( @Min(1) @Max(5)@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId) throws IOException;
com.netflix.hystrix.HystrixCommand<ResponseEntity<Order>> getOrderById( @Min(1) @Max(5)@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId);


@ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class, tags={ "store", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = Order.class),
@ApiResponse(code = 400, message = "Invalid Order", response = Order.class) })

@RequestMapping(value = "/store/order",
produces = "application/json",
consumes = "application/json",
method = RequestMethod.POST)
com.netflix.hystrix.HystrixCommand<ResponseEntity<Order>> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody Order body) throws IOException;
com.netflix.hystrix.HystrixCommand<ResponseEntity<Order>> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody Order body);

}
Loading