【问题标题】:How to use Jackson HyperSchema to generate schema link references如何使用 Jackson HyperSchema 生成架构链接引用
【发布时间】:2014-06-05 05:12:03
【问题描述】:

我正在使用 Jackson jsonSchema(https://github.com/FasterXML/jackson-module-jsonSchema) 为我的数据模型自动创建模式。

根据http://json-schema.org/和jsonSchema中提供的示例,json shema使用的格式包括链接

{
  "name":"Product",
  "properties":{
    "id":{
      "type":"number",
      "description":"Product identifier",
      "required":true
    },
    "name":{
      "description":"Name of the product",
      "type":"string",
      "required":true
    },
    "price":{
      "required":true,
      "type": "number",
      "minimum":0,
      "required":true
    },
    "tags":{
      "type":"array",
      "items":{
        "type":"string"
      }
    }
  },
  "links":[
    {
      "rel":"full",
      "href":"{id}"
    },
    {
      "rel":"comments",
      "href":"comments/?id={id}"
    }
  ]
}

但是我找不到将它添加到生成的架构中的方法,虽然有一个HyperSchema对象,这似乎是我需要的,但我找不到如何使用它。

【问题讨论】:

    标签: json rest jackson jsonschema hateoas


    【解决方案1】:

    在 json-schema 项目中提出了一个问题,并在表单中基于注释提出了支持 HyperSchema 的拉取请求

    https://github.com/FasterXML/jackson-module-jsonSchema/issues/35

    public class Pet {
        public String genus;
    }
    
    @JsonHyperSchema(pathStart = "/persons/", links = {
        @Link(href = "{name}", rel = "self"),
        @Link(href = "{name}/pet", rel = "pet", targetSchema = Pet.class)
    })
    public class Person {
        public String name;
        public String hat;
    }
    

    更改在https://github.com/clemble/jackson-module-jsonSchema

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      相关资源
      最近更新 更多