Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(swagger): Upgrade SpringFox and Swagger #827

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,13 +16,10 @@

package com.netflix.spinnaker.config;

import static com.google.common.base.Predicates.or;

import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand All @@ -32,11 +29,9 @@
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.paths.AbstractPathProvider;
import springfox.documentation.spring.web.paths.DefaultPathProvider;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the (very light on detail) migration instructions here: https://github.com/springfox/springfox#migrating-from-existing-2x-version

@Configuration
@ConditionalOnProperty("swagger.enabled")
@ConfigurationProperties(prefix = "swagger")
Expand Down Expand Up @@ -80,7 +75,7 @@ private static Class<?> getClassIfPresent(String name) {
}

private Predicate<String> paths() {
return or(patterns.stream().map(PathSelectors::regex).collect(Collectors.toList()));
return patterns.stream().map(PathSelectors::regex).reduce(x -> false, Predicate::or);
}

private ApiInfo apiInfo() {
Expand Down Expand Up @@ -123,7 +118,8 @@ public String getDocumentationPath() {
return documentationPath;
}

public class BasePathProvider extends AbstractPathProvider {
// TODO: make sure this works given https://github.com/springfox/springfox/issues/3493
public class BasePathProvider extends DefaultPathProvider {
private String basePath;
private String documentationPath;

Expand All @@ -133,13 +129,13 @@ private BasePathProvider(String basePath, String documentationPath) {
}

@Override
protected String applicationPath() {
Copy link
Contributor Author

@luispollo luispollo Dec 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They deprecated AbstractPathProvider in this version, and the docs are not great around path customization, so this is my current guess as to what needs to change, but needs testing. If anyone knows what effect basePath had in the original implementation, please let me know.

return basePath;
public String getOperationPath(String operationPath) {
return documentationPath + "/" + super.getOperationPath(operationPath);
}

@Override
protected String getDocumentationPath() {
return documentationPath;
public String getResourceListingPath(String groupName, String apiDeclaration) {
return documentationPath + "/" + super.getResourceListingPath(groupName, apiDeclaration);
}
}
}
6 changes: 3 additions & 3 deletions spinnaker-dependencies/spinnaker-dependencies.gradle
Expand Up @@ -25,8 +25,8 @@ ext {
spring : "5.2.9.RELEASE", // this should be kept in sync with spring-boot / removed once the need for a version override is gone
springBoot : "2.2.5.RELEASE",
springCloud : "Hoxton.SR4",
springfoxSwagger : "2.9.2",
swagger : "1.5.20" //this should stay in sync with what springfoxSwagger expects
springfoxSwagger : "3.0.0",
swagger : "2.1.2" //this should stay in sync with what springfoxSwagger expects
]
}

Expand Down Expand Up @@ -127,7 +127,7 @@ dependencies {
api("io.mockk:mockk:1.10.0")
api("io.springfox:springfox-swagger-ui:${versions.springfoxSwagger}")
api("io.springfox:springfox-swagger2:${versions.springfoxSwagger}")
api("io.swagger:swagger-annotations:${versions.swagger}")
api("io.swagger.core.v3:swagger-annotations:${versions.swagger}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may break services using annotations, I'm not sure yet. Second thing to verify. SpringFox uses different deps for v2 and v3: https://github.com/springfox/springfox/blob/9722b7e3a41208bc3e7c0409aa3e63fc27a66f52/gradle/dependencies.gradle#L61-L68

api("javax.annotation:javax.annotation-api:1.3.2")
api("javax.xml.bind:jaxb-api:2.3.1")
api("mysql:mysql-connector-java:8.0.20")
Expand Down