openactive / data-model-validator

The OpenActive data model validator library
MIT License
1 stars 1 forks source link

Incorrect validation of extension types #421

Closed nickevansuk closed 1 year ago

nickevansuk commented 1 year ago

Extension types are not being validated correctly in cases where the model implies only one type should be used for a property.

For example, this response:

{
  "@context": [
    "https://openactive.io/",
    "https://openactive.io/stripe-extension"
  ],
  "@type": "Order",
  ...
  "payment": {
    "@type": "stripe:PaymentIntent",
    "identifier": "pi_123456789", // payment intent ID
    "stripe:clientSecret": "sk_test_26PHem9AhJZvU623DfE1x4sd",
    "stripe:publishableKey": "pk_test_TYooMQauvdEDq54NiTphI7jx"
  }
}

With this defined extension:

{
  "@context": [
    "https://openactive.io/ns-extension",
    {
      "stripe": "https://openactive.io/stripe-extension#"
    }
  ],
  "@graph": [
    {
      "@id": "stripe:PaymentIntent",
      "@type": "Class",
      "label": "PaymentIntent",
      "subClassOf": [
        "oa:Payment"
      ],
      "comment": "OpenActive representation of a Stripe Payment Intent"
    },
    {
      "@id": "stripe:clientSecret",
      "@type": "Property",
      "label": "clientSecret",
      "comment": "The `client_secret` within the Stripe Payment Intent",
      "domainIncludes": [
        "stripe:PaymentIntent"
      ],
      "rangeIncludes": [
        "schema:Text"
      ]
    },
    {
      "@id": "stripe:publishableKey",
      "@type": "Property",
      "label": "publishableKey",
      "comment": "The Stripe `publishableKey`",
      "domainIncludes": [
        "stripe:PaymentIntent"
      ],
      "rangeIncludes": [
        "schema:Text"
      ]
    }
  ]
}

The above returns an error for both stripe:clientSecret and stripe:publishableKey which reads "A definition for this extension property was found, but it has not been included in the correct object type. Please check the spelling of this property and ensure that you are using it within the correct object "@type".

This error is incorrect, as the properties are explicitly defined on the type in the extension.