Enums and string-format validation boundaries
Compact enums use status:{draft|published} (semicolon also separates choices). The string is trimmed before exact, case-sensitive membership checking. A required enum rejects an omitted/empty value. Nested objects use {name:Type}; they are not enum declarations.
In total5@0.0.19, Color accepts hexadecimal #RGB, #RRGGBB and #RRGGBBAA; it does not accept CSS color names. Icon validates a class-name pattern, not the presence of the icon asset. Base64 and Zip use the framework's validators: format acceptance is not content verification. In the compact-schema parser of this version, JSON and IP are not recognized subtypes and fall back to plain strings. Malformed JSON and invalid IP text are accepted. The explicit JSON Schema below sets native subtype values to enable these checks; it does not parse a JSON string into an object. Do not use SafeString in place of bound SQL parameters or output escaping.
var schema = NEWSCHEMA('FormatBoundaries', '*status:{draft|published},*color:Color,*blob:Base64,*zip:Zip,*icon:Icon,*document:JSON,*address:IP');
var explicit = Total.newjsonschema('ExplicitFormats', { $id: 'ExplicitFormats', type: 'object', required: ['document','address'], properties: { document: { type: 'string', subtype: 'json' }, address: { type: 'string', subtype: 'ip' } } });
exports.install = function() {
ROUTE('POST /explicit/ @json', function($) {
var result = explicit.transform($.body);
if (result.error) { $.response.status = 400; $.json({ error: 'invalid format' }); }
else $.json(result.response);
});
ROUTE('POST /formats/ @json', formats);
};
function formats($) {
var result = schema.transform($.body);
if (result.error) {
$.response.status = 400;
$.json({ error: 'invalid format' });
} else
$.json(result.response);
}