looking for some solutions? You are welcome.

SOLVED: swagger data validation with allOf and additional properties

Mathieu Gobert:

Need help to solve a swagger definiton schema using allOf and additionalProperties: false

Here my JSON Schema

"deliveryContact": {
      "allOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "name": {
              "type": "string",
              "maxLength": 1024
            },
            "phone": {
              "type": "string",
              "maxLength": 24
            }
          }
        },
        {
          "$ref": "#/definitions/address"
        }
      ]
    },
    "address": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "address": {
          "type": "string",
          "maxLength": 1024
        },
        "postalCode": {
          "type": "string",
          "maxLength": 12
        },
        "city": {
          "type": "string",
          "maxLength": 512
        },
        "state": {
          "type": "string",
          "maxLength": 512
        }
      }
    },

Sample data

                   delivery: {
                        address: 'my address',
                        postalCode: 'my postalCode',
                        city: 'my city',
                        state: 'my state',
                        name: 'my name',
                        phone: 'my phone'
                    },


I use AJV 6.10.0 to validate my data, but I think I have a wrong schema definition. With Ajv options :

        ajv = require('ajv')({
            allErrors: true,
            verbose: true,
            removeAdditional: false,
        });

Actually I have 6 errors wich warn of additional properties for each properties

During validation of the first object in allOf (name and phone), validation found error on (address, postalCode, city and state)

If I remove additionalProperties of the first allOf object (name, phone), during validation of address schema, the validation found error on (name and phone)

How can I solve my schema definition



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent