SchemaType Compiler, Validator, Translator, Formatter and Generator
# Check if a YAML file is well-formed: > stp validate -s file-schema.stp file.yaml
schematype package installs a CLI program called
stp tool has many functions related to SchemaType. It can do data document (YAML, JSON, others) validation. It can import other kinds of schema into SchemaType and it can export SchemaType back into those formats. It can compile and reformat SchemaType (
.stp) files. Most importantly, it can generate all kinds of software code from SchemaType files. These include:
- Input editors
- Server model code
- Database SQL
- Data visualizers
- Test input
stp command is currently written in Node.js. To install it, run:
> npm install -g schematype > stp -h
You can also easily run it as with Docker, if you have Docker installed and don't want to install it with Node.js/npm. See below.
stp command has many functions. It has a subcommand for each function. The general usage is:
stp <command> [<option>...] [<file>...]
Use this to get a help overview:
this to see the full help:
and this to get help for a specific command:
stp help <command>
See below for a full description of each command and option.
Running with Docker
If you use Docker, you don't need to install
stp or Node.js at all. Just create a shell alias:
alias stp='docker run --rm -it -v $PWD:/data schematype/stp'
then you can use the
stp alias just like an installed version of
These commands are currently supported:
compile-- Compile a
.stpfile to a
export-- Export a
.stpfile to a
.jsc(JSON Schema) file.
validate-- Validate one or more data documents against a schema.
These commands will be implemented soon:
convert-- Convert a data file from one format to another
create-- Create a .stp file from valid data files
format-- Reformat a .stp file to a desired style
generate-- Generate code from a schema file
import-- Import .stp from other formats
--verbose options are available for all commands. The
--schema option is used for all commands that need a schema. The
--output options specify files explicitly when they can't be inferred from a file list. The
--to options specify the input and output formats when they can't be inferred from file extensions or content heuristics.
Many commands accept a list of file paths to perform the specified operation on. Input files can either be local paths or they can be URLs. You can also use the
--input option to specify one input explicitly. The
--input option should not be used along with a file list. Use one or the other.
stp command has the following options:
stpto be less noisy about what it is doing.
stpto be more moisy about what it is doing.
--schema=<file>Specify the schema to use for this operation. Schema files end with
.stpand compiled schema files end with
.stpx. If the schema path is specified without a file extension,
stpwill look for a
.stpxfile, and then for a
.stpfile. If the path is a directory (URLs should end with
stpwill look for
--input=<file>Specify a single input file path (or URL) for the operation. Use this in place of the file list argument if appropriate. A value of
-indicates that the input will be read from STDIN. The file extension will be used as the
--fromvalue, if that is needed.
--output=<file>Specify a single output file path for the operation. A value of
-indicates that the output will be written to STDOUT. The file extension will br used as the
--tovalue, if needed.
--from=<format>SchemaType commands can operate on different types of input data (like YAML or JSON) for example. The
--fromoption explicitly specifies the input format. Usually
stpcan correctly guess the input format. Use this option when it can't.
--to=<format>Explicitly specify the output format for the command.
stpwrites output files, there is often more than one way to do it. This option specifies the output layout style to use. Current styles are:
.stpfiles in a more compact form. Write JSON files without whitespace between tokens. The JSON default is a pretty style.
.stpfiles in a more explicit style. The default is a medium between compact and explicit.
You can try out
stp yourself with these commands:
> git clone https://github.com/schematype/schematype-js > cd schematype-js/test/manifest > stp validate -s manifest.stp manifest.yml > stp compile -i manifest.stp > stp export -i manifest.stp -t jsc
Or you can skip the
git clone and do it using URLs for the file names:
> stp validate -s \ https://raw.githubusercontent.com/schematype/schematype-js/master/test/manifest/manifest.stp \ https://raw.githubusercontent.com/Stackato-Apps/django-cms/stackato-3.6/manifest.yml
- "JSON Schema"<...>