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

Commit c0b0e8b

Browse files
committed
Merge pull request #18 from apiaryio/pksunkara/fixes
Fix bugs which have been occurring
2 parents 806b7c4 + e1cb984 commit c0b0e8b

File tree

6 files changed

+73
-8
lines changed

6 files changed

+73
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drafter",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"author": "Apiary.io <[email protected]>",
55
"description": "Snow Crash parser harness",
66
"license": "MIT",

src/rules/mson-inheritance.coffee

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ module.exports =
6363
dataStructure.sections.push memberTypeSection
6464
dataStructure.typeDefinition.typeSpecification.nestedTypes = []
6565

66-
if superType is null or typeof superType isnt 'object' or not superType?.literal
67-
return @expanded[superType] = true
66+
# 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]
68+
return @expanded[name] = true
6869

6970
# Expand the super type first
7071
@expandInheritance superType.literal, @dataStructures[superType.literal]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports =
3030
superType = member.content.valueDefinition.typeDefinition.typeSpecification.name
3131

3232
# If super type is a valid symbol
33-
if typeof superType is 'object' and superType?.literal
33+
if typeof superType is 'object' and superType?.literal and @dataStructures[superType.literal]
3434
@expandMember superType.literal, @dataStructures[superType.literal]
3535

3636
superTypeBaseName = @dataStructures[superType.literal].typeDefinition.typeSpecification.name

src/rules/mson-mixin.coffee

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ module.exports =
3030
when 'mixin'
3131
superType = member.content.typeSpecification.name
3232

33-
# Expand the super type first
34-
@expandMixin superType.literal, @dataStructures[superType.literal]
35-
rule.copyMembers @dataStructures[superType.literal], sectionOrMember
33+
# Make sure the super type exists
34+
if typeof superType is 'object' and superType?.literal and @dataStructures[superType.literal]
35+
36+
# Expand the super type first
37+
@expandMixin superType.literal, @dataStructures[superType.literal]
38+
rule.copyMembers @dataStructures[superType.literal], sectionOrMember
3639

3740
when 'oneOf', 'group'
3841
memberType =

src/rules/rule.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports =
55
# @param dataStructure [Object] The super type data structure
66
# @param memberTypeSection [Object] Member Type Section to be copied into
77
copyMembers: (dataStructure, memberTypeSection) ->
8-
return if not dataStructure
8+
return if not dataStructure or not memberTypeSection
99

1010
for section in dataStructure.sections
1111
if section['class'] is 'memberType'

test/unit/drafter-test.coffee

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,64 @@ describe 'Drafter Class', ->
2323
assert.deepEqual result.ast, require '../fixtures/dataStructures.ast.json'
2424

2525
done()
26+
27+
it 'parses correctly when super type of a member is not found', (done) ->
28+
drafter = new Drafter
29+
30+
blueprint = '''
31+
# Polls [/]
32+
33+
+ Attributes
34+
+ owner (Person)
35+
'''
36+
37+
drafter.make blueprint, (error, result) ->
38+
assert.isNull error
39+
assert.ok result.ast
40+
done()
41+
42+
it 'parses correctly when super type of a type is not found', (done) ->
43+
drafter = new Drafter
44+
45+
blueprint = '''
46+
# Polls [/]
47+
## Get a Poll [GET]
48+
49+
+ Attributes (Person)
50+
+ id
51+
'''
52+
53+
drafter.make blueprint, (error, result) ->
54+
assert.isNull error
55+
assert.ok result.ast
56+
done()
57+
58+
it 'parses correctly when named type in a mixin is not found', (done) ->
59+
drafter = new Drafter
60+
61+
blueprint = '''
62+
# Polls [/]
63+
64+
+ Attributes
65+
+ Include Person
66+
'''
67+
68+
drafter.make blueprint, (error, result) ->
69+
assert.isNull error
70+
assert.ok result.ast
71+
done()
72+
73+
it 'parses correctly when named type in a mixin is a primitive type', (done) ->
74+
drafter = new Drafter
75+
76+
blueprint = '''
77+
# Polls [/]
78+
79+
+ Attributes
80+
+ Include string
81+
'''
82+
83+
drafter.make blueprint, (error, result) ->
84+
assert.isNull error
85+
assert.ok result.ast
86+
done()

0 commit comments

Comments
 (0)