Skip to content

Commit

Permalink
[ISSUE-2992][Improve] Using code style & quality rules to improve org…
Browse files Browse the repository at this point in the history
….apache.streampark.console.base.config package of streampark-console module. (#3012)

* extract string as constant

* code style format

* define it directly instead of using constants

* code correction

* Update OpenapiConfig.java

* Update WebMvcConfig.java

---------

Co-authored-by: lihui <[email protected]>
Co-authored-by: benjobs <[email protected]>
  • Loading branch information
3 people authored Sep 10, 2023
1 parent 0d61f5d commit 65d968f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@
@ConditionalOnWebApplication
public class OpenapiConfig implements WebMvcConfigurer {

private static final String OPEN_API_INFO_OVERVIEW = "Apache StreamPark Api Docs";
private static final String OPEN_API_INFO_VERSION = "2.2.0-SNAPSHOT";
private static final String OPEN_API_INFO_LICENSE_NAME = "Apache-2.0 license";
private static final String OPEN_API_INFO_CONTACT_NAME = "Apache StreamPark";
private static final String OPEN_API_INFO_CONTACT_URL = "https://streampark.apache.org";
private static final String OPEN_API_INFO_CONTACT_EMAIL = "[email protected]";

@Bean
public OpenAPI apiV1Info() {
return new OpenAPI()
.info(
new Info()
.title("Apache StreamPark Api Docs")
.description("Apache StreamPark Api Docs")
.title(OPEN_API_INFO_OVERVIEW)
.description(OPEN_API_INFO_OVERVIEW)
.contact(
new Contact()
.name("Apache StreamPark")
.url("https://streampark.apache.org/")
.email("[email protected]"))
.version("2.2.0-SNAPSHOT")
.license(new License().name("Apache-2.0 license")))
.name(OPEN_API_INFO_CONTACT_NAME)
.url(OPEN_API_INFO_CONTACT_URL)
.email(OPEN_API_INFO_CONTACT_EMAIL))
.version(OPEN_API_INFO_VERSION)
.license(new License().name(OPEN_API_INFO_LICENSE_NAME)))
.components(
new Components()
.addSecuritySchemes(
Expand All @@ -76,4 +83,5 @@ public GroupedOpenApi publicApiV1() {
public GroupedOpenApi publicApiV2() {
return GroupedOpenApi.builder().group("v2").pathsToMatch("/v2/**").build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.ResourceHttpMessageConverter;
Expand All @@ -41,6 +42,14 @@ public class WebMvcConfig implements WebMvcConfigurer {

@Autowired private UploadFileTypeInterceptor uploadFileTypeInterceptor;

private static final String[] CORS_MAPPINGS_ALLOWED_METHODS = {
HttpMethod.POST.name(),
HttpMethod.GET.name(),
HttpMethod.PUT.name(),
HttpMethod.OPTIONS.name(),
HttpMethod.DELETE.name()
};

@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new ByteArrayHttpMessageConverter());
Expand All @@ -54,7 +63,7 @@ public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
.allowedMethods(CORS_MAPPINGS_ALLOWED_METHODS)
.allowedHeaders("*")
.allowCredentials(true)
.maxAge(3600);
Expand All @@ -72,4 +81,5 @@ public Module jacksonModule() {
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(uploadFileTypeInterceptor).addPathPatterns("/flink/app/upload");
}

}

0 comments on commit 65d968f

Please sign in to comment.