Problem/Motivation

We will likely be (and are excited to be) using JSONAPI Schema in farmOS 2.x. I believe this would be a good feature in contexts outside of farmOS, but forgive me if I'm mistaken!

Currently the enum key is only included if a field's settings.target_type and settings.handler_settings.target_bundles values are provided. Seems like it would be useful to provide an enum of all entity bundles when settings.target_type is specified, but no specific target_bundles are specified.

An example: the farmOS data model uses "Log" entities and "Asset" entities. Most log bundles (eg: harvest log, input log) can optionally specify references to multiple "assets" (eg: animal asset, plant asset) with the log.asset field. Logs also have a log.equipment field to reference "equipment" assets (the "equipment" asset bundle). An enum is provided on the log.equipment field, but not the log.asset field. Because a farmOS server may have different assets bundles enabled (a farm may not need the "animal asset"), an enum would be quite useful in validating what bundles are available.

log.equpment relationship schema:

"equipment":{
   "type":"object",
   "properties":{
      "data":{
         "type":"array",
         "items":{
            "type":"object",
            "required":[
               "type",
               "id"
            ],
            "properties":{
               "type":{
                  "type":"string",
                  "title":"Referenced resource",
                  "enum":[
                     "asset--equipment"
                  ]
               },
               "id":{
                  "type":"string",
                  "title":"Resource ID",
                  "format":"uuid",
                  "maxLength":128
               },
               "meta":{
                  "type":"integer",
                  "title":"Asset ID"
               }
            }
         }
      }
   },

log.asset relationship schema:

"asset":{
   "type":"object",
   "properties":{
      "data":{
         "type":"array",
         "items":{
            "type":"object",
            "required":[
               "type",
               "id"
            ],
            "properties":{
               "type":{
                  "type":"string",
                  "title":"Referenced resource"
               },
               "id":{
                  "type":"string",
                  "title":"Resource ID",
                  "format":"uuid",
                  "maxLength":128
               }
            }
         }
      }
   },
   "title":"Assets",
   "links":[
      {
         "href":"{instanceHref}",
         "rel":"related",
         "targetMediaType":"application/vnd.api+json",
         "targetSchema":"http://localhost/api/log/input/resource/relationships/asset/related/schema",
         "templatePointers":{
            "instanceHref":"/links/related/href"
         },
         "templateRequired":[
            "instanceHref"
         ]
      }
   ]
},

Proposed resolution

Load all entity bundles if no specific target_bundles are provided.

Data model changes

This would add an enum property to schemas that previously did not have one. My understanding is that this would provide additional validation to clients relying on JSONAPI which is maybe considered a breaking change?

Comments

paul121 created an issue. See original summary.