|
80 | 80 | % 'dependentSchemas', 'allOf', 'anyOf', 'oneOf', 'not', |
81 | 81 | % 'if', 'then', 'else', 'title', 'description', 'examples', |
82 | 82 | % '$comment', '$ref', '$defs', 'definitions' |
| 83 | +% |
| 84 | +% to enable validation of strongly-typed ND arrays, we also |
| 85 | +% extended JSON schema add added the following 3 keywords |
| 86 | +% 'binType': must be one of |
| 87 | +% 'uint8','int8','uint8','int8','uint8','int8','uint8','int8','single','double','logical' |
| 88 | +% 'minDims' and 'maxDims': sets the min/max dimension |
| 89 | +% vector (i.e. size(data)); when minDims/maxDims |
| 90 | +% contains a single integer, it expects data to be a |
| 91 | +% 1D vector of a valid length |
83 | 92 | % schema = jd.attr2schema('title', 'Nested Example') exports the |
84 | 93 | % schema-attributes as a JSON schema object |
85 | 94 | % |
|
165 | 174 | % 'age',struct('type','integer','minimum',0)),... |
166 | 175 | % 'required',{{'name','age'}}); |
167 | 176 | % jd.setschema(schema); |
168 | | -% err = jd.validate(); % validate data against schema |
169 | | -% jd.getschema('json') % get schema as JSON string |
| 177 | +% err = jd.validate(); % validate data against schema |
| 178 | +% jd.getschema('json') % get schema as JSON string |
| 179 | +% |
| 180 | +% jd = jdict; |
| 181 | +% jd{':type'}='array'; % expects an array |
| 182 | +% jd{':binType'}='uint8'; % expects a uint8 array |
| 183 | +% jd{':minDims'}=2; % expects a 1D uint8 array of min length of 2 |
| 184 | +% jd{':maxDims'}=6; % expects a 1D uint8 array of max length of 6 |
| 185 | +% jd.setschema(jd.attr2schema()); % use ':keyword' attributes to create a schema |
| 186 | +% jd <= uint8([1,2,3]) % this works |
| 187 | +% %jd <= [1,2;3 4] % 2D array fails dims and binType check |
170 | 188 | % |
171 | 189 | % % loading complex data from REST-API |
172 | 190 | % jd = jdict('https://neurojson.io:7777/cotilab/NeuroCaptain_2025'); |
|
1092 | 1110 | allflags = [varargin(1:2:end); varargin(2:2:end)]; |
1093 | 1111 | opt = struct(allflags{:}); |
1094 | 1112 |
|
1095 | | - schemaKeywords = {'type', 'enum', 'const', 'default', ... |
| 1113 | + schemaKeywords = {'type', 'enum', 'const', 'default', 'binType', 'minDims', 'maxDims', ... |
1096 | 1114 | 'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'multipleOf', ... |
1097 | 1115 | 'minLength', 'maxLength', 'pattern', 'format', ... |
1098 | 1116 | 'items', 'minItems', 'maxItems', 'uniqueItems', 'contains', 'prefixItems', ... |
|
0 commit comments