Repository: swagger-api/swagger-parser
Pull request #1453 (2020-10-08 06:28:58)

Fix for issue-1419
Fix for issue-1419.
The issue here is that when enum field is having an array value, It is getting logged as error.
This was fixed as the missing condition was handled. The value is currently saved as string. 


Patch:
diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
index 55a6dfdc..b88b9887 100644
--- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
+++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java
@@ -2285,7 +2285,12 @@ public class OpenAPIDeserializer {
                     catch( ParseException e) {
                         result.invalidType( location, String.format( "enum=`%s`", e.getMessage()), schema.getFormat(), n);
                     }
-                } else {
+                } else if (n.isArray()) {
+                    for (JsonNode n1 : (ArrayNode)n) {
+                        schema.addEnumItemObject(String.valueOf(n1));
+                    }
+                }
+                else {
                     result.invalidType(location, "enum", "value", n);
                 }
             }


Test patch:
diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
index 95767742..a560af9e 100644
--- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
+++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java
@@ -2617,4 +2617,21 @@ public class OpenAPIV3ParserTest {
         Assert.assertNotNull(cat);
     }
 
+    @Test
+    public void testParser() {
+
+        OpenAPIV3Parser parser = new OpenAPIV3Parser();
+        ParseOptions options =  new ParseOptions();
+        options.setResolve(Boolean.TRUE);
+        final SwaggerParseResult result = parser.readLocation("src/test/resources/issue-1419.yaml", null, options);
+        System.out.println(result.getMessages());
+        Assert.assertNotNull(result);
+        ArraySchema schema   = (ArraySchema) result.getOpenAPI().getComponents().getSchemas().get("Vehicle").getProperties().get("arrayG");
+        ArraySchema schema1 = (ArraySchema) schema.getItems();
+        ArrayList enum1 = (ArrayList) schema1.getEnum();
+
+        Assert.assertEquals(enum1.get(0),"[[1,2],[2,6]]");
+
+    }
+
 }
diff --git a/modules/swagger-parser-v3/src/test/resources/issue-1419.yaml b/modules/swagger-parser-v3/src/test/resources/issue-1419.yaml
new file mode 100644
index 00000000..e04c366c
--- /dev/null
+++ b/modules/swagger-parser-v3/src/test/resources/issue-1419.yaml
@@ -0,0 +1,158 @@
+{
+  "openapi": "3.0.0",
+  "servers": [{
+                "description": "Production environment",
+                "url": "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry"
+              },
+              {
+                "description": "Test environment",
+                "url": "https://uat.driver-vehicle-licensing.api.gov.uk/vehicle-enquiry"
+              }
+  ],
+  "info": {
+    "contact": {
+      "email": "DvlaAPIAccess@dvla.gov.uk",
+      "name": "DVLA API Team",
+      "x-twitter": "GDSTeam"
+    },
+    "description": "Interface specification for the DVLA Vehicle Enquiry API",
+    "title": "Vehicle Enquiry",
+    "version": "1.1.0",
+    "x-apisguru-categories": [
+      "open_data"
+    ],
+    "x-logo": {
+      "url": "https://api.apis.guru/v2/cache/logo/https_twitter.com_GDSTeam_profile_image.png"
+    },
+    "x-origin": [{
+                   "format": "openapi",
+                   "url": "https://developer-portal.driver-vehicle-licensing.api.gov.uk/apis/vehicle-enquiry-service/v1.1.0-vehicle-enquiry-service.json",
+                   "version": "3.0"
+                 }],
+    "x-preferred": true,
+    "x-providerName": "api.gov.uk",
+    "x-serviceName": "vehicle-enquiry"
+  },
+  "tags": [{
+             "name": "vehicle"
+           }],
+  "paths": {
+    "/v1/vehicles": {
+      "post": {
+        "description": "Returns vehicle details based on registration number",
+        "operationId": "getVehicleDetailsByRegistrationNumber",
+        "parameters": [{
+                         "description": "Client Specific API Key",
+                         "in": "header",
+                         "name": "x-api-key",
+                         "required": true,
+                         "schema": {
+                           "type": "string"
+                         }
+                       },
+                       {
+                         "description": "Consumer Correlation ID",
+                         "in": "header",
+                         "name": "X-Correlation-Id",
+                         "required": false,
+                         "schema": {
+                           "type": "string"
+                         }
+                       }
+        ],
+        "requestBody": {
+          "content": {
+            "application/json": {
+              "schema": {
+                "$ref": "#/components/schemas/Vehicle"
+              }
+            }
+          },
+          "description": "Registration number of the vehicle to find details for",
+          "required": true
+        },
+        "responses": {
+          "200": {
+            "content": {
+              "application/json": {
+
+              }
+            },
+            "description": "Successful response"
+          },
+          "400": {
+
+            "description": "Bad Request"
+          }
+        },
+        "summary": "Get vehicle details by registration number",
+        "tags": [
+          "vehicle"
+        ]
+      }
+    }
+  },
+  "components": {
+    "schemas": {
+
+      "Vehicle": {
+        "properties": {
+          "arrayA": {
+            "type": "array",
+            "items": {
+
+            }
+          },
+
+          "arrayG": {
+            "type": "array",
+            "items": {
+              "type": "array",
+              "items": {
+                "type": "integer",
+                "format": "int32",
+                "minimum": 12,
+                "maximum": 24,
+                "nullable": true,
+                "exclusiveMinimum": true,
+                "exclusiveMaximum": true,
+                "enum": [1, 2],
+                "default": 1
+
+              },
+              "enum": [
+              [
+              [
+              [1, 2],
+              [2, 6]
+              ]
+              ]
+              ]
+            }
+          },
+          "arrayH": {
+            "type": "array",
+            "items": {
+              "type": "array",
+              "items": {
+                "type": "string",
+                "nullable": true,
+                "enum": ["1", "2"]
+
+              },
+              "enum": [
+              ["1", "2"],
+              ["3", "2"]
+              ]
+            }
+
+
+
+
+
+          }
+        }
+      }
+    }
+  }
+}
\ No newline at end of file