Skip to content

Commit

Permalink
add summary attribute on Info annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-confino committed May 9, 2024
1 parent 763f097 commit 6a43ff0
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 0 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 @@ -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 @@ -297,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

0 comments on commit 6a43ff0

Please sign in to comment.