Skip to content

Commit

Permalink
Merge pull request #23 from apiaryio/honzajavorek/dealing-with-defaul…
Browse files Browse the repository at this point in the history
…t-enum-values

Dealing with defaults of enum values
  • Loading branch information
freaz committed May 13, 2016
2 parents 344b40b + 02631a3 commit f79dd50
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/from-api-elements/compile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ compileParameters = (hrefVariables) ->
types = (content(member.attributes?.typeAttributes) or [])

if value?.element is 'enum'
example = content(content(value)[0])
if value.attributes?.default?.length
example = content(value.attributes.default[0])
else
example = content(content(value)[0])
else
example = content(value)

Expand Down
35 changes: 35 additions & 0 deletions test/unit/from-api-elements/compile-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,41 @@ describe('compileFromApiElements()', ->
)
)

describe('API description with different sample and default value of URI parameter', ->
err = undefined
transaction = undefined

beforeEach((done) ->
compile('''
FORMAT: 1A
# Beehive API
## Honey [/honey{?beekeeper}]
### GET
+ Parameters
+ beekeeper: `Adam` (string, optional) - Beekeeper.
Description...
+ Default: `Honza`
+ Members
+ `Adam` - Adam K.
+ `Honza` - Honza J.
+ Response 200
''', (args...) ->
[err, compilationResult] = args
transaction = compilationResult.transactions[0]
done()
)
)

it('expands the request URI using correct value', ->
assert.equal(transaction.request.uri, '/honey?beekeeper=Honza')
)
)

describe('Valid API description', ->
filename = path.join(__dirname, '../../fixtures/blueprint.apib')
apiDescriptionDocument = fs.readFileSync(filename).toString()
Expand Down

0 comments on commit f79dd50

Please sign in to comment.