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

Commit 390d099

Browse files
committed
Merge pull request #11 from apiaryio/kylef/action-uri-template
Support URI Templates attached to an action
2 parents 0c6af57 + 09abffd commit 390d099

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

APIBlueprintImporter.coffee

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,21 @@ APIBlueprintImporter = ->
6464

6565
requestGroup = context.createRequestGroup(name)
6666
for action in actions
67-
request = @importResourceAction(context, url, action)
67+
request = @importResourceAction(context, baseHost, url, action)
6868
requestGroup.appendChild(request)
6969

7070
return requestGroup
7171

7272
# Imports an action from a blueprint.
7373
#
7474
# @param [Context] context Paw context
75+
# @param [String] baseHost The blueprint's base host
7576
# @param [String] url Actions URL
7677
# @param [Object] action the blueprint action
7778
#
7879
# @return [Request,RequestGroup] Returns either a request or request group
7980
#
80-
@importResourceAction = (context, url, action) ->
81+
@importResourceAction = (context, baseHost, url, action) ->
8182
name = action["name"]
8283
if name.length == 0
8384
name = action["description"]
@@ -89,6 +90,12 @@ APIBlueprintImporter = ->
8990
method = action["method"]
9091
# TODO uri templates
9192

93+
attributes = action['attributes']
94+
if attributes
95+
uriTemplate = attributes['uriTemplate']
96+
if uriTemplate && uriTemplate.length > 0
97+
url = baseHost + uriTemplate
98+
9299
console.log("Importing resource action '" + name + "' " + examples.length + " examples")
93100

94101
if examples.length > 0

test.coffee

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe 'API Blueprint Importer Paw Extension', ->
110110
],
111111
}
112112
importer = new APIBlueprintImporter()
113-
@requestGroup = importer.importResourceAction(@context, "", action)
113+
@requestGroup = importer.importResourceAction(@context, "", "", action)
114114

115115
it 'should create a request group with a name', ->
116116
assert.equal(@requestGroup.name, 'Retrieve a Message')
@@ -127,7 +127,7 @@ describe 'API Blueprint Importer Paw Extension', ->
127127
"examples": [],
128128
}
129129
importer = new APIBlueprintImporter()
130-
@request = importer.importResourceAction(@context, "http://api.acme.com/message", action)
130+
@request = importer.importResourceAction(@context, "", "http://api.acme.com/message", action)
131131

132132
it 'should return a request with a name', ->
133133
assert.equal(@request.name, "Retrieve a Message")
@@ -138,6 +138,29 @@ describe 'API Blueprint Importer Paw Extension', ->
138138
it 'should return a request with a URL', ->
139139
assert.equal(@request.url, "http://api.acme.com/message")
140140

141+
describe 'with its own URI', ->
142+
before ->
143+
action = {
144+
"name": "Retrieve a Message",
145+
"method": "GET",
146+
"parameters": [],
147+
"examples": [],
148+
"attributes": {
149+
"uriTemplate": "/other"
150+
}
151+
}
152+
importer = new APIBlueprintImporter()
153+
@request = importer.importResourceAction(@context, "http://api.acme.com", "http://api.acme.com/message", action)
154+
155+
it 'should return a request with a name', ->
156+
assert.equal(@request.name, "Retrieve a Message")
157+
158+
it 'should return a request with a method', ->
159+
assert.equal(@request.method, "GET")
160+
161+
it 'should return a request with a URL', ->
162+
assert.equal(@request.url, "http://api.acme.com/other")
163+
141164
describe 'when importing an example', ->
142165
before ->
143166
@context = new Context()

0 commit comments

Comments
 (0)