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

Commit b6f41c4

Browse files
committed
Merge pull request #16 from apiaryio/pksunkara/array
Generate body and schema for arrays
2 parents dc49701 + 119c28e commit b6f41c4

File tree

6 files changed

+895
-27
lines changed

6 files changed

+895
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"boutique": "~0.1.3",
2222
"deep-equal": "1.0.x",
2323
"deepcopy": "0.4.x",
24-
"protagonist-experimental": "~0.18.7",
24+
"protagonist": "0.19.x",
2525
"yargs": "~1.3.3"
2626
},
2727
"devDependencies": {

src/drafter.coffee

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
protagonist = require 'protagonist-experimental'
1+
protagonist = require 'protagonist'
22
boutique = require 'boutique'
33
options = require './options'
44
fs = require 'fs'
@@ -174,8 +174,9 @@ class Drafter
174174
# @param node [Object] A node of API Blueprint
175175
# @param rules [Array] List of rules to apply
176176
# @param elementTye [String] The element type of the node
177-
# @param parent [Object] Parent node's content of which the current node is a part of
178-
expandNode: (node, rules, elementType, parentContent) ->
177+
# @param parentContent [Object] Parent node's content of which the current node is a part of
178+
# @param parentElementType [String] The element type of the parent node
179+
expandNode: (node, rules, elementType, parentContent, parentElementType) ->
179180
elementType ?= node.element
180181

181182
# On root node, Gather data structures first before applying rules to any of the children nodes
@@ -219,7 +220,7 @@ class Drafter
219220
rule[elementType].call rule, newNode if elementType in Object.keys(rule)
220221

221222
# Append resolved data structures
222-
if elementType is 'dataStructure' and not deepEqual node, newNode
223+
if parentElementType not in ['resource', 'blueprint'] and elementType is 'dataStructure' and not deepEqual node, newNode
223224
newNode.element = 'resolvedDataStructure'
224225
parentContent.push newNode
225226

@@ -236,7 +237,7 @@ class Drafter
236237
@expandNode response, rules, 'payload' for response in node.responses
237238

238239
if node.content and Array.isArray node.content
239-
@expandNode element, rules, null, node.content for element in node.content
240+
@expandNode element, rules, null, node.content, elementType for element in node.content
240241

241242
# Reconstruct deprecated resource groups key from elements
242243
#

src/rules/mson-inheritance.coffee

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,41 @@ module.exports =
2828
# Check for inheritance
2929
superType = dataStructure.typeDefinition.typeSpecification.name
3030

31+
# If super type is array and if it has nested type, append them as value members only if there are no value members
32+
if superType is 'array'
33+
nestedTypes = dataStructure.typeDefinition.typeSpecification.nestedTypes
34+
valueMembersExist = false
35+
36+
for section in dataStructure.sections
37+
if section['class'] is 'memberType'
38+
valueMembersExist = true
39+
40+
if not valueMembersExist and nestedTypes.length
41+
memberTypeSection =
42+
content: []
43+
44+
memberTypeSection['class'] = 'memberType'
45+
46+
for nestedType in nestedTypes
47+
valueMember =
48+
content:
49+
description: ''
50+
valueDefinition:
51+
values: []
52+
typeDefinition:
53+
typeSpecification:
54+
name: nestedType,
55+
nestedTypes: []
56+
attributes: []
57+
sections: []
58+
59+
valueMember['class'] = 'value'
60+
memberTypeSection.content.push valueMember
61+
62+
# Push the value members
63+
dataStructure.sections.push memberTypeSection
64+
dataStructure.typeDefinition.typeSpecification.nestedTypes = []
65+
3166
if superType is null or typeof superType isnt 'object' or not superType?.literal
3267
return @expanded[superType] = true
3368

test/fixtures/blueprint.parseresult+sourcemap.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ast": {
3-
"_version": "2.1",
3+
"_version": "3.0",
44
"metadata": [],
55
"name": "",
66
"description": "",
@@ -23,6 +23,10 @@
2323
"description": "",
2424
"method": "GET",
2525
"parameters": [],
26+
"attributes": {
27+
"relation": "",
28+
"uriTemplate": ""
29+
},
2630
"content": [],
2731
"examples": [
2832
{
@@ -73,6 +77,10 @@
7377
"description": "",
7478
"method": "GET",
7579
"parameters": [],
80+
"attributes": {
81+
"relation": "",
82+
"uriTemplate": ""
83+
},
7684
"content": [],
7785
"examples": [
7886
{
@@ -139,6 +147,10 @@
139147
]
140148
],
141149
"parameters": [],
150+
"attributes": {
151+
"relation": [],
152+
"uriTemplate": []
153+
},
142154
"examples": [
143155
{
144156
"name": [],
@@ -208,6 +220,10 @@
208220
]
209221
],
210222
"parameters": [],
223+
"attributes": {
224+
"relation": [],
225+
"uriTemplate": []
226+
},
211227
"examples": [
212228
{
213229
"name": [],

test/fixtures/blueprint.parseresult.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"ast": {
3-
"_version": "2.1",
3+
"_version": "3.0",
44
"metadata": [],
55
"name": "",
66
"description": "",
@@ -23,6 +23,10 @@
2323
"description": "",
2424
"method": "GET",
2525
"parameters": [],
26+
"attributes": {
27+
"relation": "",
28+
"uriTemplate": ""
29+
},
2630
"content": [],
2731
"examples": [
2832
{
@@ -73,6 +77,10 @@
7377
"description": "",
7478
"method": "GET",
7579
"parameters": [],
80+
"attributes": {
81+
"relation": "",
82+
"uriTemplate": ""
83+
},
7684
"content": [],
7785
"examples": [
7886
{

0 commit comments

Comments
 (0)