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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(swagger): Upgrade to swagger and migrate to springdocs #1198

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions kork-swagger/kork-swagger.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ apply plugin: "java-library"
dependencies {
api(platform(project(":spinnaker-dependencies")))

api "io.swagger:swagger-annotations"

implementation "com.google.guava:guava"
implementation "org.springframework.boot:spring-boot-autoconfigure"
implementation "io.springfox:springfox-boot-starter"
implementation "org.springdoc:springdoc-openapi-ui"
implementation "org.springframework:spring-webmvc"

implementation "io.swagger.core.v3:swagger-annotations"
implementation "io.swagger.core.v3:swagger-core"
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@

package com.netflix.spinnaker.config;

import com.google.common.collect.ImmutableList;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import org.springdoc.core.SpringDocUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.paths.DefaultPathProvider;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@ConditionalOnProperty("swagger.enabled")
Expand All @@ -43,19 +41,21 @@ public class SwaggerConfig {
private String basePath = "";
private String documentationPath = "/";

private static final ImmutableList<String> IGNORED_CLASS_NAMES =
ImmutableList.of("groovy.lang.MetaClass");
private static final List<String> IGNORED_CLASS_NAMES = List.of("groovy.lang.MetaClass");

@Bean
public Docket gateApi() {
return new Docket(DocumentationType.SWAGGER_2)
.pathProvider(new BasePathProvider(documentationPath))
.select()
.apis(RequestHandlerSelectors.any())
.paths(paths())
.build()
.apiInfo(apiInfo())
.ignoredParameterTypes(ignoredClasses());
public OpenAPI gateApi() {
Arrays.stream((ignoredClasses()))
.forEach(
each -> {
SpringDocUtils.getConfig().addJavaTypeToIgnore(each);
});
return new OpenAPI()
.info(new Info().description(description).title(title).contact(new Contact().name(contact)))
.externalDocs(
new ExternalDocumentation()
.url("https://spinnaker.io")
.description("Spinnaker Documentation"));
}

private static Class[] ignoredClasses() {
Expand All @@ -74,14 +74,6 @@ private static Class<?> getClassIfPresent(String name) {
}
}

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

private ApiInfo apiInfo() {
return new ApiInfo(title, description, null, null, contact, null, null);
}

public void setTitle(String title) {
this.title = title;
}
Expand Down Expand Up @@ -117,17 +109,4 @@ public void setDocumentationPath(String documentationPath) {
public String getDocumentationPath() {
return documentationPath;
}

public class BasePathProvider extends DefaultPathProvider {
private String documentationPath;

private BasePathProvider(String documentationPath) {
this.documentationPath = documentationPath;
}

@Override
protected String getDocumentationPath() {
return documentationPath;
}
}
}
1 change: 0 additions & 1 deletion kork-swagger/src/main/resources/META-INF/spring.factories

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions kork-swagger/src/main/resources/static/swagger/index.html

This file was deleted.

13 changes: 5 additions & 8 deletions spinnaker-dependencies/spinnaker-dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ ext {
protobuf : "3.21.12",
okhttp : "2.7.5", // CVE-2016-2402
okhttp3 : "4.9.3",
openapi : "1.3.9", // this needs to be kept in sync with spring boot as it pulls in the spring-boot-dependencies BOM
restassured : "5.2.1", // spring boot 2.7.18 brings rest-assured 4.5.1. It uses groovy 3. Keep until spring boot >=3.0.13
openapi : "1.8.0",
retrofit : "1.9.0",
retrofit2 : "2.8.1",
spectator : "1.0.6",
spek : "1.1.5",
spek2 : "2.0.9",
springBoot : "2.7.18",
springCloud : "2021.0.8",
springfoxSwagger : "3.0.0",
swagger : "1.5.20", //this should stay in sync with what springfoxSwagger expects.

swagger : "2.2.22",
// 2.7.18 brings in 9.0.83, which fixes all CVEs to date (20-feb-24). Continue to pin.
// See https://tomcat.apache.org/security-9.html for latest security fixes.
tomcat : "9.0.83"
Expand Down Expand Up @@ -160,9 +157,8 @@ dependencies {
api("de.huxhorn.sulky:de.huxhorn.sulky.ulid:8.2.0")
api("dev.minutest:minutest:1.13.0")
api("io.mockk:mockk:1.10.5")
api("io.springfox:springfox-boot-starter:${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}")
api("io.swagger.core.v3:swagger-core:${versions.swagger}")
api("javax.annotation:javax.annotation-api:1.3.2")
api("javax.xml.bind:jaxb-api:2.3.1")
api("net.logstash.logback:logstash-logback-encoder:4.11")
Expand Down Expand Up @@ -214,6 +210,7 @@ dependencies {
api("org.yaml:snakeyaml:1.31")
api("org.springdoc:springdoc-openapi-webmvc-core:${versions.openapi}")
api("org.springdoc:springdoc-openapi-kotlin:${versions.openapi}")
api("org.springdoc:springdoc-openapi-ui:${versions.openapi}")
api("org.springframework.boot:spring-boot-configuration-processor:${versions.springBoot}")
api("org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.3.12.RELEASE")
api("org.springframework.security.extensions:spring-security-saml-dsl-core:1.0.5.RELEASE")
Expand Down
Loading