Skip to content

Commit

Permalink
feat: Introducing x-example attribute for Swagger non-body parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Jul 27, 2016
1 parent 2904a20 commit 2955a52
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"deckardcain": "^0.3.2",
"fury": "^2.1.0",
"fury-adapter-apib-parser": "^0.3.0",
"fury-adapter-swagger": "^0.8.1",
"fury-adapter-swagger": "^0.9.1",
"sift": "^3.2.1",
"traverse": "^0.6.6",
"uri-template": "^1.0.0"
Expand Down
1 change: 1 addition & 0 deletions src/compile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ compileParameters = (hrefVariables) ->
default: defaultValue
example: exampleValue
values: if value?.element is 'enum' then ({value: content(v)} for v in content(value)) else []

parameters


Expand Down
22 changes: 22 additions & 0 deletions test/fixtures/api-blueprint/example-parameter.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FORMAT: 1A

# Beehive API

## Honey [/honey{?beekeeper}]

+ Parameters
+ beekeeper: Honza (enum[string])

Description...

+ Members
+ Adam
+ Honza
+ Dredd
+ Default: `Dredd`

### Remove [DELETE]

+ Request (application/json)

+ Response 200
4 changes: 4 additions & 0 deletions test/fixtures/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ fixtures =
apiBlueprint: fromFile('./api-blueprint/default-required.apib')
swagger: fromFile('./swagger/default-required.yml')
)
exampleParameter: fixture(
apiBlueprint: fromFile('./api-blueprint/example-parameter.apib')
swagger: fromFile('./swagger/example-parameter.yml')
)

# Specific to API Blueprint
unrecognizable: fixture(
Expand Down
44 changes: 44 additions & 0 deletions test/fixtures/swagger/example-parameter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
swagger: "2.0"
info:
version: "1.0"
title: Petstore
description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification
host: petstore.swagger.io
basePath: /
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/honey:
get:
parameters:
- name: beekeeper
in: query
type: string
enum:
- Adam
- Honza
- Dredd
x-example: Honza
default: Dredd
responses:
200:
description: pet response
schema:
$ref: '#/definitions/Pet'
definitions:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
18 changes: 18 additions & 0 deletions test/integration/compile-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,24 @@ describe('compile() · all API description formats', ->
)
)

describe('with parameter having an example value', ->
transaction = undefined

fixtures.exampleParameter.forEachDescribe(({source}) ->
beforeEach((done) ->
compileFixture(source, (args...) ->
[err, compilationResult] = args
transaction = compilationResult.transactions[0]
done(err)
)
)

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

describe('with response schema', ->
transaction = undefined

Expand Down

0 comments on commit 2955a52

Please sign in to comment.