On project creation, you are supplied with a basic schema, lets go over it!
{ your_project: { // project modifiers add_validator:true, add_tablestamp:true, set_debug_level:3, with_api:true, "authy('User')":{ // table modifiers set_parent_menu:"Settings", set_menu_priority: 200, set_list_hide_columns: ["rights", "passwd_hash"], add_search_columns: { "Name":[["username", "%val", "or"], ["email", "%val"]], "Primary group":[["id_authy_group", "%val"]] }, with_child_tables: ["authy_group_x", "authy_log"], // columns id_authy:["primary"] // missing comma, no worry // use of quote and unquoted string, you should decide whats best for you validation_key:"string(32)" "username(Username)":["string(32)", "not-required", "unique"], "fullname(Fullname)":["string(100)", "not-required"], "email(Email)":["string(100)", "required"], "passwd_hash(Password)":["string(32)", "required"], "expire(Expiration)":["date()", "default:0000-00-00"], deactivate(Deactivated):["enum(Yes, No)", "default:No"], // validators validator:{ email:{ required:"message_authy_email_required", unique:"message_authy_email_in_use", }, passwd_hash:{ required:"message_authy_password_required" } } } } }
Structure
The overall structure is very flexible as you can see, this is HJSON after all.
- Commas are optional
- Comments are supported in different styles (#, // or block /* */)
- Object names can be specified without quotes.
- You can specify strings without quotes.
- Write multiline strings with proper whitespace handling.
Languages
The is 4 components to the schema:
- Database
- Table
- Column
- Modifier
Database
The object key is the name.
APIgoat supports only one database for the moment.
Tables
Tables contains columns and modifiers.
The object key is database_name(‘Caption’). As in the example above, the table name in the database and API will be ‘authy‘. All reference to the table in the backend will be to ‘User‘ or the plural version when proper.
Columns
Same as the table, the object key is database_name(‘Caption’), where database_name is the name of the column in the database, and Caption the label(s) for the fields.
Column have more parameters obviously. They will be following the key.
All the SQL parameters are supported, simply add parameter:value to the column.
But the most used types have shorcuts:
Shortcut string | Default SQL type |
primary(length) | integer(lenght or 11) autoIncrement primaryKey required not null |
foreign(foreign_table) | integer(11) required not null, both local and foreign column must have the same name. |
string(length) | varchar(lenght or 32) required not null |
integer(length) | integer(lenght or 11) required not null |
enum(choice1,choice2,..) | integer(4) required not null but map in code as ENUM |
date() | date format Y-m-d required not null |
decimal(size, scale) | decimal(size or 6, scale or 2) required not null |
text(length) | longvarchar(lenght or 254) required not null |
timestamp() | timestamp required not null |
Parameters to a column can be a string or an array. String should be one of the above. Array can have a variety of parameters:
Array shortcuts | SQL equivalent |
required / not-required | |
null / not-null | |
default | default value as default:value |
auto-increment | |
foreign | |
index | add index |
unique | add unique index |
You can also specify any propel parameters as key:value.
Modifiers
Modifiers applies to the backend and API behavior. They help you make a rich interface that fits the needs of your client.
See the Modifiers documentation to get the full idea of what can be done.
You can check the HJSON to XML converter in GitHub if you want to contribute.