1

我正在运行 API 平台模式类型生成器,但在使用 schema.org 中定义但没有自己的属性 ( http://schema.org/Duration ) 的类型时遇到了困难。

当我运行 vendor/bin/schema generate-types 时,我得到

[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").

我的类型配置是:

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

如果我定义 Duration 从父级继承的属性之一(例如 Thing->Name),它会生成 OK,但我不确定如何在其上设置持续时间属性(可能是文本)。也许我混淆了如何使用/定义没有自己属性的类型 - 有没有办法告诉模式“这只是一个单一的文本值”?

4

1 回答 1

1

我不熟悉 API Platform,但我认为您的问题可以从创作 Schema.org 结构化数据的角度来回答:

提供文本值(推荐

您通常不会指定Duration为类型。只需提供一个文本值。

从 Schema.org 的cookTime属性示例(需要一个Duration值):

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

所以它的用途类似于数据类型

提供项目值

如果您必须将其作为类型提供(无论出于何种原因),您可以将其作为name属性的值提供,因为没有定义其他合适的属性:

"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>

但这并不常见,消费者可能无法正确处理。例如,Google 的 SDTT 报告了一个警告,它不将值“PT1H”理解为 ISO 8601 日期/时间,而在将其指定为文本值时没有报告任何警告。

于 2018-04-06T17:43:53.220 回答