RAML 1.0中引用JSON Schema的方法详解
来源:互联网 发布:二环十三郎 知乎 编辑:程序博客网 时间:2024/06/09 17:35
在RAML 1.0中,不再推荐使用Schema,但是为了保持与RAML 0.8的兼容,所以仍然保留了Schema相关的关键字。
在RAML 1.0中,放弃了RAML 0.8的资源的概念,取而代之的是数据类型。所以,使用Schema的方式也是在定义数据类型Data Types。
虽然仍然保留了schemas,但是推荐使用types替代。而且,types和schemas,二者只能出现其一。
同样,在引用一个具体的数据类型时,推荐使用type替代schema。而且,type和schema,二者只能出现其一。
即在RAML 1.0中,以types的形式定义Schema,以type的形式引用Schema。
1.命名的Schema(可重用)
1) 借助于JSON Schema定义数据类型
types: song: !include jukebox-include-song.schema artist: !include jukebox-include-artist.schema album: !include jukebox-include-album.schema或
types: song: type: !include jukebox-include-song.schema artist: type: !include jukebox-include-artist.schema album: type: !include jukebox-include-album.schema
或(不推荐如下方式)
types: song: schema: !include jukebox-include-song.schema artist: schema: !include jukebox-include-artist.schema album: schema: !include jukebox-include-album.schema或
types: song: | { "type": "object", "$schema": "http://json-schema.org/draft-03/schema", "id": "http://jsonschema.net", "required": true, "properties": { "songTitle": { "type": "string", "required": true }, "albumId": { "type": "string", "required": true, "minLength": 36, "maxLength": 36 } } } artist: ...
2) 对于上述命名的数据类型,使用其数据类型
body: application/json: type: song
body: application/json: type: !include jukebox-include-chronus.schema
或(不推荐如下方式)
body: application/json: schema: !include jukebox-include-chronus.schema
2.不预定义数据类型,在使用时直接以Schema给出匿名的数据类型(不可重用)
body: application/json: type: | { "type": "object", "$schema": "http://json-schema.org/draft-03/schema", "id": "http://jsonschema.net", "required": true, "properties": { "songTitle": { "type": "string", "required": true }, "albumId": { "type": "string", "required": true, "minLength": 36, "maxLength": 36 } } }
3.只引用Schema中的子元素
type: !include elements.xsd#Foo
参考链接:
https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md/
阅读全文
1 0
- RAML 1.0中引用JSON Schema的方法详解
- RAML 0.8中引用JSON Schema的方法详解
- JSON Schema详解
- RAML规范的Python参考实现ramlfications详解
- xml中引用自定义schema
- RAML
- RAML文档生成器raml2html详解
- 在xml中如何引用自己定义的schema文件?
- Schema中elementFormDefault详解
- RAML文件的Java解析器raml-java-parser概述
- Ajax中解析Json的两种方法详解
- Ajax中解析Json的两种方法详解
- Ajax中解析Json的两种方法详解
- Ajax中解析Json的两种方法详解
- 在 XML 文档中引用 Schema
- Java中引用的详解
- C++中引用的详解
- Java中引用的详解
- 三,创建项目
- AMD-SDK的学习[1]--AdvancedConvolution
- Python多线程锁例子
- GAN改进五大方向
- MyEclipse 反编译插件的安装
- RAML 1.0中引用JSON Schema的方法详解
- linux 在线安装 jdk tomcat mysql eclipse
- 怎样选择免备案虚拟主机空间
- 四、获取项目
- java项目中的全局变量
- Matlab图像处理转灰度图,绘制直方图,直方图均衡化
- iOS如何指定某个页面可以旋转屏幕,其余控制器都正常竖屏
- Android之引用包含远程依赖库的aar(引用aar时找不到arr的远程依赖库问题)
- plsql是可以写多个select的,但是一定要加上;号,不然就会报错