Skip to content

Additional flexibility for imperativeConfiguration #56

Description

@nickevansuk

Requirement

Add additional flexibility to imperativeConfiguration to allow for the containing property name to be considered when setting required fields for a type.

This functionality would mean that, for example, validating the below Organization type would depend on the property within which it was found - e.g. "broker".

"broker": {
  "@type": "Organization",
  "name": "Acme leisure"
}

Suggested design

Use imperativeConfigurationWithContext within the model files, which includes a map within requiredFields, recommendedFields, shallNotInclude and requiredOptions. This is an additional map of property names (see example below). These changes already exist dormantly in Organization.json and Person.json - just remove the placeholder empty "imperativeConfiguration".

Implementation hints

Implementation of this likely requires changes to src/rules/core/required-optional-fields-rule.js, src/rules/core/required-fields-rule.js, src/rules/core/recommended-fields-rule.js, and src/rules/core/shall-not-include-fields-rule.js within data-model-validator.

Example

  "imperativeConfigurationWithContext": {
    "request": {
      "requiredFields": {
        "broker": [
          "id",
          "name"
        ],
        "seller": [
          "id"
        ],
        "customer": [
          "email",
          "name",
          "address"
        ]
      },
      "recommendedFields": {
        "broker": [
          "email",
          "url",
          "logo"
        ],
        "seller": [
        ],
        "customer": [
        ]
      }
    },
    "response": {
      "requiredFields": {
        "broker": [
        ],
        "seller": [
          "id",
          "name",
          "legalName",
          "taxMode",
          "vatID",
          "address"
        ],
        "customer": [
        ]
      },
      "recommendedFields": {
        "broker": [
        ],
        "seller": [
          "email",
          "url",
          "logo"
        ],
        "customer": [
        ]
      }
    }
  },

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions