From 519b3b5adc45aa0e590acd971e60f4cdff2d3829 Mon Sep 17 00:00:00 2001 From: Navid Shakibapour Date: Tue, 16 Jan 2018 14:01:43 -0500 Subject: [PATCH] Changed the annotation reader logic for Info annotation Signed-off-by: Navid Shakibapour --- .../openapi/impl/core/util/AnnotationsUtils.java | 10 ++++++++-- .../ws/microprofile/openapi/impl/jaxrs2/Reader.java | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dev/com.ibm.ws.microprofile.openapi/src/com/ibm/ws/microprofile/openapi/impl/core/util/AnnotationsUtils.java b/dev/com.ibm.ws.microprofile.openapi/src/com/ibm/ws/microprofile/openapi/impl/core/util/AnnotationsUtils.java index 5e522114948..1805d68b93d 100644 --- a/dev/com.ibm.ws.microprofile.openapi/src/com/ibm/ws/microprofile/openapi/impl/core/util/AnnotationsUtils.java +++ b/dev/com.ibm.ws.microprofile.openapi/src/com/ibm/ws/microprofile/openapi/impl/core/util/AnnotationsUtils.java @@ -371,6 +371,7 @@ public static Optional getInfo(org.eclipse.microprofile.openapi.annotation if (info == null) { return Optional.empty(); } + boolean isEmpty = true; Info infoObject = new InfoImpl(); if (StringUtils.isNotBlank(info.description())) { @@ -389,11 +390,16 @@ public static Optional 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); } diff --git a/dev/com.ibm.ws.microprofile.openapi/src/com/ibm/ws/microprofile/openapi/impl/jaxrs2/Reader.java b/dev/com.ibm.ws.microprofile.openapi/src/com/ibm/ws/microprofile/openapi/impl/jaxrs2/Reader.java index 89bcf869449..d66eb7a16be 100644 --- a/dev/com.ibm.ws.microprofile.openapi/src/com/ibm/ws/microprofile/openapi/impl/jaxrs2/Reader.java +++ b/dev/com.ibm.ws.microprofile.openapi/src/com/ibm/ws/microprofile/openapi/impl/jaxrs2/Reader.java @@ -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)); @@ -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