Skip to content

Commit

Permalink
feat(swagger): Upgrade to swagger and migrate to springdocs (#1198) (#…
Browse files Browse the repository at this point in the history
…1218)

Co-authored-by: Cameron Motevasselani <cmotevasselani@gmail.com>
Co-authored-by: Christos Arvanitis <christos.arvanitis@armory.io>
(cherry picked from commit f07cba2)

Co-authored-by: Jason <jason.mcintosh@armory.io>
  • Loading branch information
mergify[bot] and jasonmcintosh authored Jan 6, 2025
1 parent 6d13c51 commit 0dd06bb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 148 deletions.
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 @@ -21,18 +21,15 @@ ext {
logback : "1.2.13",
protobuf : "3.25.2",
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 @@ -157,9 +154,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 @@ -211,6 +207,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

0 comments on commit 0dd06bb

Please sign in to comment.