Skip to content
Merged
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
1 change: 1 addition & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/wcc
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: MFpFnhhICniFNPA
SPRING_APP_BASE_URL: http://localhost:8080
networks:
- app-network

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.wcc.platform.configuration;

import com.wcc.platform.domain.platform.config.PlatformServers;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.models.OpenAPI;
Expand All @@ -11,6 +10,7 @@
import java.util.stream.IntStream;
import org.springdoc.core.customizers.OpenApiCustomizer;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand All @@ -27,6 +27,9 @@ public class OpenApiConfig implements WebMvcConfigurer {
private static final String ACTUATOR = "actuator";
private static final String ACTUATOR_SPRING = "Spring Boot Actuator";

@Value("${backend.app.url}")
private String appBaseUrl;

private static Consumer<Tag> renameActuator() {
return tag -> {
if (ACTUATOR.equalsIgnoreCase(tag.getName())) {
Expand Down Expand Up @@ -58,9 +61,7 @@ public GroupedOpenApi publicApi() {
/** Customize servers for open API. */
@Bean
public OpenAPI customOpenApi() {
return new OpenAPI()
.addServersItem(new Server().url(PlatformServers.DEV.getUri()).description("Dev"))
.addServersItem(new Server().url(PlatformServers.LOCAL.getUri()).description("Localhost"));
return new OpenAPI().addServersItem(new Server().url(appBaseUrl));
}

/** Customize Actuator endpoint tag. */
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/wcc/platform/configuration/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.wcc.platform.configuration.converter.StringToEnumConverter;
import com.wcc.platform.configuration.converter.StringToEnumConverterFactory;
import com.wcc.platform.domain.platform.config.PlatformServers;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
Expand All @@ -12,11 +12,14 @@
@Configuration
public class WebConfig implements WebMvcConfigurer {

@Value("${backend.app.url}")
private String appBaseUrl;

@Override
public void addCorsMappings(final CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOrigins(PlatformServers.LOCAL.getUri(), PlatformServers.DEV.getUri())
.allowedOrigins(appBaseUrl)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*");
}
Expand Down

This file was deleted.

4 changes: 4 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ spring:
timeout: 5000
writetimeout: 5000

backend:
app:
url: ${SPRING_APP_BASE_URL:http://localhost:8080}

mentorship:
daysCycleOpen: 10
validation:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.wcc.platform.configuration;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import io.swagger.v3.oas.models.OpenAPI;
import java.lang.reflect.Field;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class OpenApiConfigTest {

private OpenApiConfig config;

@BeforeEach
void setUp() throws Exception {
config = new OpenApiConfig();
// set the private appBaseUrl field used by customOpenApi()
Field f = OpenApiConfig.class.getDeclaredField("appBaseUrl");
f.setAccessible(true);
f.set(config, "https://example.com/base");
}

@Test
void customOpenApi_setsServerUrlFromAppBaseUrl() {
OpenAPI openAPI = config.customOpenApi();
assertNotNull(openAPI);

// verify there's a server with the configured URL
assertNotNull(openAPI.getServers());
assertEquals("https://example.com/base", openAPI.getServers().get(0).getUrl());
}
}
Loading