Repository: codekie/openapi-examples-validator (js)

Issue:
Examples > Value: with array of value - problem
Hi @codekie ,

I have a strange issue, with the "value" property in an example.

Path

 ```
 /lists/audiences:
    parameters:
      - $ref: '#/components/parameters/X-ApiKey'
    get:
      summary: Get all audience configurations
      tags:
        - Lists - Audience
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/listsAudienceResults'
              examples:
                sample-list-audiences:
                  $ref: '#/components/examples/sample-list-audiences'
      operationId: get-audience-lists
      description: |-
        Returns a list of audience configurations.
        The configurations are returned sorted by name.
```

Components - Schema
```
components:
  schemas:
    listsAudienceResults:
      description: An audience configuration result.
      type: object
      properties:
        'value':
          description: 'Result of the audience configurations, based on the query options.'
          type: array
          items:
            $ref: '#/components/schemas/listsAudienceResultData'
        '@count':
            $ref: '#/components/schemas/link@count'
        '@nextlink':
            $ref: '#/components/schemas/link@nextlink'
```

Components - Example
```
    sample-list-audiences:
      value:
        value:
          - id: 12345-6789-01234-567-890
            tenant: 12345-6789-3333-1111-2222
            name: Master Contact list
            apiName: master_contact
            systemFields:
              mobile: MASTER.MOBILE
              language: MASTER.LANGUAGE
            type: Userlist
            requireSegment: true
            created: '2020-01-31T10:31:21.286Z'
            brands:
              - brandName: Demo
                brandId: 12345-6789-5555-6666-7777
        '@count': 68
        '@nextLink': https://api.demo.com/v2/lists/audiences?$count=true&$top=3&$skip=3
      summary: A sample of list of audience configurations response
```

When I run the validation check, it always throws the following error:
```
Errors found.

[
    {
        "type": "Validation",
        "message": "should be object",
        "keyword": "type",
        "dataPath": "",
        "schemaPath": "#/type",
        "params": {
            "type": "object"
        },
        "examplePath": "/paths/~1lists~1audiences/get/responses/200/content/application~1json/examples/sample-list-audiences/value/value"
    }
]
```

If I rename the "value" property in the schema and in the example to something else, like "data", the example is valid and no error is thrown.

Could it be that "value" property is a special property in the validation library, which causes the error to occur for a nested "value" property?

Pull request:
fix: don't recognize `value`-properties as examples
closes #80 

Don't recognize every `value`-property as an example.

Patch:
diff --git a/src/impl/v3/index.js b/src/impl/v3/index.js
index 29bb2b1..107e88d 100644
--- a/src/impl/v3/index.js
+++ b/src/impl/v3/index.js
@@ -8,11 +8,11 @@ const { JSONPath: jsonPath } = require('jsonpath-plus'),
 // CONSTANTS
 
 const PATH__EXAMPLE = '$..responses..content.application/json.example',
-    PATH__EXAMPLES = '$..responses..content.application/json.examples..value',
+    PATH__EXAMPLES = '$..responses..content.application/json.examples.*.value',
     PATH__EXAMPLE__PARAMETER = '$..parameters..example',
-    PATH__EXAMPLES__PARAMETER = '$..parameters..examples..value',
+    PATH__EXAMPLES__PARAMETER = '$..parameters..examples.*.value',
     PATH__EXAMPLE__REQUEST_BODY = '$..requestBody.content.application/json.example',
-    PATH__EXAMPLES__REQUEST_BODY = '$..requestBody.content.application/json.examples..value',
+    PATH__EXAMPLES__REQUEST_BODY = '$..requestBody.content.application/json.examples.*.value',
     PROP__SCHEMA = 'schema',
     PROP__EXAMPLE = 'example',
     PROP__EXAMPLES = 'examples';


Test patch:
diff --git a/test/data/v3/valid-single-with-value-property.yaml b/test/data/v3/valid-single-with-value-property.yaml
new file mode 100644
index 0000000..6ed9446
--- /dev/null
+++ b/test/data/v3/valid-single-with-value-property.yaml
@@ -0,0 +1,52 @@
+openapi: 3.0.0
+info:
+  version: 1.0.0
+  title: Swagger Petstore
+  license:
+    name: MIT
+servers:
+  - url: 'http://petstore.swagger.io/v1'
+paths:
+  /pets:
+    get:
+      summary: List all assets
+      operationId: listAssets
+      responses:
+        '200':
+          description: An array of assets
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/Assets'
+              examples:
+                single:
+                  summary: a single example
+                  value:
+                    value:
+                      - id: 0
+                        name: Table
+                        tag: furniture
+                        value: 500
+                        currency: USD
+components:
+  schemas:
+    Asset:
+      required:
+        - id
+        - name
+      properties:
+        id:
+          type: number
+        name:
+          type: string
+        tag:
+          type: string
+        value:
+            type: number
+    Assets:
+      type: object
+      properties:
+        value:
+          type: array
+          items:
+            $ref: '#/components/schemas/Asset'
diff --git a/test/specs/impl/v3/index.js b/test/specs/impl/v3/index.js
index 07e039d..ba6e081 100644
--- a/test/specs/impl/v3/index.js
+++ b/test/specs/impl/v3/index.js
@@ -34,6 +34,7 @@ const JSON_PATH__CONTEXT_MUTUALLY_EXCLUSIVE = '/paths/~1pets/get/responses/200/c
     FILE_PATH__INVALID__REQUEST_BODY = path.join(__dirname, '../../../data/v3/request-invalid-requestbody.json'),
     FILE_PATH__INVALID__REQUEST_BODY__EXAMPLES
         = path.join(__dirname, '../../../data/v3/request-invalid-requestbody-examples.json'),
+    FILE_PATH__VALID__VALUE_PROPERTY = path.join(__dirname, '../../../data/v3/valid-single-with-value-property.yaml'),
     FILE_PATH__VALID__YAML = path.join(__dirname, '../../../data/v3/simple-api-with-examples-with-refs.yaml'),
     FILE_PATH__VALID__YML = path.join(__dirname, '../../../data/v3/simple-api-with-examples-with-refs.yml');
 
@@ -239,6 +240,17 @@ describe('Main-module, for v3 should', function() {
             });
         });
     });
+    describe('example with `value`s as properties', function() {
+        it('should not be recognized as separate example', async function() {
+            const { valid, statistics } = (await validateFile(FILE_PATH__VALID__VALUE_PROPERTY));
+            valid.should.equal(true);
+            statistics.should.deep.equal({
+                schemasWithExamples: 1,
+                examplesWithoutSchema: 0,
+                examplesTotal: 1
+            });
+        });
+    });
     describe('statistics for examples, without schema', function() {
         it('should return the right amount', async function() {
             (await validateFile(FILE_PATH__EXAMPLES_WITH_MISSING_SCHEMA))