Skip to content

Commit

Permalink
Merge pull request OpenLiberty#4 from navidsh/info-reader
Browse files Browse the repository at this point in the history
Changed the annotation reader logic for Info annotation
  • Loading branch information
arturdzm authored Jan 16, 2018
2 parents d7252ba + 519b3b5 commit d04297c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ public static Optional<Info> getInfo(org.eclipse.microprofile.openapi.annotation
if (info == null) {
return Optional.empty();
}

boolean isEmpty = true;
Info infoObject = new InfoImpl();
if (StringUtils.isNotBlank(info.description())) {
Expand All @@ -389,11 +390,16 @@ public static Optional<Info> getInfo(org.eclipse.microprofile.openapi.annotation
infoObject.setVersion(info.version());
isEmpty = false;
}

getContact(info.contact()).ifPresent(infoObject::setContact);
isEmpty &= infoObject.getContact() == null;

getLicense(info.license()).ifPresent(infoObject::setLicense);
isEmpty &= infoObject.getLicense() == null;

if (isEmpty) {
return Optional.empty();
}
getContact(info.contact()).ifPresent(infoObject::setContact);
getLicense(info.license()).ifPresent(infoObject::setLicense);

return Optional.of(infoObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,15 @@ public OpenAPI read(Class<?> cls, String parentPath) {
// OpenApiDefinition
OpenAPIDefinition openAPIDefinition = ReflectionUtils.getAnnotation(cls, OpenAPIDefinition.class);

// If there are more than one openAPIDefinition annotation is present across the app, there is no
// guarantee which one is picked.
if (openAPIDefinition != null) {

// info
AnnotationsUtils.getInfo(openAPIDefinition.info()).ifPresent(info -> openAPI.setInfo(info));

// OpenApiDefinition security requirements
SecurityParser.getSecurityRequirements(openAPIDefinition.security()).ifPresent(s -> openAPI.setSecurity(s));
//

// OpenApiDefinition external docs
AnnotationsUtils.getExternalDocumentation(openAPIDefinition.externalDocs()).ifPresent(docs -> openAPI.setExternalDocs(docs));

Expand All @@ -253,7 +254,6 @@ public OpenAPI read(Class<?> cls, String parentPath) {

// OpenApiDefinition servers
AnnotationsUtils.getServers(openAPIDefinition.servers()).ifPresent(servers -> openAPI.setServers(servers));

}

// class security schemes
Expand Down

0 comments on commit d04297c

Please sign in to comment.