Skip to content

Commit

Permalink
Merge pull request #1815 from benjamin-confino/schema-model-3.1-benja…
Browse files Browse the repository at this point in the history
…min-2

Support summary attribute on Info annotation
  • Loading branch information
MikeEdgar authored May 10, 2024
2 parents 918393e + 6a43ff0 commit 73183db
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 2 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/io/smallrye/openapi/api/OpenApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ default String getInfoTermsOfService() {
return getConfigValue(SmallRyeOASConfig.INFO_TERMS, String.class, () -> null);
}

default String getInfoSummary() {
return getConfigValue(SmallRyeOASConfig.INFO_SUMMARY, String.class, () -> null);
}

default String getInfoContactEmail() {
return getConfigValue(SmallRyeOASConfig.INFO_CONTACT_EMAIL, String.class, () -> null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private SmallRyeOASConfig() {
public static final String INFO_TITLE = SMALLRYE_PREFIX + "info.title";
public static final String INFO_VERSION = SMALLRYE_PREFIX + "info.version";
public static final String INFO_DESCRIPTION = SMALLRYE_PREFIX + "info.description";
public static final String INFO_SUMMARY = SMALLRYE_PREFIX + "info.summary";
public static final String INFO_TERMS = SMALLRYE_PREFIX + "info.termsOfService";
public static final String INFO_CONTACT_EMAIL = SMALLRYE_PREFIX + "info.contact.email";
public static final String INFO_CONTACT_NAME = SMALLRYE_PREFIX + "info.contact.name";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class InfoImpl extends ExtensibleImpl<Info> implements Info, ModelImpl {
private Contact contact;
private License license;
private String version;
private String summary;

/**
* @see org.eclipse.microprofile.openapi.models.info.Info#getTitle()
Expand Down Expand Up @@ -115,4 +116,20 @@ public void setVersion(String version) {
this.version = version;
}

/**
* @see org.eclipse.microprofile.openapi.models.info.Info#getSummary()
*/
@Override
public String getSummary() {
return summary;
}

/**
* @see org.eclipse.microprofile.openapi.models.info.Info#setSummary(java.lang.String)
*/
@Override
public void setSummary(String summary) {
this.summary = summary;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected static final void configureInfo(OpenApiConfig config, OpenAPI oai) {
setIfPresent(config.getInfoTitle(), oai.getInfo()::setTitle);
setIfPresent(config.getInfoVersion(), oai.getInfo()::setVersion);
setIfPresent(config.getInfoDescription(), oai.getInfo()::setDescription);
setIfPresent(config.getInfoSummary(), oai.getInfo()::setSummary);
setIfPresent(config.getInfoTermsOfService(), oai.getInfo()::setTermsOfService);

// Contact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class InfoIO<V, A extends V, O extends V, AB, OB> extends ModelIO<Info, V
private static final String PROP_DESCRIPTION = "description";
private static final String PROP_LICENSE = "license";
private static final String PROP_CONTACT = "contact";
private static final String PROP_SUMMARY = "summary";

public InfoIO(IOContext<V, A, O, AB, OB> context) {
super(context, Names.INFO, Names.create(Info.class));
Expand All @@ -30,6 +31,7 @@ public Info read(AnnotationInstance annotation) {
Info info = new InfoImpl();
info.setTitle(value(annotation, PROP_TITLE));
info.setDescription(value(annotation, PROP_DESCRIPTION));
info.setSummary(value(annotation, PROP_SUMMARY));
info.setTermsOfService(value(annotation, PROP_TERMS_OF_SERVICE));
info.setContact(contactIO().read(annotation.value(PROP_CONTACT)));
info.setLicense(licenseIO().read(annotation.value(PROP_LICENSE)));
Expand All @@ -50,6 +52,7 @@ public Info readObject(O node) {
Info info = new InfoImpl();
info.setTitle(jsonIO().getString(node, PROP_TITLE));
info.setDescription(jsonIO().getString(node, PROP_DESCRIPTION));
info.setSummary(jsonIO().getString(node, PROP_SUMMARY));
info.setTermsOfService(jsonIO().getString(node, PROP_TERMS_OF_SERVICE));
info.setContact(contactIO().readValue(jsonIO().getValue(node, PROP_CONTACT)));
info.setLicense(licenseIO().readValue(jsonIO().getValue(node, PROP_LICENSE)));
Expand All @@ -62,6 +65,7 @@ public Optional<O> write(Info model) {
return optionalJsonObject(model).map(node -> {
setIfPresent(node, PROP_TITLE, jsonIO().toJson(model.getTitle()));
setIfPresent(node, PROP_DESCRIPTION, jsonIO().toJson(model.getDescription()));
setIfPresent(node, PROP_SUMMARY, jsonIO().toJson(model.getSummary()));
setIfPresent(node, PROP_TERMS_OF_SERVICE, jsonIO().toJson(model.getTermsOfService()));
setIfPresent(node, PROP_CONTACT, contactIO().write(model.getContact()));
setIfPresent(node, PROP_LICENSE, licenseIO().write(model.getLicense()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ConfigExtensionsTest extends JaxRsDataObjectScannerTestBase {
private static final String TITLE = "mp.openapi.extensions.smallrye.info.title";
private static final String VERSION = "mp.openapi.extensions.smallrye.info.version";
private static final String DESCRIPTION = "mp.openapi.extensions.smallrye.info.description";
private static final String SUMMARY = "mp.openapi.extensions.smallrye.info.summary";
private static final String TERMS = "mp.openapi.extensions.smallrye.info.termsOfService";
private static final String CONTACT_EMAIL = "mp.openapi.extensions.smallrye.info.contact.email";
private static final String CONTACT_NAME = "mp.openapi.extensions.smallrye.info.contact.name";
Expand Down Expand Up @@ -85,10 +86,10 @@ void testSettingJustLicenseName() throws IOException, JSONException {

@Test
void testSettingAllInfo() throws IOException, JSONException {

System.setProperty(TITLE, "My own awesome REST service");
System.setProperty(VERSION, "1.2.3");
System.setProperty(DESCRIPTION, "This service is awesome");
System.setProperty(SUMMARY, "This summary is rather boring");
System.setProperty(TERMS, "The terms is also awesome");
System.setProperty(CONTACT_EMAIL, "phillip.kruger@redhat.com");
System.setProperty(CONTACT_NAME, "Phillip Kruger");
Expand All @@ -109,6 +110,7 @@ void testSettingAllInfo() throws IOException, JSONException {
System.clearProperty(TITLE);
System.clearProperty(VERSION);
System.clearProperty(DESCRIPTION);
System.clearProperty(SUMMARY);
System.clearProperty(TERMS);
System.clearProperty(CONTACT_EMAIL);
System.clearProperty(CONTACT_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"title" : "My own awesome REST service",
"description" : "This service is awesome",
"termsOfService" : "The terms is also awesome",
"summary" : "This summary is rather boring",
"contact" : {
"name" : "Phillip Kruger",
"url" : "https://www.phillip-kruger.com",
Expand Down Expand Up @@ -182,4 +183,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Configs implements SmallryeOpenApiProperties {
final Property<String> infoTitle;
final Property<String> infoVersion;
final Property<String> infoDescription;
final Property<String> infoSummary;
final Property<String> infoTermsOfService;
final Property<String> infoContactEmail;
final Property<String> infoContactName;
Expand Down Expand Up @@ -84,6 +85,7 @@ class Configs implements SmallryeOpenApiProperties {
infoTitle = objects.property(String.class);
infoVersion = objects.property(String.class);
infoDescription = objects.property(String.class);
infoSummary = objects.property(String.class);
infoTermsOfService = objects.property(String.class);
infoContactEmail = objects.property(String.class);
infoContactName = objects.property(String.class);
Expand Down Expand Up @@ -119,6 +121,7 @@ class Configs implements SmallryeOpenApiProperties {
infoTitle = objects.property(String.class).convention(ext.getInfoTitle());
infoVersion = objects.property(String.class).convention(ext.getInfoVersion());
infoDescription = objects.property(String.class).convention(ext.getInfoDescription());
infoSummary = objects.property(String.class).convention(ext.getInfoSummary());
infoTermsOfService = objects.property(String.class).convention(ext.getInfoTermsOfService());
infoContactEmail = objects.property(String.class).convention(ext.getInfoContactEmail());
infoContactName = objects.property(String.class).convention(ext.getInfoContactName());
Expand Down Expand Up @@ -177,6 +180,7 @@ private Map<String, String> getProperties() {
addToPropertyMap(cp, SmallRyeOASConfig.INFO_TITLE, infoTitle);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_VERSION, infoVersion);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_DESCRIPTION, infoDescription);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_SUMMARY, infoSummary);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_TERMS, infoTermsOfService);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_CONTACT_EMAIL, infoContactEmail);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_CONTACT_NAME, infoContactName);
Expand Down Expand Up @@ -289,6 +293,10 @@ public Property<String> getInfoDescription() {
return infoDescription;
}

public Property<String> getInfoSummary() {
return infoSummary;
}

public Property<String> getInfoTermsOfService() {
return infoTermsOfService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public interface SmallryeOpenApiProperties {

Property<String> getInfoDescription();

Property<String> getInfoSummary();

Property<String> getInfoTermsOfService();

Property<String> getInfoContactEmail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ public Property<String> getInfoTermsOfService() {
return properties.infoTermsOfService;
}

@Input
@Optional
@Override
public Property<String> getInfoSummary() {
return properties.infoSummary;
}

@Input
@Optional
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void taskPropertiesInheritance() {
ext.infoLicenseUrl.set("info-license-url");
ext.infoTermsOfService.set("info-tos");
ext.infoTitle.set("info-title");
ext.infoSummary.set("info-summary");
ext.infoVersion.set("info-version");
ext.modelReader.set("model-reader");
ext.operationIdStrategy.set(OperationIdStrategy.CLASS_METHOD);
Expand Down Expand Up @@ -112,6 +113,7 @@ void taskPropertiesInheritance() {
SmallryeOpenApiProperties::getInfoDescription,
SmallryeOpenApiProperties::getInfoLicenseName,
SmallryeOpenApiProperties::getInfoLicenseUrl,
SmallryeOpenApiProperties::getInfoSummary,
SmallryeOpenApiProperties::getInfoTermsOfService,
SmallryeOpenApiProperties::getInfoTitle,
SmallryeOpenApiProperties::getInfoVersion,
Expand Down Expand Up @@ -199,6 +201,7 @@ void smokeProject(Path buildDir, boolean withQuarkus, String taskName, String ou
" infoVersion.set(\"Info Version\")",
" infoDescription.set(\"Info Description\")",
" infoTermsOfService.set(\"Info TOS\")",
" infoSummary.set(\"Info Summary\")",
" infoContactEmail.set(\"Info Email\")",
" infoContactName.set(\"Info Contact\")",
" infoContactUrl.set(\"https://github.com/smallrye/smallrye-open-api/issues/1231\")",
Expand Down Expand Up @@ -294,6 +297,7 @@ private static void checkGeneratedFiles(Path buildDir, String expectedOutputFile
assertThat(info).isNotNull();
assertThat(info.get("title").asText()).isEqualTo("Info Title");
assertThat(info.get("description").asText()).isEqualTo("Info Description");
assertThat(info.get("summary").asText()).isEqualTo("Info Summary");
assertThat(info.get("termsOfService").asText()).isEqualTo("Info TOS");
assertThat(info.get("version").asText()).isEqualTo("Info Version");
assertThat(info.get("contact").get("email").asText()).isEqualTo("Info Email");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ public class GenerateSchemaMojo extends AbstractMojo {
@Parameter(property = "infoDescription")
private String infoDescription;

@Parameter(property = "infoSummary")
private String infoSummary;

@Parameter(property = "infoTermsOfService")
private String infoTermsOfService;

Expand Down Expand Up @@ -357,6 +360,7 @@ private Map<String, String> getProperties() throws IOException {
addToPropertyMap(cp, SmallRyeOASConfig.INFO_TITLE, infoTitle);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_VERSION, infoVersion);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_DESCRIPTION, infoDescription);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_SUMMARY, infoSummary);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_TERMS, infoTermsOfService);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_CONTACT_EMAIL, infoContactEmail);
addToPropertyMap(cp, SmallRyeOASConfig.INFO_CONTACT_NAME, infoContactName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void basic_info(MavenExecutionResult result) throws IOException {
assertEquals(properties.get("infoTitle"), schema.getInfo().getTitle());
assertEquals(properties.get("infoDescription"), schema.getInfo().getDescription());
assertEquals(properties.get("infoTermsOfService"), schema.getInfo().getTermsOfService());
assertEquals(properties.get("infoSummary"), schema.getInfo().getSummary());
assertEquals(properties.get("infoContactName"), schema.getInfo().getContact().getName());
assertEquals(properties.get("infoContactUrl"), schema.getInfo().getContact().getUrl());
assertEquals(properties.get("infoContactEmail"), schema.getInfo().getContact().getEmail());
Expand Down

0 comments on commit 73183db

Please sign in to comment.