Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit bbd033e

Browse files
authored
Merge pull request #2 from KeepSafe/features/document_array_param_without_name
add possibility to document an array without name
2 parents f22519b + 6b4f9de commit bbd033e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/parsers/api_param.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ var regExp = {
3535
e: '\\s*\\}\\s*)?' // ending with '}', optional surrounding spaces
3636
},
3737
wName: {
38-
b: '(\\[?\\s*', // 5 optional optional-marker
39-
name: '([a-zA-Z0-9\\:\\.\\/\\\\_-]+', // 6
38+
b: '((?:\\[?\\s*)(?!\\])\\s*', // 5 optional optional-marker
39+
name: '((?:(?:\\[\\])?[a-zA-Z0-9\\:\\.\\/\\\\_-]+|\\[\\])', // 6 allow to document an array (name field as [])
4040
withArray: '(?:\\[[a-zA-Z0-9\\.\\/\\\\_-]*\\])?)', // https://github.com/apidoc/apidoc-core/pull/4
4141
oDefaultValue: { // optional defaultValue
4242
b: '(?:\\s*=\\s*(?:', // starting with '=', optional surrounding spaces
@@ -110,7 +110,7 @@ function parse(content, source, defaultGroup) {
110110
type : matches[2],
111111
size : matches[3],
112112
allowedValues: allowedValues,
113-
optional : (matches[5] && matches[5][0] === '[') ? true : false,
113+
optional : !!(matches[5] && matches[5][0] === '[' && matches[5][1] !== ']'),
114114
field : matches[6],
115115
defaultValue : matches[7] || matches[8] || matches[9],
116116
description : unindent(matches[10] || '')

test/parser_api_param_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,29 @@ describe('Parser: apiParam', function() {
4545
{
4646
title: 'All options, with optional defaultValue',
4747
content: ' ( MyGroup ) { \\Object\\String.uni-code_char[] { 1..10 } = \'abc\', \'def\' } ' +
48-
'[ \\MyClass\\field.user_first-name = \'John Doe\' ] Some description.',
48+
'[ []\\MyClass\\field.user_first-name = \'John Doe\' ] Some description.',
4949
expected: {
5050
group: 'MyGroup',
5151
type: '\\Object\\String.uni-code_char[]',
5252
size: '1..10',
5353
allowedValues: [ '\'abc\'', '\'def\'' ],
5454
optional: true,
55-
field: '\\MyClass\\field.user_first-name',
55+
field: '[]\\MyClass\\field.user_first-name',
5656
defaultValue: 'John Doe',
5757
description: 'Some description.'
5858
}
5959
},
6060
{
6161
title: 'All options, without optional-marker',
6262
content: ' ( MyGroup ) { \\Object\\String.uni-code_char[] { 1..10 } = \'abc\', \'def\' } ' +
63-
'\\MyClass\\field.user_first-name = \'John Doe\' Some description.',
63+
'[]\\MyClass\\field.user_first-name = \'John Doe\' Some description.',
6464
expected: {
6565
group: 'MyGroup',
6666
type: '\\Object\\String.uni-code_char[]',
6767
size: '1..10',
6868
allowedValues: [ '\'abc\'', '\'def\'' ],
6969
optional: false,
70-
field: '\\MyClass\\field.user_first-name',
70+
field: '[]\\MyClass\\field.user_first-name',
7171
defaultValue: 'John Doe',
7272
description: 'Some description.'
7373
}

0 commit comments

Comments
 (0)