Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#395 support info-extensions definition in environment #401

Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -64,19 +64,25 @@ private AsyncApiDocket parseApplicationConfigProperties(SpringwolfConfigProperti
return builder.build();
}

private static Info buildInfo(@Nullable SpringwolfConfigProperties.ConfigDocket.Info info) {
tvahrst marked this conversation as resolved.
Show resolved Hide resolved
if (info == null || !StringUtils.hasText(info.getVersion()) || !StringUtils.hasText(info.getTitle())) {
private static Info buildInfo(@Nullable SpringwolfConfigProperties.ConfigDocket.Info configDocketInfo) {
if (configDocketInfo == null
|| !StringUtils.hasText(configDocketInfo.getVersion())
|| !StringUtils.hasText(configDocketInfo.getTitle())) {
throw new IllegalArgumentException("One or more required fields of the info object (title, version) "
+ "in application.properties with path prefix " + SpringwolfConfigConstants.SPRINGWOLF_CONFIG_PREFIX
+ " is not set.");
}

return Info.builder()
.version(info.getVersion())
.title(info.getTitle())
.description(info.getDescription())
.contact(info.getContact())
.license(info.getLicense())
Info asyncapiInfo = Info.builder()
.version(configDocketInfo.getVersion())
.title(configDocketInfo.getTitle())
.description(configDocketInfo.getDescription())
.contact(configDocketInfo.getContact())
.license(configDocketInfo.getLicense())
.build();

asyncapiInfo.setExtensionFields(configDocketInfo.getExtensionFields());
sam0r040 marked this conversation as resolved.
Show resolved Hide resolved

return asyncapiInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public static class Info {
@NestedConfigurationProperty
@Nullable
private License license;

@Nullable
protected Map<String, Object> extensionFields;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class DefaultAsyncApiDocketServiceIntegrationTest {
"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",
timonback marked this conversation as resolved.
Show resolved Hide resolved
"springwolf.docket.base-package=io.github.stavshamir.springwolf.example",
"springwolf.docket.servers.test-protocol.protocol=test",
"springwolf.docket.servers.test-protocol.url=some-server:1234"
Expand All @@ -46,6 +47,7 @@ void testDocketContentShouldBeLoadedFromProperties() {
AsyncApiDocket docket = asyncApiDocketService.getAsyncApiDocket();
assertThat(docket).isNotNull();
assertThat(docket.getInfo().getTitle()).isEqualTo("Info title was loaded from spring properties");
assertThat(docket.getInfo().getExtensionFields().get("x-api-name")).isEqualTo("api-name");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties.ConfigDocket.Info;
import org.junit.jupiter.api.Test;

import java.util.Map;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -35,15 +36,16 @@ void testConfigurationShouldMapAllPropertiesToTheDocket() {
info.setDescription("some-description");
info.setLicense(new License("license-name", "license-url"));
info.setContact(new Contact("contact-name", "contact-url", "contact-email"));
info.setExtensionFields(Map.of("x-api-name", "api-name"));
configDocket.setInfo(info);

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

// when
DefaultAsyncApiDocketService docketConfiguration =
DefaultAsyncApiDocketService asyncApiDocketService =
new DefaultAsyncApiDocketService(Optional.empty(), Optional.of(properties));
AsyncApiDocket asyncApiDocket = docketConfiguration.getAsyncApiDocket();
AsyncApiDocket asyncApiDocket = asyncApiDocketService.getAsyncApiDocket();

// then
assertThat(asyncApiDocket.getDefaultContentType()).isEqualTo(configDocket.getDefaultContentType());
Expand All @@ -53,6 +55,8 @@ void testConfigurationShouldMapAllPropertiesToTheDocket() {
assertThat(asyncApiDocket.getInfo().getDescription()).isEqualTo(info.getDescription());
assertThat(asyncApiDocket.getInfo().getLicense()).isEqualTo(info.getLicense());
assertThat(asyncApiDocket.getInfo().getContact()).isEqualTo(info.getContact());
assertThat(asyncApiDocket.getInfo().getExtensionFields().get("x-api-name"))
.isEqualTo("api-name");
}

@Test
Expand Down