5个版本

0.2.0 2022年7月16日
0.1.3 2022年7月16日
0.1.2 2022年7月16日
0.1.1 2022年7月15日
0.1.0 2022年7月15日

#1445数据库接口

MPL-2.0 许可证

48KB
1.5K SLoC

Json简化模式

编写模式的新方法

工具和实现

Intellij

Rust

  • jss-rs
  • jss-cli: TODO
  • jss-mock: TODO

Node

语法

描述

Aka. doc-comment,注释以 /// 开始

模式

顶层定义,指定所有顶层字段的约束

/// 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模式
{
    "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 License: object {
    additionalProperties: false
    required: [
        "name",
    ]
    patternProperties: {
        "^x-": {},
    }
    .name: string
    .url: string {
        format: "uri-reference"
    }
}
等效的json模式
{
    "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 可以缩写为 .

/// Dimensions for the product
property dimensions: object {
    .length: number
    .width: number
    .height: number

    required: ["length", "width", "height"]
}
等效的json模式
{
    "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的模拟数据生成器

依赖关系

~18–26MB
~431K SLoC