Skip to content

Commit

Permalink
Merge pull request #1635 from gmarziou/swagger_2_1508
Browse files Browse the repository at this point in the history
Migration from Swagger Spring MVC to Swagger Springfox 2.0.3
  • Loading branch information
jdubois committed Jun 29, 2015
2 parents 9a80403 + c771cb4 commit 111ceb7
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 143 deletions.
5 changes: 1 addition & 4 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,7 @@ JhipsterGenerator.prototype.app = function app() {
}else{
this.template(resourceDir + '/i18n/_messages_en.properties', resourceDir + 'i18n/messages_en.properties', this, {});
}
// Swagger-ui for Jhipster
this.template(webappDir + '/swagger-ui/_index.html', webappDir + 'swagger-ui/index.html', this, {});
this.copy(webappDir + '/swagger-ui/images/throbber.gif', webappDir + 'swagger-ui/images/throbber.gif');


// Angular JS views

this.template(webappDir + '/scripts/app/_app.js', webappDir + 'scripts/app/app.js', this, {});
Expand Down
6 changes: 2 additions & 4 deletions app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,17 @@ module.exports = function (grunt) {
src: ['src/main/webapp/index.html', 'src/main/scss/main.scss'],
exclude: [
/angular-i18n/, // localizations are loaded dynamically
/swagger-ui/,
'bower_components/bootstrap/' // Exclude Bootstrap LESS as we use bootstrap-sass
],
ignorePath: /\.\.\/webapp\/bower_components\// // remove ../webapp/bower_components/ from paths of injected sass files <% } else { %>
src: ['src/main/webapp/index.html'],
exclude: [
/angular-i18n/, // localizations are loaded dynamically
/swagger-ui/
/angular-i18n/ // localizations are loaded dynamically
]<% } %>
},
test: {
src: 'src/test/javascript/karma.conf.js',
exclude: [/angular-i18n/, /swagger-ui/, /angular-scenario/],
exclude: [/angular-i18n/, /angular-scenario/],
ignorePath: /\.\.\/\.\.\//, // remove ../../ from paths of injected javascripts
devDependencies: true,
fileTypes: {
Expand Down
1 change: 0 additions & 1 deletion app/templates/_bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"angular-translate-loader-partial": "2.7.0",
"angular-dynamic-locale": "0.1.27",<% } %>
"angular-local-storage": "0.2.0",
"swagger-ui": "2.0.24",
"angular-cache-buster": "0.4.3",
"ngInfiniteScroll": "1.2.0"
},
Expand Down
8 changes: 3 additions & 5 deletions app/templates/_build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@ dependencies {
compile group: 'org.springframework.security', name: 'spring-security-messaging', version: spring_security_version <% } %><% if (authenticationType == 'oauth2') { %>
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: spring_security_oauth2_version<% } %><% if (databaseType == 'mongodb') { %>
compile group: 'org.mongeez', name: 'mongeez', version: mongeez_version<% } %>
compile(group: 'com.mangofactory', name: 'swagger-springmvc', version: swagger_springmvc_version) {
exclude(module: 'jackson-module-scala_2.10')
exclude(module: 'scalap')
exclude(module: 'scala-compiler')
}<% if (devDatabaseType == 'mysql' || prodDatabaseType == 'mysql') { %>
compile(group: 'io.springfox', name: 'springfox-swagger-ui', version: springfox_version)
compile(group: 'io.springfox', name: 'springfox-swagger2', version: springfox_version)
<% if (devDatabaseType == 'mysql' || prodDatabaseType == 'mysql') { %>
compile group: 'mysql', name: 'mysql-connector-java'<% } %><% if (devDatabaseType == 'postgresql' || prodDatabaseType == 'postgresql') { %>
compile group: 'org.postgresql', name: 'postgresql', version: postgresql_version<% } %><% if (devDatabaseType == 'h2Memory') { %>
compile group: 'com.h2database', name: 'h2'<% } %><% if (javaVersion == '8') { %>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/_gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ metrics_spring_version=3.0.4<% if (devDatabaseType == 'postgresql' || prodDataba
postgresql_version=9.3-1102-jdbc41<% } %><% if (authenticationType == 'oauth2') { %>
spring_security_oauth2_version=2.0.7.RELEASE<% } %>
spring_security_version=4.0.1.RELEASE
swagger_springmvc_version=0.9.5
springfox_version=2.0.3
spring_boot_version=1.2.4.RELEASE
spring_cloud_version=1.1.1.RELEASE
usertype_core_version=3.2.0.GA<% if (devDatabaseType == 'mysql' || prodDatabaseType == 'mysql') { %>
Expand Down
27 changes: 9 additions & 18 deletions app/templates/_pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<sonar-maven-plugin.version>2.3</sonar-maven-plugin.version>
<spring-security.version>4.0.1.RELEASE</spring-security.version><% if (authenticationType == 'oauth2') { %>
<spring-security-oauth2.version>2.0.7.RELEASE</spring-security-oauth2.version><% } %>
<swagger-springmvc.version>0.9.5</swagger-springmvc.version>
<springfox.version>2.0.3</springfox.version>
<usertype-core.version>3.2.0.GA</usertype-core.version>
</properties>

Expand Down Expand Up @@ -164,23 +164,14 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>${swagger-springmvc.version}</version>
<exclusions>
<exclusion>
<artifactId>jackson-module-scala_2.10</artifactId>
<groupId>com.fasterxml.jackson.module</groupId>
</exclusion>
<exclusion>
<artifactId>scalap</artifactId>
<groupId>org.scala-lang</groupId>
</exclusion>
<exclusion>
<artifactId>scala-compiler</artifactId>
<groupId>org.scala-lang</groupId>
</exclusion>
</exclusions>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency><% if (databaseType == 'sql') { %>
<dependency>
<groupId>com.mattbertolini</groupId>
Expand Down
13 changes: 9 additions & 4 deletions app/templates/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ gulp.task('serve', function() {
'/api',
'/health',
'/configprops',
'/api-docs',
'/v2/api-docs',
'/swagger-ui.html',
'/configuration/security',
'/configuration/ui',
'/swagger-resources',
'/webjars',
'/metrics',
'/websocket/tracker',
'/dump'<% if (authenticationType == 'oauth2') { %>,
'/oauth/token'<% } %><% if (devDatabaseType == 'h2Memory') { %>,
'/console/'<% } %>
Expand Down Expand Up @@ -181,15 +187,14 @@ gulp.task('wiredep', ['wiredep:test', 'wiredep:app']);
gulp.task('wiredep:app', function () {
var s = gulp.src('src/main/webapp/index.html')
.pipe(wiredep({
exclude: [/angular-i18n/, /swagger-ui/]
exclude: [/angular-i18n/]
}))
.pipe(gulp.dest('src/main/webapp'));

return <% if (useCompass) { %>es.merge(s, gulp.src('src/main/scss/main.scss')
.pipe(wiredep({
exclude: [
/angular-i18n/, // localizations are loaded dynamically
/swagger-ui/,
'bower_components/bootstrap/' // Exclude Bootstrap LESS as we use bootstrap-sass
],
ignorePath: /\.\.\/webapp\/bower_components\// // remove ../webapp/bower_components/ from paths of injected sass files
Expand All @@ -200,7 +205,7 @@ gulp.task('wiredep:app', function () {
gulp.task('wiredep:test', function () {
return gulp.src('src/test/javascript/karma.conf.js')
.pipe(wiredep({
exclude: [/angular-i18n/, /swagger-ui/, /angular-scenario/],
exclude: [/angular-i18n/, /angular-scenario/],
ignorePath: /\.\.\/\.\.\//, // remove ../../ from paths of injected javascripts
devDependencies: true,
fileTypes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void configure(WebSecurity web) throws Exception {
.antMatchers("/bower_components/**")
.antMatchers("/i18n/**")
.antMatchers("/assets/**")
.antMatchers("/swagger-ui/**")<% if (authenticationType == 'oauth2') { %>
.antMatchers("/swagger-ui.html")<% if (authenticationType == 'oauth2') { %>
.antMatchers("/api/register")
.antMatchers("/api/activate")
.antMatchers("/api/account/reset_password/init")
Expand Down Expand Up @@ -137,6 +137,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/api/**").authenticated()<% if (websocket == 'spring-websocket') { %>
.antMatchers("/websocket/tracker").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/websocket/**").permitAll()<% } %>
.antMatchers("/webjars/**").permitAll()
.antMatchers("/metrics/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/health/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/trace/**").hasAuthority(AuthoritiesConstants.ADMIN)
Expand All @@ -148,7 +149,10 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/autoconfig/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/env/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/trace/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/api-docs/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/v2/api-docs/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/configuration/security").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/configuration/ui").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/swagger-ui.html").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/protected/**").authenticated()<% if (authenticationType != 'xauth') { %>;<% } %><% if (authenticationType == 'xauth') { %>
.and()
.apply(securityConfigurerAdapter());<% } %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package <%=packageName%>.config.apidoc;

import <%=packageName%>.config.Constants;
import com.mangofactory.swagger.configuration.SpringSwaggerConfig;
import com.mangofactory.swagger.models.dto.ApiInfo;
import com.mangofactory.swagger.plugin.EnableSwagger;
import com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.bind.RelaxedPropertyResolver;
Expand All @@ -15,17 +11,23 @@
import org.springframework.core.env.Environment;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StopWatch;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import static springfox.documentation.builders.PathSelectors.regex;

/**
* Swagger configuration.
* Springfox Swagger configuration.
*
* Warning! When having a lot of REST endpoints, Swagger can become a performance issue. In that
* Warning! When having a lot of REST endpoints, Springfox can become a performance issue. In that
* case, you can use a specific Spring profile for this class, so that only front-end developers
* have access to the Swagger view.
*/
@Configuration
@EnableSwagger
@Profile("!" + Constants.SPRING_PROFILE_FAST)
@EnableSwagger2
@Profile("!"+Constants.SPRING_PROFILE_PRODUCTION)
public class SwaggerConfiguration implements EnvironmentAware {

private final Logger log = LoggerFactory.getLogger(SwaggerConfiguration.class);
Expand All @@ -40,19 +42,19 @@ public void setEnvironment(Environment environment) {
}

/**
* Swagger Spring MVC configuration.
* Swagger Springfox configuration.
*/
@Bean
public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin(SpringSwaggerConfig springSwaggerConfig) {
public Docket swaggerSpringfoxDocket() {
log.debug("Starting Swagger");
StopWatch watch = new StopWatch();
watch.start();
SwaggerSpringMvcPlugin swaggerSpringMvcPlugin = new SwaggerSpringMvcPlugin(springSwaggerConfig)
Docket swaggerSpringMvcPlugin = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.genericModelSubstitutes(ResponseEntity.class)
.includePatterns(DEFAULT_INCLUDE_PATTERN);

swaggerSpringMvcPlugin.build();
.select()
.paths(regex(DEFAULT_INCLUDE_PATTERN)) // and by paths
.build();
watch.stop();
log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
return swaggerSpringMvcPlugin;
Expand All @@ -63,11 +65,12 @@ public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin(SpringSwaggerConfig springS
*/
private ApiInfo apiInfo() {
return new ApiInfo(
propertyResolver.getProperty("title"),
propertyResolver.getProperty("description"),
propertyResolver.getProperty("termsOfServiceUrl"),
propertyResolver.getProperty("contact"),
propertyResolver.getProperty("license"),
propertyResolver.getProperty("licenseUrl"));
propertyResolver.getProperty("title"),
propertyResolver.getProperty("description"),
propertyResolver.getProperty("version"),
propertyResolver.getProperty("termsOfServiceUrl"),
propertyResolver.getProperty("contact"),
propertyResolver.getProperty("license"),
propertyResolver.getProperty("licenseUrl"));
}
}
3 changes: 1 addition & 2 deletions app/templates/src/main/resources/_logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
<logger name="org.springframework.cache" level="WARN"/>
<logger name="org.thymeleaf" level="WARN"/>
<logger name="org.xnio" level="WARN"/>
<logger name="com.mangofactory.swagger" level="WARN"/>
<logger name="com.wordnik.swagger" level="WARN"/><% if (databaseType == 'sql') { %>
<logger name="springfox" level="WARN"/><% if (databaseType == 'sql') { %>
<logger name="liquibase" level="WARN"/><% } %>
<logger name="sun.rmi.transport" level="WARN"/>

Expand Down
1 change: 1 addition & 0 deletions app/templates/src/main/resources/config/_application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ authentication:<% if (authenticationType == 'xauth') { %>
swagger:
title: <%=baseName%> API
description: <%=baseName%> applications and beyond!
version: 0.0.1
termsOfServiceUrl: http://jhipster.github.io/
contact:
license: Apache 2.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<iframe src="swagger-ui/index.html" frameborder="0" marginheight="0" marginwidth="0"
<iframe src="swagger-ui.html" frameborder="0" marginheight="0" marginwidth="0"
width="100%" height="900" scrolling="auto" target='_top'></iframe>
74 changes: 0 additions & 74 deletions app/templates/src/main/webapp/swagger-ui/_index.html

This file was deleted.

Binary file not shown.
1 change: 1 addition & 0 deletions app/templates/src/test/resources/config/_application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ metrics:
swagger:
apiDocsLocation: http://localhost:8080
title: jhipster API
version: 0.0.1
description: jhipster applications and beyond!
termsOfServiceUrl: http://jhipster.github.io/
contact:
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,5 @@
"node": ">=0.12.0",
"npm": ">=1.4.0"
},
"licenses": [
{
"type": "Apache 2.0"
}
]
"license": "Apache-2.0"
}
2 changes: 0 additions & 2 deletions test/test-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ describe('JHipster generator ', function () {
'src/main/webapp/i18n/fr/global.json',
'src/main/webapp/i18n/fr/health.json',
'src/main/resources/i18n/messages_fr.properties',
'src/main/webapp/swagger-ui/index.html',
'src/main/webapp/swagger-ui/images/throbber.gif',
'src/main/webapp/scripts/app/app.js',
'src/main/webapp/scripts/components/admin/audits.service.js',
'src/main/webapp/scripts/components/admin/configuration.service.js',
Expand Down

0 comments on commit 111ceb7

Please sign in to comment.