From a62b737be4e681f66c73526b3c7408e28a5388b0 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Wed, 11 Feb 2015 02:05:13 +0530 Subject: [PATCH] Expanding attributes finished --- src/drafter.coffee | 4 +- src/rules/mson-inheritance.coffee | 12 + src/rules/mson-member-type-name.coffee | 12 + src/rules/mson-mixin.coffee | 12 + test/fixtures/dataStructures.ast.json | 484 ++++++++++++++++++++++++- 5 files changed, 503 insertions(+), 21 deletions(-) diff --git a/src/drafter.coffee b/src/drafter.coffee index f356df7..41c9cf4 100644 --- a/src/drafter.coffee +++ b/src/drafter.coffee @@ -69,8 +69,8 @@ class Drafter @dataStructures[subElement.name.literal] = subElement when 'resource' - for resourceElement in subElement.content - @dataStructures[resourceElement.name.literal] = resourceElement if resourceElement.element is 'dataStructure' + for resourceSubElement in subElement.content + @dataStructures[resourceSubElement.name.literal] = resourceSubElement if resourceSubElement.element is 'dataStructure' # Expand the gathered data structures for rule in rules diff --git a/src/rules/mson-inheritance.coffee b/src/rules/mson-inheritance.coffee index 8a524a2..799c326 100644 --- a/src/rules/mson-inheritance.coffee +++ b/src/rules/mson-inheritance.coffee @@ -6,6 +6,18 @@ module.exports = expanded: {} dataStructures: {} + # Expand dataStructure element + dataStructure: (element) -> + superType = element.typeDefinition.name + typeName = element.name + + if not typeName + typeName = + literal: '' + + @expandInheritance typeName.literal, element + delete @expanded[''] + # Given a data structure, expand its inheritance recursively # # @param name [String] Name of the data structure diff --git a/src/rules/mson-member-type-name.coffee b/src/rules/mson-member-type-name.coffee index 268689d..b928a3c 100644 --- a/src/rules/mson-member-type-name.coffee +++ b/src/rules/mson-member-type-name.coffee @@ -6,6 +6,18 @@ module.exports = expanded: {} dataStructures: {} + # Expand dataStructure element + dataStructure: (element) -> + superType = element.typeDefinition.name + typeName = element.name + + if not typeName + typeName = + literal: '' + + @expandMember typeName.literal, element + delete @expanded[''] + # Given a list of elements, recursively expand member type name contained # in a group of elements inside the initial group of elements # diff --git a/src/rules/mson-mixin.coffee b/src/rules/mson-mixin.coffee index 7e08b63..942ec65 100644 --- a/src/rules/mson-mixin.coffee +++ b/src/rules/mson-mixin.coffee @@ -6,6 +6,18 @@ module.exports = expanded: {} dataStructures: {} + # Expand dataStructure element + dataStructure: (element) -> + superType = element.typeDefinition.name + typeName = element.name + + if not typeName + typeName = + literal: '' + + @expandMixin typeName.literal, element + delete @expanded[''] + # Given a list of elements, recursively expand mixins contained # in a group of elements inside the initial group of elements # diff --git a/test/fixtures/dataStructures.ast.json b/test/fixtures/dataStructures.ast.json index fdc5b80..e305597 100644 --- a/test/fixtures/dataStructures.ast.json +++ b/test/fixtures/dataStructures.ast.json @@ -349,15 +349,173 @@ "name": null, "typeDefinition": { "typeSpecification": { - "name": { - "literal": "Coupon", - "variable": false - }, + "name": "object", "nestedTypes": [] }, "attributes": [] }, - "sections": [] + "sections": [ + { + "content": [ + { + "content": { + "name": { + "literal": "id" + }, + "description": "", + "valueDefinition": { + "values": [ + { + "literal": "250FF", + "variable": false + } + ], + "typeDefinition": { + "typeSpecification": { + "name": "string", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "percent_off" + }, + "description": "", + "valueDefinition": { + "values": [ + { + "literal": "25", + "variable": false + } + ], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [ + { + "class": "blockDescription", + "content": "A positive integer between 1 and 100 that represents the discount the coupon will apply.\n" + } + ] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "redeem_by" + }, + "description": "Date after which the coupon can no longer be redeemed", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "created" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "modified" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "created_at" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "updated_at" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + } + ], + "class": "memberType" + } + ] } ] } @@ -592,10 +750,7 @@ "name": null, "typeDefinition": { "typeSpecification": { - "name": { - "literal": "Coupons", - "variable": false - }, + "name": "array", "nestedTypes": [] }, "attributes": [] @@ -619,15 +774,148 @@ "name": null, "typeDefinition": { "typeSpecification": { - "name": { - "literal": "Coupon Base", - "variable": false - }, + "name": "object", "nestedTypes": [] }, "attributes": [] }, - "sections": [] + "sections": [ + { + "content": [ + { + "content": { + "name": { + "literal": "percent_off" + }, + "description": "", + "valueDefinition": { + "values": [ + { + "literal": "25", + "variable": false + } + ], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [ + { + "class": "blockDescription", + "content": "A positive integer between 1 and 100 that represents the discount the coupon will apply.\n" + } + ] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "redeem_by" + }, + "description": "Date after which the coupon can no longer be redeemed", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "created" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "modified" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "created_at" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "updated_at" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + } + ], + "class": "memberType" + } + ] } ], "examples": [ @@ -667,15 +955,173 @@ "name": null, "typeDefinition": { "typeSpecification": { - "name": { - "literal": "Coupon", - "variable": false - }, + "name": "object", "nestedTypes": [] }, "attributes": [] }, - "sections": [] + "sections": [ + { + "content": [ + { + "content": { + "name": { + "literal": "id" + }, + "description": "", + "valueDefinition": { + "values": [ + { + "literal": "250FF", + "variable": false + } + ], + "typeDefinition": { + "typeSpecification": { + "name": "string", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "percent_off" + }, + "description": "", + "valueDefinition": { + "values": [ + { + "literal": "25", + "variable": false + } + ], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [ + { + "class": "blockDescription", + "content": "A positive integer between 1 and 100 that represents the discount the coupon will apply.\n" + } + ] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "redeem_by" + }, + "description": "Date after which the coupon can no longer be redeemed", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "created" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "modified" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "created_at" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + }, + { + "content": { + "name": { + "literal": "updated_at" + }, + "description": "", + "valueDefinition": { + "values": [], + "typeDefinition": { + "typeSpecification": { + "name": "number", + "nestedTypes": [] + }, + "attributes": [] + } + }, + "sections": [] + }, + "class": "property" + } + ], + "class": "memberType" + } + ] } ] }