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

Commit

Permalink
Merge pull request #18 from apiaryio/pksunkara/fixes
Browse files Browse the repository at this point in the history
Fix bugs which have been occurring
  • Loading branch information
zdne committed Apr 2, 2015
2 parents 806b7c4 + e1cb984 commit c0b0e8b
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drafter",
"version": "0.2.0",
"version": "0.2.1",
"author": "Apiary.io <[email protected]>",
"description": "Snow Crash parser harness",
"license": "MIT",
Expand Down
5 changes: 3 additions & 2 deletions src/rules/mson-inheritance.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ module.exports =
dataStructure.sections.push memberTypeSection
dataStructure.typeDefinition.typeSpecification.nestedTypes = []

if superType is null or typeof superType isnt 'object' or not superType?.literal
return @expanded[superType] = true
# Make sure super type is valid
if superType is null or typeof superType isnt 'object' or not superType?.literal or not @dataStructures[superType.literal]
return @expanded[name] = true

# Expand the super type first
@expandInheritance superType.literal, @dataStructures[superType.literal]
Expand Down
2 changes: 1 addition & 1 deletion src/rules/mson-member-type-name.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports =
superType = member.content.valueDefinition.typeDefinition.typeSpecification.name

# If super type is a valid symbol
if typeof superType is 'object' and superType?.literal
if typeof superType is 'object' and superType?.literal and @dataStructures[superType.literal]
@expandMember superType.literal, @dataStructures[superType.literal]

superTypeBaseName = @dataStructures[superType.literal].typeDefinition.typeSpecification.name
Expand Down
9 changes: 6 additions & 3 deletions src/rules/mson-mixin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ module.exports =
when 'mixin'
superType = member.content.typeSpecification.name

# Expand the super type first
@expandMixin superType.literal, @dataStructures[superType.literal]
rule.copyMembers @dataStructures[superType.literal], sectionOrMember
# Make sure the super type exists
if typeof superType is 'object' and superType?.literal and @dataStructures[superType.literal]

# Expand the super type first
@expandMixin superType.literal, @dataStructures[superType.literal]
rule.copyMembers @dataStructures[superType.literal], sectionOrMember

when 'oneOf', 'group'
memberType =
Expand Down
2 changes: 1 addition & 1 deletion src/rules/rule.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports =
# @param dataStructure [Object] The super type data structure
# @param memberTypeSection [Object] Member Type Section to be copied into
copyMembers: (dataStructure, memberTypeSection) ->
return if not dataStructure
return if not dataStructure or not memberTypeSection

for section in dataStructure.sections
if section['class'] is 'memberType'
Expand Down
61 changes: 61 additions & 0 deletions test/unit/drafter-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,64 @@ describe 'Drafter Class', ->
assert.deepEqual result.ast, require '../fixtures/dataStructures.ast.json'

done()

it 'parses correctly when super type of a member is not found', (done) ->
drafter = new Drafter

blueprint = '''
# Polls [/]
+ Attributes
+ owner (Person)
'''

drafter.make blueprint, (error, result) ->
assert.isNull error
assert.ok result.ast
done()

it 'parses correctly when super type of a type is not found', (done) ->
drafter = new Drafter

blueprint = '''
# Polls [/]
## Get a Poll [GET]
+ Attributes (Person)
+ id
'''

drafter.make blueprint, (error, result) ->
assert.isNull error
assert.ok result.ast
done()

it 'parses correctly when named type in a mixin is not found', (done) ->
drafter = new Drafter

blueprint = '''
# Polls [/]
+ Attributes
+ Include Person
'''

drafter.make blueprint, (error, result) ->
assert.isNull error
assert.ok result.ast
done()

it 'parses correctly when named type in a mixin is a primitive type', (done) ->
drafter = new Drafter

blueprint = '''
# Polls [/]
+ Attributes
+ Include string
'''

drafter.make blueprint, (error, result) ->
assert.isNull error
assert.ok result.ast
done()

0 comments on commit c0b0e8b

Please sign in to comment.