CiscoDevNet / FMCAnsible

GNU General Public License v3.0
21 stars 25 forks source link

Null object value not permitted for required schema data #63

Open brebouch opened 8 months ago

brebouch commented 8 months ago

The FMC API spec for the RAVPN endpoint has required keys for addressAssignmentSettings and connectionProfiles that do not exist before the RAVPN object is created. Similarly the required dapPolicy object value can be set to null using the REST API as it is not required for every RAVPN. The current swagger validation process on plugins/module_utils/fmc_swagger_client.py line 683 mandates that any required field dictionary value is not None which causes the following output below:

FAILED! => {"changed": false, "msg": {"Invalid data provided": {"required": ["addressAssignmentSettings", "connectionProfiles", "dapPolicy"]}}}

By changing the _check_required_fields function from :

    def _check_required_fields(self, status, required_fields, data, path):
        missed_required_fields = [self._create_path_to_field(path, field) for field in
                                  required_fields if field not in data.keys() or data[field] is None]
        if len(missed_required_fields) > 0:
            status[PropName.REQUIRED] += missed_required_fields

To the following:

    def _check_required_fields(self, status, required_fields, data, path):
        missed_required_fields = [self._create_path_to_field(path, field) for field in
                                  required_fields if field not in data.keys()]
        if len(missed_required_fields) > 0:
            status[PropName.REQUIRED] += missed_required_fields

Everything works as expected. In the event that the field value is not allowed to be null, the failure would be reflected in the API response rather than preventing the request to be initiated.