-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the SchemaType wiki!
Please read the SchemaType Wiki Editing Guide before editing here.
SchemaType is a language for defining detailed semantics and intentions of data structures. It is intended to be used with key/value data formats such as YAML, JSON, CSV, RDBMS, etc.
SchemaType is more than a traditional schema language. Most schema languages are targeted at data integrity and validation. SchemaType does those as well, but adds code generation and format interchange. The dream is that by richly and precisely defining your data, you can generate things like:
- Input (G)UIs
- SQL Schemas
- Transfer protocol definitions
- Server code
- Server API code
- Test suites
- Fuzz test data
- Documentation
In big software projects, data structure changes happen all the time, and they require changes at many levels. This needs to be done by programmers, and that is expensive. Imagine if all the related code could be rewritten instantly. That's what SchemaType is all about.
Validation isn't even required by the software, because it has been generated by the same definitions as the validator would use. In other words, the generated input UI is incapable of allowing data that doesn't meet your requirements.
The SchemaType project has the following components:
You write the definitions of your data structures in the SchemaType DSL.
Here's a tiny example of a schema file likely called soldier.stp
:
SchemaType v0.0.1 +0.1.2
soldier =
+ name => !person/name
+ rank => [private corporal sergeant]
+ serial-number => /{digit}{9,10}[ABC]/
? age => [18..65]
? gender => [female male]
This defines a mapping where the name
, rank
and serial-number
are required, and the age
and gender
are optional.
The !
is a typeref indicator.
The person/name
type was imported from the SchemaType core types repository (version 0.1.2).
Also we used version 0.0.1 of the SchemaType specification.
SchemaType will have a written spec explaining the language. It will also be defined by a comprehensive test suite.
SchemaType defines a handful of type primitives in the specification. These are defined by exact words in a spec, which is then translated into the code of the compiler and tools. Every other type is an extension of those primitives.
SchemaType then defines 1000s of useful, real world types that you can import and extend yourself.
These types are in hosted repositories and you import them into your schemas with the Import
directive.
There is nothing special about these SchemaType repositories though.
They can be defined by anyone.
You can even build a business over your own internal type repositories if you wish.
SchemaType provides a command called stp
to invoke:
- The compiler
- The validators
- The code generators
The stp compile ...
command takes DSL schemas, fetches the imported type repositories and compiles everything from a .stp
file to a .stpx
file.
This file is then the immutable source of truth for your data structures.
You can in turn host the .stpx
files yourself for other to use.
The .stpx
internal format is JSON by default.
The compiler can also output native language code if you want.
For instance if you compile to C, your output would go into a .stpx.c
file.