【问题标题】:API Platform - can't generate Entity from schema with no owned propertiesAPI 平台 - 无法从没有自有属性的模式生成实体
【发布时间】:2018-09-16 05:31:25
【问题描述】:

我正在运行 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,但我不确定如何在其上设置持续时间属性(可能是文本)。 也许我混淆了如何使用/定义没有自身属性的类型 - 有没有办法告诉架构“这只是一个单一的文本值”?

【问题讨论】:

    标签: php symfony schema.org api-platform.com


    【解决方案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
    

    所以它的用法类似于data types

    提供项目值

    如果您确实必须将其作为类型提供(无论出于何种原因),您可以将其作为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 日期/时间,而在将其指定为文本值时没有报告任何警告。

    【讨论】:

      猜你喜欢
      • 2020-11-13
      • 2020-01-15
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 2015-08-03
      • 2011-08-22
      • 1970-01-01
      • 2017-02-02
      相关资源
      最近更新 更多