Skip to content

Commit

Permalink
Upgrade the swagger to OAS3.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergii-iakovenko committed Jul 16, 2022
1 parent 89c7a0b commit b7cd749
Show file tree
Hide file tree
Showing 66 changed files with 798 additions and 878 deletions.
3 changes: 1 addition & 2 deletions src-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ subprojects {
testImplementation 'io.grpc:grpc-testing:1.43.2'
implementation 'com.google.protobuf:protobuf-java-util:3.19.2'

implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
implementation 'org.springdoc:springdoc-openapi-ui:1.4.8'

implementation 'com.esotericsoftware:kryo:5.2.1'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
"http://checkstyle.sourceforge.net/dtds/suppressions_1_2.dtd">

<suppressions>
<suppress files="src/main/java/org/openkilda/grpc/speaker/GrpcSpeaker.java" checks="HideUtilityClassConstructor"/>
</suppressions>
7 changes: 3 additions & 4 deletions src-java/grpc-speaker/grpc-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ configurations {

description = 'GRPC service'
dependencies {
implementation(platform('org.springframework:spring-framework-bom:5.2.19.RELEASE'))
implementation(platform('org.springframework:spring-framework-bom:5.2.22.RELEASE'))
implementation(platform('org.springframework.boot:spring-boot-dependencies:2.2.13.RELEASE'))

implementation project(':grpc-api')
Expand Down Expand Up @@ -51,8 +51,7 @@ dependencies {
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.commons:commons-lang3'
implementation 'com.sabre.oss.conf4j:conf4j-spring-boot'
implementation 'io.springfox:springfox-swagger2'
implementation 'io.springfox:springfox-swagger-ui'
implementation 'org.springdoc:springdoc-openapi-ui'
implementation files('lib/noviflow-grpc-lib-1.0.jar')
//system group: 'io.grpc.noviflow', name: 'noviflow-grpc-lib', version:'1.0'

Expand All @@ -78,7 +77,7 @@ compileJava {
}

bootJar {
mainClassName = 'org.openkilda.grpc.speaker.GrpcSpeaker'
mainClassName = 'org.openkilda.grpc.speaker.GrpcSpeakerApplication'
archiveFileName = "${archivesBaseName}.${archiveExtension.get()}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"http://checkstyle.sourceforge.net/dtds/suppressions_1_2.dtd">

<suppressions>
<suppress files="src/main/java/org/openkilda/grpc/speaker/GrpcSpeaker.java" checks="HideUtilityClassConstructor"/>
<suppress files="src/main/java/org/openkilda/grpc/speaker/GrpcSpeakerApplication.java" checks="HideUtilityClassConstructor"/>
</suppressions>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2017 Telstra Open Source
/* Copyright 2022 Telstra Open Source
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,24 +13,16 @@
* limitations under the License.
*/

package org.openkilda.northbound;

import org.openkilda.northbound.config.AppConfig;
package org.openkilda.grpc.speaker;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;

/**
* The Application.
*/
@SpringBootApplication
public class Application {
/**
* Main method to start the application.
*
* @param args application arguments
*/
@PropertySource("classpath:grpc-service.properties")
public class GrpcSpeakerApplication {
public static void main(String[] args) {
SpringApplication.run(AppConfig.class, args);
SpringApplication.run(GrpcSpeakerApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2019 Telstra Open Source
/* Copyright 2022 Telstra Open Source
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -26,23 +26,18 @@
import com.sabre.oss.conf4j.processor.ConfigurationValueProcessor;
import com.sabre.oss.conf4j.spring.annotation.ConfigurationType;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import java.util.List;

/**
* The Application configuration. This configuration is used for application run. It includes configs of different
* components via {@link Import} annotation.
* The Conf4J configuration.
*/
@Configuration
@ConfigurationType(name = "kafkaTopicsConfig", value = KafkaTopicsConfig.class)
@ConfigurationType(name = "kafkaGroupConfig", value = KafkaGrpcSpeakerConfig.class)
@ConfigurationType(EnvironmentConfig.class)
@ComponentScan({"org.openkilda.grpc.speaker"})
public class AppConfig {

public class Conf4jConfig {
@Bean(CONF4J_CONFIGURATION_VALUE_PROCESSORS)
List<ConfigurationValueProcessor> configurationValueProcessors(EnvironmentConfig environmentConfig) {
String namingPrefix = environmentConfig.getNamingPrefix();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.kafka.annotation.EnableKafka;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
Expand All @@ -45,7 +44,6 @@
*/
@Configuration
@EnableKafka
@PropertySource("classpath:grpc-service.properties")
public class MessageConsumerConfig {
/**
* Kafka queue poll timeout.
Expand Down Expand Up @@ -128,8 +126,7 @@ public Map<String, Object> consumerConfigs() {
@Bean
public ConsumerFactory<String, CommandMessage> consumerFactory() {
return new DefaultKafkaConsumerFactory<>(consumerConfigs(),
new StringDeserializer(), new ErrorHandlingDeserializer2(
new JsonDeserializer<>(CommandMessage.class)));
new StringDeserializer(), new ErrorHandlingDeserializer2(new JsonDeserializer<>(CommandMessage.class)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
Expand All @@ -42,7 +41,6 @@
* Kafka message producer configuration.
*/
@Configuration
@PropertySource("classpath:grpc-service.properties")
public class MessageProducerConfig {
/**
* Kafka bootstrap servers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,27 @@

package org.openkilda.grpc.speaker.config;

import com.google.common.base.Predicates;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
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.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
/**
* Swagger configuration.
*
* @return {@link Docket} instance
*/
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.any())
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
public OpenAPI apiInfo() {
return new OpenAPI()
.info(new Info().title("GRPC Speaker")
.description("GRPC Speaker for work with switches")
.version("1.0"));
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("GRPC Speaker")
.description("GRPC Speaker for work with switches")
.version("1.0")
@Bean
public GroupedOpenApi api() {
return GroupedOpenApi.builder()
.group("Grpc-Speaker-API")
.pathsToExclude("/error**")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2017 Telstra Open Source
/* Copyright 2022 Telstra Open Source
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
Expand All @@ -35,13 +34,19 @@
*/
@Configuration
@EnableWebSecurity
@PropertySource("classpath:grpc-service.properties")
public class SecurityConfig extends WebSecurityConfigurerAdapter {
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
/**
* Default role for admin user.
*/
private static final String DEFAULT_ROLE = "ADMIN";

private static final String[] EXCLUDE_PATTERNS = {
"/health-check",
// swagger related patterns
"/swagger*/**",
"/v3/api-docs/**"
};

/**
* The environment variable for username.
*/
Expand Down Expand Up @@ -96,7 +101,7 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests().antMatchers("/health-check").permitAll().and()
.authorizeRequests().antMatchers(EXCLUDE_PATTERNS).permitAll().and()
.authorizeRequests().anyRequest().fullyAuthenticated().and()
.httpBasic().authenticationEntryPoint(authenticationEntryPoint).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
import org.openkilda.grpc.speaker.service.HealthCheckService;
import org.openkilda.messaging.model.HealthCheck;

import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -33,7 +35,6 @@
* REST Controller for health-check request.
*/
@RestController
@PropertySource("classpath:grpc-service.properties")
public class HealthCheckController {
private static final Logger logger = LoggerFactory.getLogger(HealthCheckController.class);

Expand All @@ -45,8 +46,9 @@ public class HealthCheckController {
*
* @return health-check model entity
*/
@ApiOperation(value = "Gets health-check status", response = HealthCheck.class)
@GetMapping(value = "/health-check")
@Operation(summary = "Gets health-check status")
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = HealthCheck.class)))
public ResponseEntity<HealthCheck> getHealthCheck() {
logger.debug("getHealthCheck");

Expand Down
Loading

0 comments on commit b7cd749

Please sign in to comment.