9 releases
0.0.9 | Dec 2, 2020 |
---|---|
0.0.8 | Nov 4, 2020 |
0.0.7 | Dec 6, 2018 |
0.0.6 | Sep 19, 2018 |
0.0.4 | Nov 22, 2017 |
#1076 in Development tools
51KB
1.5K
SLoC
Chema
Generate JSON Schema from a lightweight DSL.
This is originally intended to generate a definitions
section of swagger specifications
Install
Download a binary from https://github.com/KeenS/chema/releases
or if you have setup cargo
, use `cargo install like below
$ cargo install chema
Usage
chema 0.0.8
Sunrin SHIMURA (keen) <3han5chou7@gmail.com>
An external DSL for JSON Schema
USAGE:
chema [FLAGS] [OPTIONS] <input>
FLAGS:
-h, --help Prints help information
--no-swagger don't use swagger spesific notation
--pack if pack the output
-V, --version Prints version information
OPTIONS:
--format <format> output format (json|yaml) [default: json]
--path-prefix <path_prefix> path prefix of paths [default: /definitions]
ARGS:
<input> input file
Syntax
TOP = ITEMS
ITEMS = ITEM+
ITEM = TYPEDEF
TYPEDEF = "type" IDENT "=" TYPE ";"
TYPE = "null" | "boolean" | "object" | "number" | "string" | "integer"
| IDENT | "[" TYPE "]" | STRUCT | ENUM | TYPE "?"
| "format" "(" STRING ")" | "url" "(" STRING ")"
| TYPE "&" TYPE | TYPE "|" TYPE
| TYPE "where" PRED
| "(" TYPE ")" | STRING
STRUCT = "struct" "{" (FIELD ",")+ "}"
FIELD = IDENT "?"? ":" TYPE
ENUM = "enum" "{" (VARIANT",")+ "}"
VARIANT = STRING
PRED = UNUMBER "<=" "length" | "length" <= UNUMBER
| "format" "=" STRING | "it" "=~" REGEX
| PRED && PRED
IDENT = [a-zA-Z_][a-zA-Z0-9_]*
STRIING = "\"" ([^"\\]|\\.)* "\""
REGEX = "/" ([^/\\]|\\.)* "/"
UNUMBER = [0-9]+
COMMENT = "//" any "\n" | "/*" any "*/"
DOC_COMMENT = "/**" any "*/"
Example
See etc. *.jsd
s are the sources and *.jsons
are the generated files.
Supported Platforms
UNIX-like system will be supported. Ubuntu LTS is the major target. Windows support is best effort and may not work .
Dependencies
~9–17MB
~234K SLoC