Skip to content

Commit

Permalink
Merge pull request #6 from jarlehansen/release-1.2.0
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
jarlehansen committed May 31, 2017
2 parents d2ed8b3 + db5597e commit 639f1c8
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 324 deletions.
19 changes: 6 additions & 13 deletions README.md
Expand Up @@ -13,7 +13,6 @@ __Features:__
* Support for using Spring placeholder values `${...}` in the configuration
* Easy to extend by using the standard Springfox classes
* Convention based naming of values displayed in swagger-ui, minimizing the need for manual configuration
* Can display all the `@Value` annotations used, with the key and the default value

---

Expand All @@ -36,7 +35,7 @@ The jar-file available in [JCenter](https://bintray.com/jarlehansen/maven/spring

_build.gradle_
```groovy
compile('com.github.springfox.loader:springfox-loader:1.1.2')
compile('com.github.springfox.loader:springfox-loader:1.2.0')
```

### Maven
Expand Down Expand Up @@ -84,7 +83,6 @@ __Full example__
```java
@EnableSpringfox(
conventionMode = false,
listValueProps = true,
swaggerUiBasePath = "",
includeControllers = MyController.class,
value = @Info(
Expand All @@ -93,15 +91,17 @@ __Full example__
description = "",
termsOfService = "",
contact = @Contact(name = "", url = "", email = ""),
license = @License(name = "", url = ""))
)
license = @License(name = "", url = ""),
extensions = @Extension(name = "x-test",
properties = @ExtensionProperty(name = "test-key", value = "test-value")
))
)
```

* Use __conventionMode__ to print better names on the swagger-ui page. It will alter the tags (the name of the groups).
It will remove _Controller_ at the end of the text if it is present. Additionally, it will split the operation name by
replacing camelcase with space and uppercasing the word (for example the method `getCustomer()` will be displayed as `Get customer`).
If the `@ApiOperation` annotation is present, these values will be used.
* __listValueProps__ is used to enable an endpoint that will display all the `@Value`-annotations (key and default value) used in the application. The endpoint is displayed in swagger-ui as 'Value-properties'. By default this is disabled.
* __swaggerUiBasePath__ customize the base path to swagger-ui. If the value is for example '/documentation', the path to swagger-ui will be '/documentation/swagger-ui.html'.
* __includeControllers__ add controllers to the swagger configuration that is not registered in the default base package (which is based on the Application class).

Expand All @@ -126,7 +126,6 @@ __Application properties__
* springfox.license.url
* springfox.activeProfiles - _Enable springfox for the configured profiles. If not set, all profiles loads springfox. Default is all profiles._
* springfox.swagger-ui-base-path
* springfox.endpoints - _Enables springfox-loader endpoints, see [Springfox loader endpoints](#springfox-loader-endpoints) for more details_

### Swagger UI

Expand All @@ -150,12 +149,6 @@ public void init() {
}
```

### Springfox loader endpoints

`GET /springfox-loader/api-docs`

Returns the swagger api-docs with [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) enabled.

### References
* [Springfox Reference Documentation](http://springfox.github.io/springfox/docs/current/)
* [Swagger Core Annotations](https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X)
21 changes: 8 additions & 13 deletions pom.xml
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.springfox.loader</groupId>
<artifactId>springfox-loader</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
Expand All @@ -15,7 +15,6 @@
<cglib.version>3.2.5</cglib.version>
<jackson.version>2.8.8</jackson.version>
<lombok.version>1.16.16</lombok.version>
<reflections.version>0.9.11</reflections.version>
<guava.version>22.0</guava.version>
<jsonpath.version>2.2.0</jsonpath.version>

Expand Down Expand Up @@ -63,28 +62,24 @@
<version>${spring.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>${reflections.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${jsonpath.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${jsonpath.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
Expand Down Expand Up @@ -144,7 +139,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<version>2.20</version>
<configuration>
<includes>
<include>**/*Spec.java</include>
Expand Down
Expand Up @@ -21,8 +21,6 @@

boolean conventionMode() default true;

boolean listValueProps() default false;

Class<?>[] includeControllers() default {};

}
Expand Up @@ -103,10 +103,6 @@ boolean conventionMode() {
return annotation.conventionMode();
}

boolean listValueProps() {
return annotation.listValueProps();
}

String swaggerUiBasePath() {
return val(annotation.swaggerUiBasePath(), loaderProps.getSwaggerUiBasePath());
}
Expand Down
Expand Up @@ -2,8 +2,6 @@

import com.github.springfox.loader.plugins.LoaderOperationPlugin;
import com.github.springfox.loader.plugins.LoaderTagProvider;
import com.github.springfox.loader.valueproperties.ValuePropertiesController;
import com.github.springfox.loader.valueproperties.ValuePropertiesLocator;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import org.springframework.beans.BeansException;
Expand All @@ -30,7 +28,6 @@
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.spring.web.readers.operation.DefaultTagsProvider;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -42,23 +39,11 @@
@ComponentScan(basePackageClasses = SpringfoxLoaderConfig.class)
public class SpringfoxLoaderConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware, EmbeddedValueResolverAware {

@Autowired
private ValuePropertiesController valuePropertiesController;

private SpringfoxLoader springfoxLoader = new SpringfoxLoader();
private ValuePropertiesLocator valuePropertiesLocator;

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
springfoxLoader.setApplicationContext(applicationContext);
if (springfoxLoader.listValueProps()) {
valuePropertiesLocator = new ValuePropertiesLocator(springfoxLoader.getBasePackage());
}
}

@PostConstruct
public void init() {
valuePropertiesController.setValuePropertiesLocator(valuePropertiesLocator);
}

@Override
Expand All @@ -76,11 +61,6 @@ public void setSpringfoxLoaderProps(SpringfoxLoaderProps loaderProps) {
public Docket api() {
ApiSelectorBuilder apiSelectorBuilder = new Docket(DocumentationType.SWAGGER_2).select();
Predicate<RequestHandler> predicate = RequestHandlerSelectors.basePackage(springfoxLoader.getBasePackage())::apply;
if (springfoxLoader.listValueProps()) {
Predicate<RequestHandler> listPropertiesRequestHandler = RequestHandlerSelectors.basePackage(ValuePropertiesController.class.getPackage().getName())::apply;
predicate = predicate.or(listPropertiesRequestHandler);
}

if (springfoxLoader.includeControllers().length > 0) {
Class<?>[] controllers = springfoxLoader.includeControllers();
for (Class<?> controller : controllers) {
Expand Down Expand Up @@ -108,12 +88,10 @@ private List<VendorExtension> getVendorExtensions() {

return Arrays.stream(extensions).map(extension -> {
ExtensionProperty[] extensionProperties = extension.properties();
List<StringVendorExtension> vendorExtensions = Arrays.stream(extensionProperties).map(property -> new StringVendorExtension(property.name(), property.value())).collect(Collectors.toList());

List<StringVendorExtension> vendorExtensions = Arrays.stream(extensionProperties)
.map(property -> new StringVendorExtension(property.name(), property.value())).collect(Collectors.toList());
ObjectVendorExtension vendorExtension = new ObjectVendorExtension(extension.name());
for (StringVendorExtension stringVendorExtension : vendorExtensions) {
vendorExtension.addProperty(stringVendorExtension);
}
vendorExtensions.forEach(vendorExtension::addProperty);
return vendorExtension;
}).collect(Collectors.toList());
}
Expand All @@ -131,10 +109,6 @@ public LoaderOperationPlugin loaderOperationPlugin() {
return new LoaderOperationPlugin(springfoxLoader.conventionMode());
}

ValuePropertiesLocator valuePropertiesLocator() {
return valuePropertiesLocator;
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
if (!StringUtils.isEmpty(springfoxLoader.swaggerUiBasePath())) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 639f1c8

Please sign in to comment.