Commit 3cfdd633 authored by Matija Obreza's avatar Matija Obreza

Swagger: split v1 (default) and v0 documentation

- URL replaced with String
parent a082e049
......@@ -16,21 +16,24 @@
package org.genesys2.spring.config;
import static com.google.common.collect.Lists.newArrayList;
import static springfox.documentation.builders.PathSelectors.ant;
import static springfox.documentation.builders.PathSelectors.regex;
import static springfox.documentation.builders.PathSelectors.*;
import static springfox.documentation.schema.AlternateTypeRules.newRule;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.google.common.base.Predicate;
import com.fasterxml.classmate.TypeResolver;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.AuthorizationCodeGrantBuilder;
import springfox.documentation.builders.OAuthBuilder;
import springfox.documentation.schema.AlternateTypeRule;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
......@@ -57,11 +60,24 @@ public class SwaggerConfig {
@Value("${build.version}")
private String version;
private TypeResolver resolver = new TypeResolver();
public SwaggerConfig() {
System.err.println("Making SwaggerConfig!");
}
private AlternateTypeRule[] alternateTypes() {
return new AlternateTypeRule[] {
// URL as String
newRule(URL.class, String.class),
newRule(resolver.arrayType(URL.class), resolver.arrayType(String.class)),
newRule(resolver.resolve(List.class, URL.class), resolver.resolve(List.class, String.class)),
newRule(resolver.resolve(Set.class, URL.class), resolver.resolve(Set.class, String.class))
// Other..
};
}
/**
* Every Docket bean is picked up by the swagger-mvc framework - allowing for
* multiple swagger groups i.e. same code base multiple swagger resource
......@@ -70,19 +86,40 @@ public class SwaggerConfig {
* @return Docket
*/
@Bean
public Docket apiDocket() {
public Docket apiV0Docket() {
return new Docket(DocumentationType.SWAGGER_2).host(hostAndPort)
// .protocols(newHashSet("http", "https"))
// Paths
.select().paths(apiPaths()).build()
.select().paths(regex("/api/v0/.+")).build()
// General info
.apiInfo(apiInfo())
.groupName("v0")
// Alternative types
.alternateTypeRules(alternateTypes())
// Security
.securitySchemes(newArrayList(oauthClientCredentials(), oauthAuthorizationCode(), oauthUserPassword(), apiKey())).securityContexts(newArrayList(securityContext()));
}
private Predicate<String> apiPaths() {
return regex("/api/v.*");
/**
* Every Docket bean is picked up by the swagger-mvc framework - allowing for
* multiple swagger groups i.e. same code base multiple swagger resource
* listings.
*
* @return Docket
*/
@Bean
public Docket apiV1Docket() {
return new Docket(DocumentationType.SWAGGER_2).host(hostAndPort)
// .protocols(newHashSet("http", "https"))
// Paths
.select().paths(regex("/api/v1/.+")).build()
// General info
.apiInfo(apiInfo())
.groupName("default")
// Alternative types
.alternateTypeRules(alternateTypes())
// Security
.securitySchemes(newArrayList(oauthClientCredentials(), oauthAuthorizationCode(), oauthUserPassword(), apiKey())).securityContexts(newArrayList(securityContext()));
}
private ApiInfo apiInfo() {
......@@ -102,7 +139,7 @@ public class SwaggerConfig {
// }
SecurityScheme oauthAuthorizationCode() {
return new OAuthBuilder().name("Other clients").grantTypes(newArrayList(new AuthorizationCodeGrantBuilder()
return new OAuthBuilder().name("authorizationCode").grantTypes(newArrayList(new AuthorizationCodeGrantBuilder()
// token request
.tokenRequestEndpoint(new TokenRequestEndpoint("//" + hostAndPort + "/oauth/authorize", "client_id", "client_secret"))
// token endpoint
......@@ -112,12 +149,12 @@ public class SwaggerConfig {
}
SecurityScheme oauthClientCredentials() {
return new OAuthBuilder().name("OAuth Client Credentials").grantTypes(newArrayList(new ClientCredentialsGrant("//" + hostAndPort + "/oauth/token"))).scopes(newArrayList(
return new OAuthBuilder().name("clientCredentials").grantTypes(newArrayList(new ClientCredentialsGrant("//" + hostAndPort + "/oauth/token"))).scopes(newArrayList(
scopes())).build();
}
SecurityScheme oauthUserPassword() {
return new OAuthBuilder().name("Resource Owner").grantTypes(newArrayList(new ResourceOwnerPasswordCredentialsGrant("//" + hostAndPort + "/oauth/token"))).scopes(
return new OAuthBuilder().name("usernamePassword").grantTypes(newArrayList(new ResourceOwnerPasswordCredentialsGrant("//" + hostAndPort + "/oauth/token"))).scopes(
newArrayList(scopes())).build();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment