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

Example names are being ignored and replaced by 'Example X' #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
src/
.travis.yml
HISTORY-Dredd.md
.git*
Expand Down
42 changes: 31 additions & 11 deletions src/blueprint-ast-to-runtime.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@ exampleToHttpPayloadPair = require './example-to-http-payload-pair'
convertAstMetadata = require './convert-ast-metadata'
validateParameters = require './validate-parameters'

isEmptyString = (string) ->
string == '' or string == null

getExampleName = (example, exampleIndex) ->
name = 'Example ' + (exampleIndex + 1)
if isEmptyString(example.name)
if example.requests.length > 0
reqName = example.requests[0].name
if !isEmptyString(reqName)
name = reqName
else
# Names can have empty example
name = ''

name

getExamplePath = (example, exampleIndex) ->
name = 'Example ' + (exampleIndex + 1)
if isEmptyString(example.name)
if example.requests.length > 0
reqName = example.requests[0].name
if !isEmptyString(reqName)
name = reqName
else
# Path can't have empty example
name = 'Example 1'

name

blueprintAstToRuntime = (blueprintAst, filename) ->
runtime =
transactions: []
Expand Down Expand Up @@ -105,19 +134,10 @@ blueprintAstToRuntime = (blueprintAst, filename) ->
if uriResult['uri'] != null
for example, exampleIndex in action['examples']

# Names can have empty example
if action['examples'].length > 1 and example['name'] == ""
origin['exampleName'] = "Example " + (exampleIndex + 1)
else
origin['exampleName'] = example['name']
origin['exampleName'] = getExampleName example, exampleIndex

# Paths can't have empty example
if example['name'] == ""
pathOrigin['exampleName'] = "Example " + (exampleIndex + 1)
else
pathOrigin['exampleName'] = example['name']


pathOrigin['exampleName'] = getExamplePath example, exampleIndex

result = exampleToHttpPayloadPair example

Expand Down