3 个版本
0.4.2 | 2022年7月16日 |
---|---|
0.4.1 | 2022年7月15日 |
0.4.0 | 2022年7月15日 |
#2151 在 解析器实现
用于 jss-core
37KB
491 行
Json Schema 简化
编写模式的一种更好的方式
- Jss 版本: open-api.jss
- Json Schema 版本: open-api.json
工具和实现
Intellij
Rust
- jss-rs
- jss-cli: TODO
- jss-mock: TODO
Node
- Wasm 绑定: jss-wasm
- 在线沙盒: replit.com@jss
语法
description
又称 doc-comment,注释从 ///
开始
schema
顶层定义,指定所有顶层字段的约束
/// The description of OpenAPI v3.1.x documents without schema validation
/// as defined by https://spec.openapis.org.cn/oas/v3.1.0
schema _: object {
$id: "https://spec.openapis.org.cn/oas/3.0/schema/2021-09-28"
$schema: "https://json-schema.fullstack.org.cn/draft-04/schema#"
additionalProperties: false
patternProperties: {
"^x-": {},
}
required: [
"openapi",
"info",
"paths",
]
}
等效 json schema
{
"title": "_",
"type": "object",
"description": "The description of OpenAPI v3.1.x documents without schema validation\nas defined by https://spec.openapis.org.cn/oas/v3.1.0",
"$id": "https://spec.openapis.org.cn/oas/3.0/schema/2021-09-28",
"$schema": "https://json-schema.fullstack.org.cn/draft-04/schema#",
"additionalProperties": false,
"patternProperties": {
"^x-": {}
},
"required": [
"openapi",
"info",
"paths"
],
"properties": {}
}
define
顶层定义,指定所有引用
define License: object {
additionalProperties: false
required: [
"name",
]
patternProperties: {
"^x-": {},
}
.name: string
.url: string {
format: "uri-reference"
}
}
等效 json schema
{
"title": "_",
"type": "undefined",
"$defs": {
"License": {
"type": "object",
"additionalProperties": false,
"required": [
"name"
],
"patternProperties": {
"^x-": {}
},
"$defs": {},
"properties": {
"name": {
"type": "string",
"properties": {}
},
"url": {
"type": "string",
"format": "uri-reference",
"properties": {}
}
}
}
},
"properties": {}
}
property
递归定义,指定每个项目的属性
property
可以缩写为 .
/// Dimensions for the product
property dimensions: object {
.length: number
.width: number
.height: number
required: ["length", "width", "height"]
}
等效 json schema
{
"title": "_",
"type": "undefined",
"properties": {
"dimensions": {
"type": "object",
"description": "Dimensions for the product",
"required": [
"length",
"width",
"height"
],
"properties": {
"length": {
"type": "number",
"$defs": {},
"properties": {}
},
"width": {
"type": "number",
"properties": {}
},
"height": {
"type": "number",
"properties": {}
}
}
}
}
}
演变
- CLI 工具
- 基于 jss 的模拟数据生成器
依赖项
~1.5MB
~32K SLoC