Skip to content

Commit 2f0603a

Browse files
authored
Merge pull request #454 from ferraro/master
Added Java Spring Boot v2 language
2 parents a8d6513 + 61f6d73 commit 2f0603a

File tree

118 files changed

+5203
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+5203
-2
lines changed

src/main/java/io/swagger/codegen/v3/generators/java/Spring2Codegen.java

Lines changed: 748 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/io/swagger/codegen/v3/generators/java/SpringCodegen.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
import static io.swagger.codegen.v3.CodegenConstants.IS_ENUM_EXT_NAME;
4242
import static io.swagger.codegen.v3.generators.handlebars.ExtensionHelper.getBooleanValue;
4343

44+
/*
45+
DEPRECATED, Spring Boot 1 is in maintenance mode only. Please use JavaSpring2.
46+
*/
4447
public class SpringCodegen extends AbstractJavaCodegen implements BeanValidationFeatures, OptionalFeatures {
4548
static Logger LOGGER = LoggerFactory.getLogger(SpringCodegen.class);
4649
public static final String DEFAULT_LIBRARY = "spring-boot";
@@ -434,7 +437,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
434437

435438
final URL urlInfo = URLPathUtil.getServerURL(openAPI);
436439
String port = "8080"; // Default value for a JEE Server
437-
if ( urlInfo != null && urlInfo.getPort() != 0) {
440+
if (urlInfo != null && urlInfo.getPort() > 0) {
438441
port = String.valueOf(urlInfo.getPort());
439442
}
440443

src/main/resources/META-INF/services/io.swagger.codegen.v3.CodegenConfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ io.swagger.codegen.v3.generators.java.JavaJerseyDIServerCodegen
1515
io.swagger.codegen.v3.generators.java.JavaResteasyEapServerCodegen
1616
io.swagger.codegen.v3.generators.java.JavaResteasyServerCodegen
1717
io.swagger.codegen.v3.generators.java.SpringCodegen
18+
io.swagger.codegen.v3.generators.java.Spring2Codegen
1819
io.swagger.codegen.v3.generators.nodejs.NodeJSServerCodegen
1920
io.swagger.codegen.v3.generators.openapi.OpenAPIGenerator
2021
io.swagger.codegen.v3.generators.openapi.OpenAPIYamlGenerator
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
springfox.documentation.swagger.v2.path=/api-docs
2-
#server.port=8090
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/**
2+
* NOTE: This class is auto generated by the swagger code generator program ({{{generatorVersion}}}).
3+
* https://github.com/swagger-api/swagger-codegen
4+
* Do not edit the class manually.
5+
*/
6+
package {{package}};
7+
8+
{{#imports}}import {{import}};
9+
{{/imports}}
10+
{{#jdk8-no-delegate}}
11+
import com.fasterxml.jackson.databind.ObjectMapper;
12+
{{/jdk8-no-delegate}}
13+
import io.swagger.annotations.*;
14+
{{#jdk8-no-delegate}}
15+
import org.slf4j.Logger;
16+
import org.slf4j.LoggerFactory;
17+
import org.springframework.http.HttpStatus;
18+
{{/jdk8-no-delegate}}
19+
import org.springframework.http.ResponseEntity;
20+
{{#useBeanValidation}}
21+
import org.springframework.validation.annotation.Validated;
22+
{{/useBeanValidation}}
23+
import org.springframework.web.bind.annotation.PathVariable;
24+
import org.springframework.web.bind.annotation.RequestBody;
25+
import org.springframework.web.bind.annotation.RequestHeader;
26+
import org.springframework.web.bind.annotation.RequestMapping;
27+
import org.springframework.web.bind.annotation.RequestMethod;
28+
import org.springframework.web.bind.annotation.RequestParam;
29+
import org.springframework.web.bind.annotation.RequestPart;
30+
import org.springframework.web.multipart.MultipartFile;
31+
32+
{{#jdk8-no-delegate}}
33+
import javax.servlet.http.HttpServletRequest;
34+
{{/jdk8-no-delegate}}
35+
{{#useBeanValidation}}
36+
import javax.validation.Valid;
37+
import javax.validation.constraints.*;
38+
{{/useBeanValidation}}
39+
{{#jdk8-no-delegate}}
40+
import java.io.IOException;
41+
{{/jdk8-no-delegate}}
42+
import java.util.List;
43+
import java.util.Map;
44+
{{#jdk8-no-delegate}}
45+
import java.util.Optional;
46+
{{/jdk8-no-delegate}}
47+
{{^jdk8-no-delegate}}
48+
{{#useOptional}}
49+
import java.util.Optional;
50+
{{/useOptional}}
51+
{{/jdk8-no-delegate}}
52+
{{#async}}
53+
import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture{{/jdk8}};
54+
{{/async}}
55+
{{>generatedAnnotation}}
56+
@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API")
57+
{{#operations}}
58+
public interface {{classname}} {
59+
{{#jdk8}}
60+
61+
{{^isDelegate}}
62+
Logger log = LoggerFactory.getLogger({{classname}}.class);
63+
64+
default Optional<ObjectMapper> getObjectMapper() {
65+
return Optional.empty();
66+
}
67+
68+
default Optional<HttpServletRequest> getRequest() {
69+
return Optional.empty();
70+
}
71+
72+
default Optional<String> getAcceptHeader() {
73+
return getRequest().map(r -> r.getHeader("Accept"));
74+
}
75+
{{/isDelegate}}
76+
{{#isDelegate}}
77+
{{classname}}Delegate getDelegate();
78+
{{/isDelegate}}
79+
{{/jdk8}}
80+
{{#operation}}
81+
{{#contents}}
82+
83+
@ApiOperation(value = "{{{summary}}}", nickname = "{{{operationId}}}", notes = "{{{notes}}}"{{#returnBaseType}}, response = {{{returnBaseType}}}.class{{/returnBaseType}}{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
84+
{{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
85+
{{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
86+
{{/hasMore}}{{/scopes}}
87+
}{{/isOAuth}}){{#hasMore}},
88+
{{/hasMore}}{{/authMethods}}
89+
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
90+
@ApiResponses(value = { {{#responses}}
91+
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{baseType}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#hasMore}},{{/hasMore}}{{/responses}} })
92+
{{#implicitHeaders}}
93+
@ApiImplicitParams({
94+
{{#headerParams}}
95+
{{>implicitHeader}}
96+
{{/headerParams}}
97+
})
98+
{{/implicitHeaders}}
99+
@RequestMapping(value = "{{{path}}}",{{#singleContentTypes}}{{#hasProduces}}
100+
produces = "{{{vendorExtensions.x-accepts}}}", {{/hasProduces}}{{#hasConsumes}}
101+
consumes = "{{{vendorExtensions.x-contentType}}}",{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}
102+
produces = { {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}{{#hasConsumes}}
103+
consumes = { {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}{{/singleContentTypes}}
104+
method = RequestMethod.{{httpMethod}})
105+
{{#jdk8}}default {{/jdk8}}{{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{#delegate-method}}_{{/delegate-method}}{{operationId}}({{#parameters}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/parameters}}){{^jdk8}};{{/jdk8}}{{#jdk8}} {
106+
{{#delegate-method}}
107+
return {{operationId}}({{#parameters}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});
108+
}
109+
110+
// Override this method
111+
default {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#parameters}}{{^isFile}}{{{dataType}}}{{/isFile}}{{#isFile}}MultipartFile{{/isFile}} {{paramName}}{{#hasMore}},{{/hasMore}}{{/parameters}}) {
112+
{{/delegate-method}}
113+
{{^isDelegate}}
114+
if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
115+
{{#examples}}
116+
if (getAcceptHeader().get().contains("{{{contentType}}}")) {
117+
try {
118+
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(getObjectMapper().get().readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}};
119+
} catch (IOException e) {
120+
log.error("Couldn't serialize response for content type {{{contentType}}}", e);
121+
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR){{#async}}){{/async}};
122+
}
123+
}
124+
{{/examples}}
125+
} else {
126+
log.warn("ObjectMapper or HttpServletRequest not configured in default {{classname}} interface so no example is generated");
127+
}
128+
return {{#async}}CompletableFuture.completedFuture({{/async}}new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED){{#async}}){{/async}};
129+
{{/isDelegate}}
130+
{{#isDelegate}}
131+
return getDelegate().{{operationId}}({{#parameters}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});
132+
{{/isDelegate}}
133+
}{{/jdk8}}
134+
135+
{{/contents}}
136+
{{/operation}}
137+
}
138+
{{/operations}}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package {{package}};
2+
3+
{{^jdk8}}
4+
{{#imports}}import {{import}};
5+
{{/imports}}
6+
{{/jdk8}}
7+
{{^isDelegate}}
8+
import com.fasterxml.jackson.databind.ObjectMapper;
9+
{{/isDelegate}}
10+
{{^jdk8}}
11+
import io.swagger.annotations.*;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
import org.springframework.http.HttpStatus;
15+
import org.springframework.http.ResponseEntity;
16+
{{/jdk8}}
17+
import org.springframework.stereotype.Controller;
18+
{{^jdk8}}
19+
import org.springframework.web.bind.annotation.PathVariable;
20+
import org.springframework.web.bind.annotation.RequestBody;
21+
import org.springframework.web.bind.annotation.RequestHeader;
22+
import org.springframework.web.bind.annotation.RequestParam;
23+
import org.springframework.web.bind.annotation.RequestPart;
24+
import org.springframework.web.multipart.MultipartFile;
25+
26+
{{#useBeanValidation}}
27+
import javax.validation.constraints.*;
28+
import javax.validation.Valid;
29+
{{/useBeanValidation}}
30+
{{/jdk8}}
31+
{{^isDelegate}}
32+
import javax.servlet.http.HttpServletRequest;
33+
{{#jdk8}}
34+
import java.util.Optional;
35+
{{/jdk8}}
36+
{{/isDelegate}}
37+
{{^jdk8-no-delegate}}
38+
{{#useOptional}}
39+
import java.util.Optional;
40+
{{/useOptional}}
41+
{{/jdk8-no-delegate}}
42+
{{^jdk8}}
43+
{{^isDelegate}}
44+
import java.io.IOException;
45+
{{/isDelegate}}
46+
import java.util.List;
47+
import java.util.Map;
48+
{{#async}}
49+
import java.util.concurrent.Callable;
50+
{{/async}}
51+
{{/jdk8}}
52+
{{>generatedAnnotation}}
53+
@Controller
54+
{{#operations}}
55+
public class {{classname}}Controller implements {{classname}} {
56+
57+
{{#isDelegate}}
58+
private final {{classname}}Delegate delegate;
59+
60+
@org.springframework.beans.factory.annotation.Autowired
61+
public {{classname}}Controller({{classname}}Delegate delegate) {
62+
this.delegate = delegate;
63+
}
64+
{{#jdk8}}
65+
66+
@Override
67+
public {{classname}}Delegate getDelegate() {
68+
return delegate;
69+
}
70+
{{/jdk8}}
71+
{{/isDelegate}}
72+
{{^isDelegate}}
73+
{{^jdk8}}
74+
private static final Logger log = LoggerFactory.getLogger({{classname}}Controller.class);
75+
76+
{{/jdk8}}
77+
private final ObjectMapper objectMapper;
78+
79+
private final HttpServletRequest request;
80+
81+
@org.springframework.beans.factory.annotation.Autowired
82+
public {{classname}}Controller(ObjectMapper objectMapper, HttpServletRequest request) {
83+
this.objectMapper = objectMapper;
84+
this.request = request;
85+
}
86+
{{#jdk8}}
87+
88+
@Override
89+
public Optional<ObjectMapper> getObjectMapper() {
90+
return Optional.ofNullable(objectMapper);
91+
}
92+
93+
@Override
94+
public Optional<HttpServletRequest> getRequest() {
95+
return Optional.ofNullable(request);
96+
}
97+
{{/jdk8}}
98+
99+
{{/isDelegate}}
100+
{{^jdk8}}
101+
{{#operation}}
102+
{{#contents}}
103+
public {{#async}}Callable<{{/async}}ResponseEntity<{{>returnTypes}}>{{#async}}>{{/async}} {{operationId}}({{#parameters}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/parameters}}) {
104+
{{^isDelegate}}
105+
{{^async}}
106+
String accept = request.getHeader("Accept");
107+
{{#examples}}
108+
if (accept != null && accept.contains("{{{contentType}}}")) {
109+
try {
110+
return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.NOT_IMPLEMENTED);
111+
} catch (IOException e) {
112+
log.error("Couldn't serialize response for content type {{{contentType}}}", e);
113+
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.INTERNAL_SERVER_ERROR);
114+
}
115+
}
116+
117+
{{/examples}}
118+
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.NOT_IMPLEMENTED);
119+
{{/async}}
120+
{{#async}}
121+
return new Callable<ResponseEntity<{{>returnTypes}}>>() {
122+
@Override
123+
public ResponseEntity<{{>returnTypes}}> call() {
124+
String accept = request.getHeader("Accept");
125+
{{#examples}}
126+
if (accept != null && accept.contains("{{{contentType}}}")) {
127+
try {
128+
return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.NOT_IMPLEMENTED);
129+
} catch (IOException e) {
130+
log.error("Couldn't serialize response for content type {{{contentType}}}", e);
131+
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.INTERNAL_SERVER_ERROR);
132+
}
133+
}
134+
135+
{{/examples}}
136+
return new ResponseEntity<{{>returnTypes}}>(HttpStatus.NOT_IMPLEMENTED);
137+
}
138+
};
139+
{{/async}}
140+
{{/isDelegate}}
141+
{{#isDelegate}}
142+
return delegate.{{operationId}}({{#parameters}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/parameters}});
143+
{{/isDelegate}}
144+
}
145+
146+
{{/contents}}
147+
{{/operation}}
148+
{{/jdk8}}
149+
}
150+
{{/operations}}

0 commit comments

Comments
 (0)