cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [3/3] cxf git commit: [CXF-6695] Improving bean validation annotations support for @MatrixPatam and @BeanParam fields
Date Fri, 04 Dec 2015 09:27:52 GMT
[CXF-6695] Improving bean validation annotations support for @MatrixPatam and @BeanParam fields


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d2a2a249
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d2a2a249
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d2a2a249

Branch: refs/heads/3.0.x-fixes
Commit: d2a2a2494799becde52f50e3edfb80bfc79b4dda
Parents: 98f176f
Author: Francesco Chicchiriccò <ilgrosso@apache.org>
Authored: Fri Dec 4 10:27:24 2015 +0100
Committer: Francesco Chicchiriccò <ilgrosso@apache.org>
Committed: Fri Dec 4 10:27:24 2015 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/swagger/JaxRs2Extension.java      | 85 +++++++++-----------
 1 file changed, 37 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d2a2a249/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/JaxRs2Extension.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/JaxRs2Extension.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/JaxRs2Extension.java
index bba367f..fc76cfc 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/JaxRs2Extension.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/JaxRs2Extension.java
@@ -46,8 +46,8 @@ import io.swagger.converter.ModelConverters;
 import io.swagger.jaxrs.ext.AbstractSwaggerExtension;
 import io.swagger.jaxrs.ext.SwaggerExtension;
 import io.swagger.jaxrs.ext.SwaggerExtensions;
+import io.swagger.models.parameters.AbstractSerializableParameter;
 import io.swagger.models.parameters.Parameter;
-import io.swagger.models.properties.AbstractNumericProperty;
 import io.swagger.models.properties.ArrayProperty;
 import io.swagger.models.properties.Property;
 import io.swagger.models.properties.RefProperty;
@@ -80,6 +80,7 @@ public class JaxRs2Extension extends AbstractSwaggerExtension {
                 if (schema != null) {
                     mp.setProperty(schema);
                 }
+                applyBeanValidatorAnnotations(mp, annotations);
                 parameters.add(mp);
             } else if (annotation instanceof BeanParam) {
                 // Use Jackson's logic for processing Beans
@@ -163,72 +164,60 @@ public class JaxRs2Extension extends AbstractSwaggerExtension {
     /**
      * This is essentially a duplicate of {@link io.swagger.jackson.ModelResolver.applyBeanValidatorAnnotations}.
      *
-     * @param property
+     * @param parameter
      * @param annotations
      */
-    private void applyBeanValidatorAnnotations(final Parameter property, final List<Annotation>
annotations) {
+    private void applyBeanValidatorAnnotations(final Parameter parameter, final List<Annotation>
annotations) {
         Map<String, Annotation> annos = new HashMap<String, Annotation>();
         if (annotations != null) {
             for (Annotation annotation : annotations) {
                 annos.put(annotation.annotationType().getName(), annotation);
             }
         }
+
         if (annos.containsKey(NotNull.class.getName())) {
-            property.setRequired(true);
-        }
-        if (annos.containsKey(Min.class.getName()) && property instanceof AbstractNumericProperty)
{
-            Min min = (Min) annos.get(Min.class.getName());
-            AbstractNumericProperty ap = (AbstractNumericProperty) property;
-            ap.setMinimum(new Double(min.value()));
-        }
-        if (annos.containsKey(Max.class.getName()) && property instanceof AbstractNumericProperty)
{
-            Max max = (Max) annos.get(Max.class.getName());
-            AbstractNumericProperty ap = (AbstractNumericProperty) property;
-            ap.setMaximum(new Double(max.value()));
+            parameter.setRequired(true);
         }
-        if (annos.containsKey(Size.class.getName())) {
-            Size size = (Size) annos.get(Size.class.getName());
-            if (property instanceof AbstractNumericProperty) {
-                AbstractNumericProperty ap = (AbstractNumericProperty) property;
-                ap.setMinimum(new Double(size.min()));
-                ap.setMaximum(new Double(size.max()));
-            } else if (property instanceof StringProperty) {
-                StringProperty sp = (StringProperty) property;
-                sp.minLength(size.min());
-                sp.maxLength(size.max());
-            } else if (property instanceof ArrayProperty) {
-                ArrayProperty sp = (ArrayProperty) property;
-                sp.setMinItems(size.min());
-                sp.setMaxItems(size.max());
+
+        if (parameter instanceof AbstractSerializableParameter) {
+            AbstractSerializableParameter<?> serializable = (AbstractSerializableParameter<?>)
parameter;
+
+            if (annos.containsKey(Min.class.getName())) {
+                Min min = (Min) annos.get(Min.class.getName());
+                serializable.setMinimum(new Double(min.value()));
             }
-        }
-        if (annos.containsKey(DecimalMin.class.getName())) {
-            DecimalMin min = (DecimalMin) annos.get(DecimalMin.class.getName());
-            if (property instanceof AbstractNumericProperty) {
-                AbstractNumericProperty ap = (AbstractNumericProperty) property;
+            if (annos.containsKey(Max.class.getName())) {
+                Max max = (Max) annos.get(Max.class.getName());
+                serializable.setMaximum(new Double(max.value()));
+            }
+            if (annos.containsKey(Size.class.getName())) {
+                Size size = (Size) annos.get(Size.class.getName());
+
+                serializable.setMinimum(new Double(size.min()));
+                serializable.setMaximum(new Double(size.max()));
+
+                serializable.setMinItems(size.min());
+                serializable.setMaxItems(size.max());
+            }
+            if (annos.containsKey(DecimalMin.class.getName())) {
+                DecimalMin min = (DecimalMin) annos.get(DecimalMin.class.getName());
                 if (min.inclusive()) {
-                    ap.setMinimum(new Double(min.value()));
+                    serializable.setMinimum(new Double(min.value()));
                 } else {
-                    ap.setExclusiveMinimum(!min.inclusive());
+                    serializable.setExclusiveMinimum(!min.inclusive());
                 }
             }
-        }
-        if (annos.containsKey(DecimalMax.class.getName())) {
-            DecimalMax max = (DecimalMax) annos.get(DecimalMax.class.getName());
-            if (property instanceof AbstractNumericProperty) {
-                AbstractNumericProperty ap = (AbstractNumericProperty) property;
+            if (annos.containsKey(DecimalMax.class.getName())) {
+                DecimalMax max = (DecimalMax) annos.get(DecimalMax.class.getName());
                 if (max.inclusive()) {
-                    ap.setMaximum(new Double(max.value()));
+                    serializable.setMaximum(new Double(max.value()));
                 } else {
-                    ap.setExclusiveMaximum(!max.inclusive());
+                    serializable.setExclusiveMaximum(!max.inclusive());
                 }
             }
-        }
-        if (annos.containsKey(Pattern.class.getName())) {
-            Pattern pattern = (Pattern) annos.get(Pattern.class.getName());
-            if (property instanceof StringProperty) {
-                StringProperty ap = (StringProperty) property;
-                ap.setPattern(pattern.regexp());
+            if (annos.containsKey(Pattern.class.getName())) {
+                Pattern pattern = (Pattern) annos.get(Pattern.class.getName());
+                serializable.setPattern(pattern.regexp());
             }
         }
     }


Mime
View raw message