使用Halcyon.net生成Curies

时间:2018-01-08 15:40:27

标签: c# json semantic-web hal curie

使用Halcyon .NET库(https://github.com/visualeyes/halcyon),我可以生成原型API所需的HAL(http://stateless.co/hal_specification.html)输出。

但是,我想添加curies来记录我的一些rel类型的其他语义。我没有看到使用提供的API添加curies作为链接的方法。

我试过了:

public class LinkBuilder
{
    public static readonly Link[] Curies =
    {
        new Link("curies", "http://test.com/api/docs/rels/{rel}", replaceParameters: false, isRelArray: true)
    };
    public static Link AsProductFamilyLink(int familyId)
    {
        return new Link("tns:product-family", $"/product-family/{familyId}");
    }

    /* snip */

}

但这导致输出缺少居里的关键name属性:

{
    "id": 2,
    "name": "Chips",
    "unitPrice": 0,
    "_links": {
        "delete-product": {
            "href": "/product/2",
            "method": "DELETE",
            "title": "Delete product"
        },
        "tns:product-family": {
            "href": "/product-family/1"
        },
        "self": {
            "href": "/product/2",
            "method": "GET"
        },
        "curies": [
            {
                "href": "http://test.com/api/docs/rels/{rel}",
                "templated": true
            }
        ]
    }
}

如何正确生成curies链接? (也许是一个不同的图书馆?)要清楚,预期的" curies"数组应该如下所示:

[
   {
      "name": "tns",
      "href": "http://test.com/api/docs/rels/{rel}",
      "templated": true
   }
]

1 个答案:

答案 0 :(得分:0)

设置CURIE链接的Name属性:

new Link("curies", "http://test.com/api/docs/rels/{rel}", replaceParameters: false, isRelArray: true)
{
    Name = "tns"
};