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
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ void validateServers(List<String> serversFromOperation, String operationId) {
if (!asyncApiServers.containsKey(server)) {
throw new IllegalArgumentException(
"Operation '%s' defines unknown server ref '%s'. This AsyncApi defines these server(s): %s"
.formatted(operationId, server, asyncApiServers.keySet()));
.formatted(
operationId,
server,
asyncApiServers.keySet().stream()
.sorted()
.toList()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import io.github.springwolf.asyncapi.v3.model.server.Server;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;
import org.springframework.http.MediaType;

import java.util.Map;
Expand All @@ -15,6 +14,7 @@
public class AsyncApiDocket {

/**
* <b>Required.</b>
* The base package(s) containing the declarations of consumers and producer beans.
* Comma-separated for multiple base packages.
*/
Expand All @@ -31,21 +31,20 @@ public class AsyncApiDocket {
/**
* Provides connection details of servers.
*/
@Singular
private final Map<String, Server> servers;

/**
* A string representing the default content type to use when encoding/decoding a message's payload.
*
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v2.0.0#defaultContentTypeString">Default Content Type</a>
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v3.0.0#defaultContentTypeString">Default Content Type</a>
*/
@Builder.Default
private final String defaultContentType = MediaType.APPLICATION_JSON_VALUE;

/**
* A string representing the default content type to use when encoding/decoding a message's payload.
*
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v2.0.0#A2SIdString">Identifier</a>
* @see <a href="https://www.asyncapi.com/docs/reference/specification/v3.0.0#A2SIdString">Identifier</a>
*/
private final String id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ private AsyncApiDocket createDocket() {

AsyncApiDocket.AsyncApiDocketBuilder builder = AsyncApiDocket.builder()
.basePackage(configProperties.getDocket().getBasePackage())
.info(buildInfo(configProperties.getDocket().getInfo()))
.servers(buildServers(configProperties.getDocket().getServers()));

.info(buildInfo(configProperties.getDocket().getInfo()));
if (configProperties.getDocket().getServers() != null) {
builder.servers(buildServers(configProperties.getDocket().getServers()));
}
if (configProperties.getDocket().getId() != null) {
builder.id(configProperties.getDocket().getId());
}
Expand All @@ -68,10 +69,7 @@ private static Info buildInfo(@Nullable SpringwolfConfigProperties.ConfigDocket.
}

private static Map<String, Server> buildServers(Map<String, Server> servers) {
if (servers == null || servers.isEmpty()) {
throw new IllegalArgumentException("No server has been defined in application.properties "
+ "with path prefix " + SPRINGWOLF_CONFIG_PREFIX);
} else {
if (servers != null) {
servers.forEach((serverName, server) -> {
if (!StringUtils.hasText(server.getProtocol()) || !StringUtils.hasText(server.getHost())) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.github.springwolf.asyncapi.v3.model.info.Info;
import io.github.springwolf.asyncapi.v3.model.operation.Operation;
import io.github.springwolf.asyncapi.v3.model.operation.OperationAction;
import io.github.springwolf.asyncapi.v3.model.server.Server;
import io.github.springwolf.asyncapi.v3.model.server.ServerReference;
import io.github.springwolf.core.asyncapi.annotations.AsyncOperation;
import io.github.springwolf.core.asyncapi.scanners.bindings.channels.ChannelBindingProcessor;
Expand Down Expand Up @@ -111,7 +112,7 @@ void scan() throws Exception {
}

@Nested
class Server {
class ServersField {
@Test
void scan() throws Exception {
// given
Expand All @@ -124,7 +125,7 @@ void scan() throws Exception {
.thenReturn(Operation.builder().title("operationId").build());
AsyncApiDocket docket = AsyncApiDocket.builder()
.info(Info.builder().build())
.server("server1", null)
.servers(Map.of("server1", Server.builder().build()))
.build();
when(asyncApiDocketService.getAsyncApiDocket()).thenReturn(docket);

Expand Down Expand Up @@ -158,8 +159,11 @@ void scanInvalid() throws Exception {
.thenReturn(Operation.builder().title("operationId").build());
AsyncApiDocket docket = AsyncApiDocket.builder()
.info(Info.builder().build())
.server("server1", null)
.server("server2", null)
.servers(Map.of(
"server1",
Server.builder().build(),
"server2",
Server.builder().build()))
.build();
when(asyncApiDocketService.getAsyncApiDocket()).thenReturn(docket);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
"springwolf.docket.info.version=1.0.0",
"springwolf.docket.info.extension-fields.x-api-name=api-name",
"springwolf.docket.base-package=io.github.springwolf.core.example",
"springwolf.docket.servers.test-protocol.protocol=test",
"springwolf.docket.servers.test-protocol.host=some-server:1234"
})
class DefaultAsyncApiDocketServiceIntegrationTest {
@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.util.Maps.newHashMap;

class DefaultAsyncApiDocketServiceTest {

Expand All @@ -28,10 +27,6 @@ void serviceShouldMapAllPropertiesToTheDocket() {

configDocket.setDefaultContentType("application/json");

Server server =
Server.builder().protocol("some-protocol").host("some-url").build();
configDocket.setServers(newHashMap("some-protocol", server));

ConfigDocket.Info info = new ConfigDocket.Info();
info.setTitle("some-title");
info.setVersion("some-version");
Expand Down Expand Up @@ -78,10 +73,6 @@ void docketServiceShouldDeliverCachedDocket() {
info.setVersion("some-version");
configDocket.setInfo(info);

Server server =
Server.builder().protocol("some-protocol").host("some-url").build();
configDocket.setServers(newHashMap("some-protocol", server));

SpringwolfConfigProperties configProperties = new SpringwolfConfigProperties();
configProperties.setDocket(configDocket);

Expand All @@ -106,10 +97,6 @@ void setUp() {
validDocket = new ConfigDocket();
validDocket.setBasePackage("test-base-package");

Server server =
Server.builder().protocol("some-protocol").host("some-url").build();
validDocket.setServers(newHashMap("some-protocol", server));

ConfigDocket.Info info = new ConfigDocket.Info();
info.setTitle("some-title");
info.setVersion("some-version");
Expand Down Expand Up @@ -164,25 +151,15 @@ void missingInfoVersion(String value) {
"One or more required fields of the info object (title, version) in application.properties with path prefix springwolf is not set.");
}

@Test
void missingServers() {
// given
validDocket.getServers().clear();

// when
assertThatThrownBy(docketService::getAsyncApiDocket)
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(
"No server has been defined in application.properties with path prefix springwolf");
}

@ParameterizedTest
@CsvSource(
value = {"''", "null"},
nullValues = {"null"})
void missingServerProtocol(String value) {
// given
validDocket.getServers().forEach((k, v) -> v.setProtocol(value));
validDocket.setServers(Map.of(
"some-protocol",
Server.builder().protocol(value).host("some-url").build()));

// when
assertThatThrownBy(docketService::getAsyncApiDocket)
Expand All @@ -197,7 +174,9 @@ void missingServerProtocol(String value) {
nullValues = {"null"})
void missingServerHost(String value) {
// given
validDocket.getServers().forEach((k, v) -> v.setHost(value));
validDocket.setServers(Map.of(
"some-protocol",
Server.builder().protocol("some-protocol").host(value).build()));

// when
assertThatThrownBy(docketService::getAsyncApiDocket)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ void docketServersTest() {
@Nested
@ExtendWith(SpringExtension.class)
@EnableConfigurationProperties(SpringwolfConfigProperties.class)
@TestPropertySource(
properties = {
"springwolf.enabled=true",
"springwolf.docket.info.title=Info title was loaded from spring properties",
"springwolf.docket.info.version=1.0.0",
"springwolf.docket.info.extension-fields.x-api-name=api-name",
"springwolf.docket.base-package=io.github.springwolf.core.example",
"springwolf.docket.servers.test-protocol.protocol=test",
"springwolf.docket.servers.test-protocol.host=some-server:1234",
})
class PayloadWithoutCustomizingIntegrationTest {

@Autowired
Expand All @@ -103,17 +93,7 @@ void payloadTest() {
@Nested
@ExtendWith(SpringExtension.class)
@EnableConfigurationProperties(SpringwolfConfigProperties.class)
@TestPropertySource(
properties = {
"springwolf.enabled=true",
"springwolf.docket.info.title=Info title was loaded from spring properties",
"springwolf.docket.info.version=1.0.0",
"springwolf.docket.info.extension-fields.x-api-name=api-name",
"springwolf.docket.base-package=io.github.springwolf.core.example",
"springwolf.docket.servers.test-protocol.protocol=test",
"springwolf.docket.servers.test-protocol.host=some-server:1234",
"springwolf.payload.extractable-classes.my.custom.class=1"
})
@TestPropertySource(properties = {"springwolf.payload.extractable-classes.my.custom.class=1"})
class PayloadWithCustomizingIntegrationTest {

@Autowired
Expand All @@ -139,17 +119,7 @@ void payloadCustomizedTest() {
@Nested
@ExtendWith(SpringExtension.class)
@EnableConfigurationProperties(SpringwolfConfigProperties.class)
@TestPropertySource(
properties = {
"springwolf.enabled=true",
"springwolf.docket.info.title=Info title was loaded from spring properties",
"springwolf.docket.info.version=1.0.0",
"springwolf.docket.info.extension-fields.x-api-name=api-name",
"springwolf.docket.base-package=io.github.springwolf.core.example",
"springwolf.docket.servers.test-protocol.protocol=test",
"springwolf.docket.servers.test-protocol.host=some-server:1234",
"springwolf.payload.extractable-classes.java.util.List=-1"
})
@TestPropertySource(properties = {"springwolf.payload.extractable-classes.java.util.List=-1"})
class PayloadDisabledIntegrationTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@
"springwolf.docket.id=urn:io:github:springwolf:example",
"springwolf.docket.default-content-type=application/json",
"springwolf.docket.base-package=io.github.springwolf.core.integrationtests.application.basic",
"springwolf.docket.servers.test-protocol.protocol=test",
"springwolf.docket.servers.test-protocol.host=some-server:1234",
})
public @interface MinimalIntegrationTestContextConfiguration {}
2 changes: 0 additions & 2 deletions springwolf-core/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ springwolf.docket.base-package=io.github.springwolf.core.integrationtests
springwolf.docket.info.title=${spring.application.name}
springwolf.docket.info.version=1.0.0
springwolf.docket.info.description=Springwolf core integration test
springwolf.docket.servers.test-protocol.protocol=property-protocol
springwolf.docket.servers.test-protocol.host=some-property-server:1234
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
"x-generator": "springwolf"
},
"defaultContentType": "application/json",
"servers": {
"test-protocol": {
"host": "some-server:1234",
"protocol": "test"
}
},
"channels": {
"listener-channel": {
"address": "listener-channel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
"x-generator": "springwolf"
},
"defaultContentType": "application/json",
"servers": {
"test-protocol": {
"host": "some-server:1234",
"protocol": "test"
}
},
"channels": {
"listener-channel": {
"address": "listener-channel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
"x-generator": "springwolf"
},
"defaultContentType": "application/json",
"servers": {
"test-protocol": {
"host": "some-property-server:1234",
"protocol": "property-protocol"
}
},
"channels": {
"listener-channel": {
"address": "listener-channel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
"x-generator": "springwolf"
},
"defaultContentType": "application/json",
"servers": {
"test-protocol": {
"host": "some-property-server:1234",
"protocol": "property-protocol"
}
},
"channels": {
"listener-channel": {
"address": "listener-channel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
"x-generator": "springwolf"
},
"defaultContentType": "application/json",
"servers": {
"test-protocol": {
"host": "some-server:1234",
"protocol": "test"
}
},
"channels": {
"listener-channel": {
"address": "listener-channel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
"x-generator": "springwolf"
},
"defaultContentType": "application/json",
"servers": {
"test-protocol": {
"host": "some-server:1234",
"protocol": "test"
}
},
"channels": {
"publisher-channel": {
"address": "publisher-channel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
"x-generator": "springwolf"
},
"defaultContentType": "application/json",
"servers": {
"test-protocol": {
"host": "some-server:1234",
"protocol": "test"
}
},
"channels": {
"enum-channel": {
"address": "enum-channel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class SpringContextIntegrationTest {
"springwolf.docket.info.title=Info title was loaded from spring properties",
"springwolf.docket.info.version=1.0.0",
"springwolf.docket.base-package=io.github.springwolf.examples",
"springwolf.docket.servers.test-protocol.protocol=amqp",
"springwolf.docket.servers.test-protocol.host=some-server:1234",
})
@ActiveProfiles("test")
class ApplicationPropertiesConfigurationTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class SpringContextIntegrationTest {
"springwolf.docket.info.title=Info title was loaded from spring properties",
"springwolf.docket.info.version=1.0.0",
"springwolf.docket.base-package=io.github.springwolf.examples",
"springwolf.docket.servers.test-protocol.protocol=kafka",
"springwolf.docket.servers.test-protocol.host=some-server:1234",
})
class ApplicationPropertiesConfigurationTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class SpringContextIntegrationTest {
"springwolf.docket.info.title=Info title was loaded from spring properties",
"springwolf.docket.info.version=1.0.0",
"springwolf.docket.base-package=io.github.springwolf.examples",
"springwolf.docket.servers.test-protocol.protocol=kafka",
"springwolf.docket.servers.test-protocol.host=some-server:1234",
})
class ApplicationPropertiesConfigurationTest {

Expand Down
Loading
Loading