Repository: codekie/openapi-examples-validator
Pull request #40 (2020-02-24 14:00:31)

Fix jsonPath of `example`


Patch:
diff --git a/src/impl/v3/index.js b/src/impl/v3/index.js
index 0f39e57..86311d8 100644
--- a/src/impl/v3/index.js
+++ b/src/impl/v3/index.js
@@ -7,7 +7,7 @@ const { JSONPath: jsonPath } = require('jsonpath-plus'),
 
 // CONSTANTS
 
-const PATH__EXAMPLE = '$..responses..content.application/json.example..value',
+const PATH__EXAMPLE = '$..responses..content.application/json.example',
     PATH__EXAMPLES = '$..responses..content.application/json.examples..value',
     PROP__SCHEMA = 'schema',
     PROP__EXAMPLE = 'example',


Test patch:
diff --git a/test/data/v3/simple-api-with-example-and-examples.json b/test/data/v3/simple-api-with-example-and-examples.json
index b1f4887..f5fadae 100644
--- a/test/data/v3/simple-api-with-example-and-examples.json
+++ b/test/data/v3/simple-api-with-example-and-examples.json
@@ -64,15 +64,13 @@
                     }
                   }
                 },
-                "example": {
-                  "value": [
-                    {
-                      "id": 0,
-                      "name": "Herbert",
-                      "tag": "Doggo"
-                    }
-                  ]
-                },
+                "example": [
+                  {
+                    "id": 0,
+                    "name": "Herbert",
+                    "tag": "Doggo"
+                  }
+                ],
                 "examples": {
                   "single": {
                     "value": [
diff --git a/test/data/v3/simple-api-with-example-with-refs-invalid.json b/test/data/v3/simple-api-with-example-with-refs-invalid.json
index f30534d..0113090 100644
--- a/test/data/v3/simple-api-with-example-with-refs-invalid.json
+++ b/test/data/v3/simple-api-with-example-with-refs-invalid.json
@@ -47,14 +47,12 @@
                 "schema": {
                   "$ref": "#/components/schemas/Pets"
                 },
-                "example": {
-                  "value": [
-                    {
-                      "id": "0",
-                      "tag": 5
-                    }
-                  ]
-                }
+                "example": [
+                  {
+                    "id": "0",
+                    "tag": 5
+                  }
+                ]
               }
             }
           },
diff --git a/test/data/v3/simple-api-with-example.json b/test/data/v3/simple-api-with-example.json
index 72bdd4b..88dc820 100644
--- a/test/data/v3/simple-api-with-example.json
+++ b/test/data/v3/simple-api-with-example.json
@@ -64,15 +64,13 @@
                     }
                   }
                 },
-                "example": {
-                  "value": [
-                    {
-                      "id": 0,
-                      "name": "Herbert",
-                      "tag": "Doggo"
-                    }
-                  ]
-                }
+                "example": [
+                  {
+                    "id": 0,
+                    "name": "Herbert",
+                    "tag": "Doggo"
+                  }
+                ]
               }
             }
           },
diff --git a/test/data/v3/simple-api-with-request-examples.json b/test/data/v3/simple-api-with-request-examples.json
index 72bdd4b..88dc820 100644
--- a/test/data/v3/simple-api-with-request-examples.json
+++ b/test/data/v3/simple-api-with-request-examples.json
@@ -64,15 +64,13 @@
                     }
                   }
                 },
-                "example": {
-                  "value": [
-                    {
-                      "id": 0,
-                      "name": "Herbert",
-                      "tag": "Doggo"
-                    }
-                  ]
-                }
+                "example": [
+                  {
+                    "id": 0,
+                    "name": "Herbert",
+                    "tag": "Doggo"
+                  }
+                ]
               }
             }
           },