【问题标题】:How to describe a collection of thing as a vocabulary property in ALPS descriptor?如何将事物的集合描述为 ALPS 描述符中的词汇属性?
【发布时间】:2021-01-30 17:16:42
【问题描述】:

为了以应用程序为中心来描述 REST API,我正在尝试使用 ALPS 描述符及其工具。

假设我有一个对象“艺术品”,一件艺术品具有以下属性:标题、艺术形式、作者等。

我应该如何描述属性“作者”?在 OpenAPI 规范中这很简单,只需说“type: Array”,然后在“items”下指定引用。在 ALPS 中描述集合的等效方式是什么?

我使用 YAML 格式来描述 API。

我当前的描述符如下所示:

descriptors:
# vocabulary properties
- id: "identifier"
  type: "semantic"
  text: "Unique identifier within Alpha Org. This is not the serial number of the item. This identifier is automatically generated when a new artwork item is created in the system."
  ref: "https://schema.org/identifier"

- id: "headline"
  type: "semantic"
  text: "Title of the artwork"
  ref: "https://schema.org/headline"

- id: "artform"
  type: "semantic"
  text: "Form of the artwork: painting? photograph? sculpture? others?"
  ref: "https://schema.org/artform"

- id: "authors"
  type: "semantic"
  text: "Authors of this artwork"
  ref: "https://schema.org/author"

- id: "serialNumber"
  type: "semantic"
  text: "Serial number of the artwork. If the artwork does not have a serial number, such as an original painting from an artist, then this number is simply the examplar number, usually 1."
  ref: "https://schema.org/serialNumber"

- id: "description"
  type: "semantic"
  text: "Description of the artwork"
  ref: "https://schema.org/description"

- id: "obtainDate"
  type: "semantic"
  text: "Date on which Alpha Org obtained the ownership of this artwork."
  ref: "https://schema.org/Date"

- id: "itemLocation"
  type: "semantic"
  text: "Location of the storage of the artwork item"
  ref: "https://schema.org/itemLocation"

- id: "images"
  type: "semantic"
  text: "Images of the artwork"
  ref: "https://schema.org/image"

【问题讨论】:

    标签: api descriptor


    【解决方案1】:

    ALPS 描述不区分单个项目和集合。从模型 POV 来看,任何东西都可以是一个集合,从实现 POV 来看,实现该 ALPS 描述的每个服务都会做出自己的决定。

    作为一种常见做法,我通常在重要时使用 IANA 链接相对值

    rel: item and rel: collection
    

    有一个小实用程序 (ALPS UNIFIED) 展示了如何将 ALPS 描述转换为 OpenAPI 定义: https://github.com/mamund/alps-unified

    【讨论】:

    • 非常感谢阿蒙森先生!我更新了我的问题并包含了我当前的代码。您能否指导我如何在上述代码中将属性“作者”和“图像”描述为数组?在 Stackoverflow 中,您可以编辑答案以包含代码 sn-ps。
    • 您可以创建一个名为“authors”的语义描述符,然后使用带有 href 属性的描述符添加嵌套描述符,引用到已定义的属性。请参阅此示例待办事项列表 ALPS 文档以获取想法:github.com/alps-io/profiles/blob/master/yaml/todo-alps.yaml
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    相关资源
    最近更新 更多