|
245 | 245 | if ~isempty(kindschema) |
246 | 246 | obj.setschema(kindschema); |
247 | 247 | elseif isempty(obj.schema) |
248 | | - error('Unknown kind "%s" and no schema defined. Use: uuid, date, time, datetime, ipv4, ipv6, email, uri, posint, nonnegative', kindval); |
| 248 | + error('Unknown kind "%s" and no schema defined. Use: uuid, date, time, datetime, email, uri', kindval); |
249 | 249 | end |
250 | 250 | obj.setattr(char(36), 'kind', kindval); |
251 | 251 | if (isempty(obj.data)) |
|
1322 | 1322 |
|
1323 | 1323 | % predefined schemas for known kinds |
1324 | 1324 | function schema = getkindschema_(kind) |
| 1325 | + schema = []; |
| 1326 | + int = @(mn, mx) struct('type', 'integer', 'minimum', mn, 'maximum', mx); |
| 1327 | + obj = @(p, r) struct('type', 'object', 'properties', p, 'required', {r}); |
| 1328 | + bintypes = {'uint8', 'int8', 'uint16', 'int16', 'uint32', 'int32', 'uint64', 'int64', 'single', 'double', 'logical'}; |
1325 | 1329 | switch lower(kind) |
1326 | | - case 'bytes' |
1327 | | - schema = struct('type', 'array', 'items', struct('type', 'integer', 'minimum', 0, 'maximum', 255)); |
1328 | 1330 | case 'uuid' |
1329 | | - schema = struct('type', 'object', ... |
1330 | | - 'properties', struct( ... |
1331 | | - 'time_low', struct('type', 'integer', 'minimum', 0, 'maximum', 4294967295), ... % 32-bit |
1332 | | - 'time_mid', struct('type', 'integer', 'minimum', 0, 'maximum', 65535), ... % 16-bit |
1333 | | - 'time_high', struct('type', 'integer', 'minimum', 0, 'maximum', 65535), ... % 16-bit |
1334 | | - 'clock_seq', struct('type', 'integer', 'minimum', 0, 'maximum', 65535), ... % 16-bit |
1335 | | - 'node', struct('type', 'integer', 'minimum', 0, 'maximum', 281474976710655)), ... % 48-bit |
1336 | | - 'required', {{'time_low', 'time_mid', 'time_high', 'clock_seq', 'node'}}); |
| 1331 | + schema = obj(struct('time_low', int(0, 4294967295), 'time_mid', int(0, 65535), 'time_high', int(0, 65535), 'clock_seq', int(0, 65535), 'node', int(0, 281474976710655)), {'time_low', 'time_mid', 'time_high', 'clock_seq', 'node'}); |
1337 | 1332 | case 'date' |
1338 | | - schema = struct('type', 'object', ... |
1339 | | - 'properties', struct( ... |
1340 | | - 'year', struct('type', 'integer', 'minimum', 1, 'maximum', 9999), ... |
1341 | | - 'month', struct('type', 'integer', 'minimum', 1, 'maximum', 12), ... |
1342 | | - 'day', struct('type', 'integer', 'minimum', 1, 'maximum', 31)), ... |
1343 | | - 'required', {{'year', 'month', 'day'}}); |
| 1333 | + schema = obj(struct('year', int(1, 9999), 'month', int(1, 12), 'day', int(1, 31)), {'year', 'month', 'day'}); |
1344 | 1334 | case 'time' |
1345 | | - schema = struct('type', 'object', ... |
1346 | | - 'properties', struct( ... |
1347 | | - 'hour', struct('type', 'integer', 'minimum', 0, 'maximum', 23), ... |
1348 | | - 'min', struct('type', 'integer', 'minimum', 0, 'maximum', 59), ... |
1349 | | - 'sec', struct('type', 'number', 'minimum', 0, 'exclusiveMaximum', 60)), ... |
1350 | | - 'required', {{'hour', 'min', 'sec'}}); |
| 1335 | + schema = obj(struct('hour', int(0, 23), 'min', int(0, 59), 'sec', struct('type', 'number', 'minimum', 0, 'exclusiveMaximum', 60)), {'hour', 'min', 'sec'}); |
1351 | 1336 | case 'datetime' |
1352 | | - schema = struct('type', 'object', ... |
1353 | | - 'properties', struct( ... |
1354 | | - 'year', struct('type', 'integer', 'minimum', 1, 'maximum', 9999), ... |
1355 | | - 'month', struct('type', 'integer', 'minimum', 1, 'maximum', 12), ... |
1356 | | - 'day', struct('type', 'integer', 'minimum', 1, 'maximum', 31), ... |
1357 | | - 'hour', struct('type', 'integer', 'minimum', 0, 'maximum', 23), ... |
1358 | | - 'min', struct('type', 'integer', 'minimum', 0, 'maximum', 59), ... |
1359 | | - 'sec', struct('type', 'number', 'minimum', 0, 'exclusiveMaximum', 60)), ... |
1360 | | - 'required', {{'year', 'month', 'day', 'hour', 'min', 'sec'}}); |
| 1337 | + schema = obj(struct('year', int(1, 9999), 'month', int(1, 12), 'day', int(1, 31), 'hour', int(0, 23), 'min', int(0, 59), 'sec', struct('type', 'number', 'minimum', 0, 'exclusiveMaximum', 60)), {'year', 'month', 'day', 'hour', 'min', 'sec'}); |
1361 | 1338 | case 'email' |
1362 | | - schema = struct('type', 'object', ... |
1363 | | - 'properties', struct( ... |
1364 | | - 'user', struct('type', 'string', 'minLength', 1), ... |
1365 | | - 'domain', struct('type', 'string', 'pattern', '^[^@\s]+\.[^@\s]+$')), ... |
1366 | | - 'required', {{'user', 'domain'}}); |
| 1339 | + schema = obj(struct('user', struct('type', 'string', 'minLength', 1), 'domain', struct('type', 'string', 'pattern', '^[^@\s]+\.[^@\s]+$')), {'user', 'domain'}); |
1367 | 1340 | case 'uri' |
1368 | | - schema = struct('type', 'object', ... |
1369 | | - 'properties', struct( ... |
1370 | | - 'scheme', struct('type', 'string', 'pattern', '^[a-zA-Z][a-zA-Z0-9+.-]*$'), ... |
1371 | | - 'host', struct('type', 'string', 'minLength', 1), ... |
1372 | | - 'port', struct('type', 'integer', 'minimum', 0, 'maximum', 65535), ... |
1373 | | - 'path', struct('type', 'string'), ... |
1374 | | - 'query', struct('type', 'string'), ... |
1375 | | - 'fragment', struct('type', 'string')), ... |
1376 | | - 'required', {{'scheme', 'host'}}); |
| 1341 | + schema = obj(struct('scheme', struct('type', 'string', 'pattern', '^[a-zA-Z][a-zA-Z0-9+.-]*$'), 'host', struct('type', 'string', 'minLength', 1), 'port', int(0, 65535), 'path', struct('type', 'string'), 'query', struct('type', 'string'), 'fragment', struct('type', 'string')), {'scheme', 'host'}); |
1377 | 1342 | otherwise |
1378 | | - schema = []; |
| 1343 | + if ismember(lower(kind), bintypes) |
| 1344 | + schema = struct('binType', lower(kind)); |
| 1345 | + end |
1379 | 1346 | end |
1380 | 1347 | end |
1381 | 1348 |
|
|
0 commit comments