Skip to content

Commit ec4b330

Browse files
authored
Merge pull request #1 from elizabetht/master
Elizabeth/Joy - adding example support if specified in the swagger spec
2 parents ca9fcd7 + 02bcad3 commit ec4b330

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

modules/swagger-codegen/src/main/resources/JavaSpring/api.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
1616
import org.springframework.web.bind.annotation.RequestParam;
1717
import org.springframework.web.bind.annotation.RequestPart;
1818
import org.springframework.web.multipart.MultipartFile;
19+
import java.io.IOException;
1920

2021
import java.util.List;
2122
{{#async}}
@@ -49,7 +50,7 @@ public interface {{classname}} {
4950
produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}}
5051
consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}}
5152
method = RequestMethod.{{httpMethod}})
52-
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}){{^jdk8}};{{/jdk8}}{{#jdk8}} {
53+
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}){{#examples}}throws IOException{{/examples}}{{^jdk8}};{{/jdk8}}{{#jdk8}} {
5354
// do some magic!
5455
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK){{#async}}){{/async}};
5556
}{{/jdk8}}

modules/swagger-codegen/src/main/resources/JavaSpring/apiController.mustache

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestHeader;
1717
import org.springframework.web.bind.annotation.RequestParam;
1818
import org.springframework.web.bind.annotation.RequestPart;
1919
import org.springframework.web.multipart.MultipartFile;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import java.io.IOException;
2022

2123
import java.util.List;
2224
{{#async}}
@@ -40,9 +42,15 @@ public class {{classname}}Controller implements {{classname}} {
4042

4143
{{^jdk8-no-delegate}}{{#operation}}
4244
public {{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
43-
{{/hasMore}}{{/allParams}}) {
45+
{{/hasMore}}{{/allParams}}) {{#examples}}throws IOException{{/examples}} {
4446
// do some magic!{{^isDelegate}}{{^async}}
45-
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);{{/async}}{{#async}}
47+
48+
{{#examples}}
49+
ObjectMapper objectMapper = new ObjectMapper();
50+
return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue({{{example}}},{{>exampleReturnTypes}}.class), HttpStatus.OK);
51+
{{/examples}}
52+
{{^examples}}
53+
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.OK);{{/examples}}{{/async}}{{#async}}
4654
return new Callable<ResponseEntity<{{>returnTypes}}>>() {
4755
@Override
4856
public ResponseEntity<{{>returnTypes}}> call() throws Exception {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{#returnContainer}}{{#isMapContainer}}Map{{/isMapContainer}}{{#isListContainer}}List{{/isListContainer}}{{/returnContainer}}{{^returnContainer}}{{{returnType}}}{{/returnContainer}}

0 commit comments

Comments
 (0)