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

Commit

Permalink
Forgot about copying mixins during inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Feb 9, 2015
1 parent 2c2d1b5 commit a34820b
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/drafter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Drafter

# Expand the gathered data structures
for rule in rules
rule.init.call rule, @dataStructures if 'dataStructures' in Object.keys(rule)
rule.init.call rule, @dataStructures if rule.init

# Apply rules to the current node
for rule in rules
Expand Down
8 changes: 4 additions & 4 deletions src/rules/mson-inheritance.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports =
if section['class'] is 'memberType'

for member in section.content
memberTypeSection.content.push member if member['class'] is 'property'
memberTypeSection.content.push member if member['class'] in ['property', 'mixin']

# Given a data structure, expand it's inheritance recursively
#
Expand All @@ -27,16 +27,16 @@ module.exports =
# Check for inheritance
superType = dataStructure.typeDefinition.typeSpecification.name

if typeof superType isnt 'object' or not superType?.literal
if superType is null or typeof superType isnt 'object' or not superType?.literal
return @expanded[superType] = true

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

# If super type is not an object
# If super type is not an object or array or enum
superTypeBaseName = @dataStructures[superType.literal].typeDefinition.typeSpecification.name

if superTypeBaseName isnt 'object'
if superTypeBaseName not in ['object', 'array', 'value']
dataStructure.typeDefinition.typeSpecification.name = superTypeBaseName
memberTypeSection =
content: []
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/dataStructures.apib
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Inspired by stripe API
## Timestamp (number)
Unix timestamp as an integer

## Legacy Timestamps
+ created_at (Timestamp)
+ updated_at (Timestamp)

## Timestamps (object)
This object contains the following unix timestamps

Expand All @@ -19,6 +23,7 @@ This object contains the following unix timestamps

### Properties
+ modified (Timestamp)
+ Include Legacy Timestamps

## Coupon Base (Timestamps)
+ percent_off: 25 (number)
Expand Down
106 changes: 106 additions & 0 deletions test/fixtures/dataStructures.ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,73 @@
}
]
},
{
"element": "dataStructure",
"name": {
"literal": "Legacy Timestamps",
"variable": false
},
"typeDefinition": {
"typeSpecification": {
"name": null,
"nestedTypes": []
},
"attributes": []
},
"sections": [
{
"class": "memberType",
"content": [
{
"content": {
"name": {
"literal": "created_at"
},
"description": "",
"valueDefinition": {
"values": [],
"typeDefinition": {
"typeSpecification": {
"name": {
"literal": "Timestamp",
"variable": false
},
"nestedTypes": []
},
"attributes": []
}
},
"sections": []
},
"class": "property"
},
{
"content": {
"name": {
"literal": "updated_at"
},
"description": "",
"valueDefinition": {
"values": [],
"typeDefinition": {
"typeSpecification": {
"name": {
"literal": "Timestamp",
"variable": false
},
"nestedTypes": []
},
"attributes": []
}
},
"sections": []
},
"class": "property"
}
]
}
]
},
{
"element": "dataStructure",
"name": {
Expand Down Expand Up @@ -105,6 +172,19 @@
"sections": []
},
"class": "property"
},
{
"content": {
"attributes": [],
"typeSpecification": {
"name": {
"literal": "Legacy Timestamps",
"variable": false
},
"nestedTypes": []
}
},
"class": "mixin"
}
]
}
Expand Down Expand Up @@ -222,6 +302,19 @@
"sections": []
},
"class": "property"
},
{
"content": {
"attributes": [],
"typeSpecification": {
"name": {
"literal": "Legacy Timestamps",
"variable": false
},
"nestedTypes": []
}
},
"class": "mixin"
}
]
}
Expand Down Expand Up @@ -343,6 +436,19 @@
"sections": []
},
"class": "property"
},
{
"content": {
"attributes": [],
"typeSpecification": {
"name": {
"literal": "Legacy Timestamps",
"variable": false
},
"nestedTypes": []
}
},
"class": "mixin"
}
]
}
Expand Down

0 comments on commit a34820b

Please sign in to comment.