Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/jsdoc-to-json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ function buildJsonSchema(comments) {
schema.properties[block.name].uniqueItems = (value === 'true');
} break;

/* customize on default */

case 'default': {
var blocktype = block.customTags.find(t => t.tag === 'schema.type').value || 'unknown';
switch (blocktype) {
case 'array': {
schema.properties[block.name][tag] = (JSON.parse(value.replace('\\"', '""')));
} break;
default: {
schema.properties[block.name][tag] = value;
} break;
}
} break;

/* strings */

case 'extends':
Expand All @@ -176,7 +190,6 @@ function buildJsonSchema(comments) {
case 'enum':
case 'description':
case 'name':
case 'default':
default: {
schema.properties[block.name][tag] = value;
} break;
Expand Down
13 changes: 12 additions & 1 deletion test/data/test-singleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,16 @@ var product = {
* @schema.minimum 0
* @schema.required true
*/
price: ''
price: '',

/**
* @schema.title SKUs
* @schema.description SKUs of the product
* @schema.type array
* @schema.minItems 1
* @schema.items [integer]
* @schema.default [42, "anothersku"]
* @schema.required true
*/
skus: []
};
10 changes: 10 additions & 0 deletions test/jsdoctojsonschema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ describe('jsdoc-to-json-schema', function () {
expect(schema.properties.price.minimum).toEqual(0);
expect(schema.properties.price.required).toEqual(true);

// .skus property
expect(schema.properties.skus).toBeDefined();
expect(schema.properties.skus.type).toEqual('array');
expect(schema.properties.skus.title).toEqual('SKUs');
expect(schema.properties.skus.description).toEqual('SKUs of the product');
expect(schema.properties.skus.minItems).toEqual(1);
expect(schema.properties.skus.items).toEqual('[integer]');
expect(schema.properties.skus.default).toEqual([42, 'anothersku']);
expect(schema.properties.skus.required).toEqual(true);

done();
})
.catch(function(err){
Expand Down