1
votes

I'm running the API Platform schema type-generator, but struggling with a type that is defined in schema.org, but has no properties of its own (http://schema.org/Duration).

When I run vendor/bin/schema generate-types, I get

[error] The property "potentialAction" (type "Duration") has an unknown type. Add its type to the config file.

[warning] The property "identifier" (type "Duration") has several types. Using the first one ("URL") or possible options("URL", "Text").

My types config is:

  types:
    Thing:
        properties:
            name: ~
    Duration: ~
    Recipe:
        properties:
            cookTime: ~
            recipeCuisine: ~

If I define one of the properties Duration inherits from a parent (Eg Thing->Name) it generates OK, but I'm not sure how to then set a duration property (presumably text) on it. Perhaps I've mixed up how to use/define types that have no properties of their own - is there a way of telling the schema 'This is just a single text value'?

1

1 Answers

1
votes

I’m not familiar with API Platform, but I think your question can be answered from the perspective of authoring Schema.org structured data:

Providing a text value (recommended)

You would typically not specify Duration as type. Just provide a text value.

From Schema.org’s example of the cookTime property (which expects a Duration value):

"cookTime": "PT1H",
Cook time: <meta itemprop="cookTime" content="PT1H">1 hour
Cook time: <meta property="cookTime" content="PT1H">1 hour

So its use is similar to data types.

Providing an item value

If you do have to provide it as type (for whatever reason), you could provide it as value for the name property, as there is no other suitable property defined:

"cookTime": {
  "@type": "Duration",
  "name": "PT1H"
},
<div itemprop="cookTime" itemscope itemtype="http://schema.org/Duration">
  Cook time: <meta itemprop="name" content="PT1H">1 hour
</div>
<div property="cookTime" typeof="Duration">
  Cook time: <meta property="name" content="PT1H">1 hour
</div>

But that’s not commonly done, and consumers might not handle it correctly. For example, Google’s SDTT reports a warning that it doesn’t understand the value "PT1H" as ISO 8601 date/time, while it reports no warning when specifying it as text value.