RAML 0.8中引用JSON Schema的方法详解
来源:互联网 发布:手机4g网络提速方法 编辑:程序博客网 时间:2024/06/05 04:17
在RAML 0.8的规范中,以Schema的方式定义资源Resources。
为了能够引用JSON Schema,提供了两个关键字schemas和schema。schemas用以声明资源,而schema用以引用资源。
根据是否在raml文件中定义JSON Schema,引用JSON Schema有两种方式,一种是在raml文件中引用独立的JSON Schema文件,另一种是在raml文件中直接使用JSON Schema片段。
1.使用schemas声明资源
...schemas: - User: schema/user.json Users: schema/users.json Org: schema/org.json Orgs: schema/orgs.json...
或
...schemas: - !include path-to-canonical-schemas/canonicalSchemas.raml - File: !include path-to-schemas/filesystem/file.xsd FileUpdate: !include path-to-schemas/filesystem/fileupdate.xsd Files: !include path-to-schemas/filesystem/files.xsd Dir: !include path-to-schemas/filesystem/dir.xsd Dirs: !include path-to-schemas/filesystem/dirs.xsd...
1) 对于已经声明过的资源,可以在后续raml文件中直接引用
/files: get: responses: 200: body: application/xml: schema: Files
2) 也可以引用从未声明过的资源
/jobs: displayName: Jobs post: description: Create a Job body: text/xml: schema: !include job.xsd application/json: schema: !include job.schema.json
或
/jobs: displayName: Jobs post: description: Create a Job body: text/xml: schema: | <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="api-request"> <xs:complexType> <xs:sequence> <xs:element type="xs:string" name="input"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> application/json: schema: | { "$schema": "http://json-schema.org/draft-03/schema", "properties": { "input": { "required": false, "type": "string" } }, "required": false, "type": "object" }
注意,对于application/x-www-form-urlencoded或multipart/form-data时,不能使用schema。
3. 补充:与schema类似,RAML 0.8中还提供了example,可以引用JSON Schema。
application/json: schema: !include job.schema.json example: | { "input": "s3://zencodertesting/test.mov" }
或
application/json: example: !include examples/instagram-v1-media-popular-example.json
参考链接:
https://github.com/raml-org/raml-spec/blob/master/versions/raml-08/raml-08.md
阅读全文
1 0
- RAML 0.8中引用JSON Schema的方法详解
- RAML 1.0中引用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中引用的详解
- 法规记忆内容
- jdk1.8新特性详解
- Shader and Program编程基本概念
- sql语句group by 和 having
- iOS消息推送(Java实现)
- RAML 0.8中引用JSON Schema的方法详解
- 文字超过多行(自定义行数)就显示省略号
- nexus数据仓库—私库
- hdu5025Saving Tang Monk(bfs+优先队列+状态压缩)
- sphinx做搜索时如果web服务器和sphinx服务器不是同一台服务器,返回false的原因说明
- Kernel PCA
- 【Spring Security实战系列】Spring Security实战(六)
- Spring mybatis maven的项目环境运行流程
- hdu 1243