Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit b6a83a9

Browse files
committed
Merge pull request #25 from apiaryio/pksunkara/fixes
Bug Squashing and Updating Protagonist & Boutique
2 parents dfb334f + 96c784b commit b6a83a9

File tree

9 files changed

+60
-21
lines changed

9 files changed

+60
-21
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drafter",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"author": "Apiary.io <support@apiary.io>",
55
"description": "Snow Crash parser harness",
66
"license": "MIT",
@@ -18,10 +18,10 @@
1818
},
1919
"dependencies": {
2020
"async": "~0.9.0",
21-
"boutique": "~0.1.4",
21+
"boutique": "~0.1.5",
2222
"deep-equal": "1.0.x",
2323
"deepcopy": "0.4.x",
24-
"protagonist": "~0.19.1",
24+
"protagonist": "~0.19.3",
2525
"yargs": "~1.3.3"
2626
},
2727
"devDependencies": {

src/rules/mson-inheritance.coffee

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module.exports =
88

99
# Expand dataStructure element
1010
dataStructure: (element) ->
11-
superType = element.typeDefinition.name
1211
typeName = element.name
1312

1413
if not typeName
@@ -63,8 +62,12 @@ module.exports =
6362
dataStructure.sections.push memberTypeSection
6463
dataStructure.typeDefinition.typeSpecification.nestedTypes = []
6564

65+
# If super type is null, it is an implicit object
66+
if superType is null
67+
dataStructure.typeDefinition.typeSpecification.name = 'object'
68+
6669
# Make sure super type is valid
67-
if superType is null or typeof superType isnt 'object' or not superType?.literal or not @dataStructures[superType.literal]
70+
if typeof superType isnt 'object' or not superType?.literal or not @dataStructures[superType.literal]
6871
return @expanded[name] = true
6972

7073
# Expand the super type first

src/rules/mson-member-type-name.coffee

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module.exports =
88

99
# Expand dataStructure element
1010
dataStructure: (element) ->
11-
superType = element.typeDefinition.name
1211
typeName = element.name
1312

1413
if not typeName
@@ -57,7 +56,7 @@ module.exports =
5756

5857
# Check for member type name
5958
for section in dataStructure.sections
60-
if section['class'] is 'memberType'
59+
if section['class'] is 'memberType' and section.content?
6160

6261
@diveIntoElements section.content
6362

src/rules/mson-mixin.coffee

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module.exports =
88

99
# Expand dataStructure element
1010
dataStructure: (element) ->
11-
superType = element.typeDefinition.name
1211
typeName = element.name
1312

1413
if not typeName
@@ -60,7 +59,7 @@ module.exports =
6059

6160
# Check for mixin
6261
for section in dataStructure.sections
63-
if section['class'] is 'memberType'
62+
if section['class'] is 'memberType' and section.content?
6463

6564
# New content for the section
6665
memberTypeSection =

src/rules/rule.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports =
88
return if not dataStructure or not memberTypeSection
99

1010
for section in dataStructure.sections
11-
if section['class'] is 'memberType'
11+
if section['class'] is 'memberType' and section.content?
1212

1313
for member in section.content
1414
memberTypeSection.content.push member

test/fixtures/dataStructures.apib

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ A coupon contains information about a percent-off or amount-off discount you mig
1515
The ID of the desired coupon.
1616

1717
+ Attributes (Coupon Base)
18-
+ id: 250FF (string)
18+
+ Properties
19+
+ id: 250FF (string)
1920

2021
### Retrieve a Coupon [GET]
2122
Retrieves the coupon with the given ID.
@@ -57,7 +58,7 @@ Unix timestamp as an integer
5758
+ created_at (Timestamp)
5859
+ updated_at (Timestamp)
5960

60-
## Timestamps (object)
61+
## Timestamps
6162
This object contains the following unix timestamps
6263

6364
+ created - Denoting the time when the object is created

test/fixtures/dataStructures.ast.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@
15321532
},
15331533
"typeDefinition": {
15341534
"typeSpecification": {
1535-
"name": "object",
1535+
"name": null,
15361536
"nestedTypes": []
15371537
},
15381538
"attributes": []
@@ -1917,7 +1917,7 @@
19171917
},
19181918
"typeDefinition": {
19191919
"typeSpecification": {
1920-
"name": null,
1920+
"name": "object",
19211921
"nestedTypes": []
19221922
},
19231923
"attributes": []
@@ -2594,7 +2594,7 @@
25942594
},
25952595
"typeDefinition": {
25962596
"typeSpecification": {
2597-
"name": null,
2597+
"name": "object",
25982598
"nestedTypes": []
25992599
},
26002600
"attributes": []

test/smoke/typing-test.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fs = require 'fs'
44

55
Drafter = require '../../src/drafter'
66

7-
KNOWN_PROBLEMATIC_LENGTHS = [631, 632, 633, 1464]
7+
KNOWN_PROBLEMATIC_LENGTHS = []
88

99
describe 'Typing test', ->
1010
blueprint = fs.readFileSync './test/fixtures/dataStructures.apib', 'utf8'

test/unit/drafter-test.coffee

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ describe 'Drafter Class', ->
3535
'''
3636

3737
drafter.make blueprint, (error, result) ->
38-
assert.isNull error
39-
assert.ok result.ast
38+
assert.isUndefined result
4039
done()
4140

42-
it 'parses correctly when super type of a type is not found', (done) ->
41+
it 'parses correctly when super type of a type in action attributes is not found', (done) ->
4342
drafter = new Drafter
4443

4544
blueprint = '''
@@ -66,8 +65,7 @@ describe 'Drafter Class', ->
6665
'''
6766

6867
drafter.make blueprint, (error, result) ->
69-
assert.isNull error
70-
assert.ok result.ast
68+
assert.isUndefined result
7169
done()
7270

7371
it 'parses correctly when named type in a mixin is a primitive type', (done) ->
@@ -99,3 +97,42 @@ describe 'Drafter Class', ->
9997
assert.isNull error
10098
assert.ok result.ast
10199
done()
100+
101+
it 'implicitly resolves base type to an object', (done) ->
102+
drafter = new Drafter
103+
104+
blueprint = '''
105+
# Root [/]
106+
## Retrieve the Entry Point [GET]
107+
+ Response 200 (application/json)
108+
+ Attributes
109+
+ Properties
110+
+ hello: 42 (string)
111+
+ nested (Question)
112+
113+
## Group Question
114+
## Question [/questions/{question_id}]
115+
+ Attributes
116+
+ question
117+
+ url
118+
'''
119+
120+
drafter.make blueprint, (error, result) ->
121+
assert.isNull error
122+
assert.ok result.ast
123+
124+
assert.equal result.ast.content[1].content[0].element, 'resource'
125+
126+
dataStructure = result.ast.content[1].content[0].content[0]
127+
128+
assert.equal dataStructure.element, 'dataStructure'
129+
assert.equal dataStructure.name.literal, 'Question'
130+
assert.isNull dataStructure.typeDefinition.typeSpecification.name
131+
132+
dataStructure = result.ast.content[1].content[0].content[1]
133+
134+
assert.equal dataStructure.element, 'resolvedDataStructure'
135+
assert.equal dataStructure.name.literal, 'Question'
136+
assert.equal dataStructure.typeDefinition.typeSpecification.name, 'object'
137+
138+
done()

0 commit comments

Comments
 (0)