知识卡片
属性格式细化基础类型
JSON Schema 的 type 规定基础数据类型,format 可进一步说明值的具体形态。例如日期仍可写成字符串,但用 format: date 表明期待日期形式。只写 type: string 时,消费者无法仅凭类型知道该值是普通文本还是日期。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 5 章《Documenting REST APIs with OpenAPI》(源文件:_epub-src/OEBPS/Text/05.htm)
- 结论依据:原文明确说在类型之外可指定格式,并以 `type: string` 与 `format: date` 描述日期属性。
- 原始内容:In addition to being able to specify the type of a property, JSON Schema also allows us to specify the format of the property. We can develop our own custom formats or use JSON Schema’s built-in formats. For example, for a property representing a date, we can use the date format—a built-in format supported by JSON Schema that represents an ISO date