This repository has been archived by the owner on Jun 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3133dd
commit 6497c49
Showing
16 changed files
with
202 additions
and
41 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...main/java/io/springside/springtime/examples/helloservice/service/GreetingServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
springtime/src/main/java/io/springside/springtime/springboot/EnableSpringTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.springside.springtime.springboot; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import org.springframework.context.annotation.Import; | ||
|
||
@Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME) | ||
@Target(value = { java.lang.annotation.ElementType.TYPE }) | ||
@Documented | ||
@Import({SpringTimeConfiguration.class}) | ||
public @interface EnableSpringTime { | ||
|
||
} |
15 changes: 3 additions & 12 deletions
15
springtime/src/main/java/io/springside/springtime/springboot/SpringTimeConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,15 @@ | ||
package io.springside.springtime.springboot; | ||
|
||
import static springfox.documentation.builders.PathSelectors.*; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import com.google.common.base.Predicates; | ||
|
||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import io.springside.springtime.swagger.SpringFoxConfiguration; | ||
|
||
@ComponentScan | ||
@Configuration | ||
@Import(SpringFoxConfiguration.class) | ||
public class SpringTimeConfiguration { | ||
|
||
@Bean | ||
public Docket swaggerSpringMvcPlugin() { | ||
return new Docket(DocumentationType.SWAGGER_2).groupName("business-api").select().paths(Predicates.not(regex("/manage.*"))) // and by paths | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
springtime/src/main/java/io/springside/springtime/springboot/SpringTimeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.springside.springtime.springboot; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Component | ||
public @interface SpringTimeService { | ||
/** | ||
* The value may indicate a suggestion for a logical component name, | ||
* to be turned into a Spring bean in case of an autodetected component. | ||
* @return the suggested component name, if any | ||
*/ | ||
String value() default ""; | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
springtime/src/main/java/io/springside/springtime/swagger/SpringFoxConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.springside.springtime.swagger; | ||
|
||
import static springfox.documentation.builders.PathSelectors.*; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.google.common.base.Predicates; | ||
|
||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
|
||
@ComponentScan | ||
@Configuration | ||
public class SpringFoxConfiguration { | ||
|
||
//TODO: manage路径从Spring里读 | ||
@Bean | ||
public Docket swaggerSpringMvcPlugin() { | ||
return new Docket(DocumentationType.SWAGGER_2).groupName("restful-api").select() | ||
.paths(Predicates.not(regex("/manage.*"))).build(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...gtime/src/main/java/io/springside/springtime/swagger/SpringTimeSwaggerDocsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.springside.springtime.swagger; | ||
|
||
import static org.springframework.http.MediaType.*; | ||
|
||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationContextAware; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.springside.springtime.springboot.SpringTimeService; | ||
import io.swagger.jaxrs.Reader; | ||
import io.swagger.jaxrs.config.ReaderConfigUtils; | ||
import io.swagger.models.Info; | ||
import io.swagger.models.Swagger; | ||
import springfox.documentation.annotations.ApiIgnore; | ||
|
||
@RestController | ||
@ApiIgnore | ||
public class SpringTimeSwaggerDocsController implements InitializingBean, ApplicationContextAware { | ||
private Swagger swagger; | ||
|
||
private ApplicationContext applicationContext; | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
swagger = new Swagger(); | ||
Info info = new Info(); | ||
info.setTitle("GreetingService"); | ||
swagger.setInfo(info); | ||
|
||
Map<String, Object> beans = applicationContext.getBeansWithAnnotation(SpringTimeService.class); | ||
Set<Class<?>> classes = new HashSet<Class<?>>(); | ||
for (Object bean : beans.values()) { | ||
classes.add(bean.getClass()); | ||
} | ||
|
||
Reader reader = new Reader(swagger, ReaderConfigUtils.getReaderConfig(null)); | ||
swagger = reader.read(classes); | ||
} | ||
|
||
@RequestMapping(value = "/v2/rfc-api-docs", method = RequestMethod.GET, produces = { APPLICATION_JSON_VALUE }) | ||
public @ResponseBody Swagger getDocumentation(HttpServletRequest servletRequest) { | ||
return swagger; | ||
} | ||
|
||
@Override | ||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
this.applicationContext = applicationContext; | ||
|
||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
springtime/src/main/java/io/springside/springtime/swagger/SpringTimeSwaggerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.springside.springtime.swagger; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.stereotype.Component; | ||
|
||
import springfox.documentation.spring.web.DocumentationCache; | ||
import springfox.documentation.swagger.web.InMemorySwaggerResourcesProvider; | ||
import springfox.documentation.swagger.web.SwaggerResource; | ||
|
||
@Component | ||
@Primary | ||
public class SpringTimeSwaggerProvider extends InMemorySwaggerResourcesProvider { | ||
|
||
public SpringTimeSwaggerProvider(DocumentationCache documentationCache) { | ||
super(documentationCache); | ||
} | ||
|
||
@Override | ||
public List<SwaggerResource> get() { | ||
List<SwaggerResource> resources = super.get(); | ||
SwaggerResource springTimeResource = new SwaggerResource(); | ||
springTimeResource.setName("SpringTime"); | ||
springTimeResource.setLocation("/v2/rfc-api-docs"); | ||
resources.add(0, springTimeResource); | ||
return resources; | ||
} | ||
|
||
} |