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

Commit

Permalink
Merge pull request #293 from apiaryio/pksunkara/286
Browse files Browse the repository at this point in the history
Parameters refract should behave same as attributes refract
  • Loading branch information
klokane committed Apr 13, 2016
2 parents f07914d + 7a04646 commit 4f25f00
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 20 deletions.
9 changes: 7 additions & 2 deletions src/RefractAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ namespace drafter {
{
refract::ArrayElement* element = CollectionToRefract<refract::ArrayElement>(MAKE_NODE_INFO(parameter, values), LiteralToRefract<T>, SerializeKey::Enum, refract::IElement::rDefault);

// FIXME: nearly duplicit code in ExtractParameter()
// Add sample value
if (!parameter.node->exampleValue.empty()) {
refract::ArrayElement* samples = new refract::ArrayElement;
Expand All @@ -142,7 +141,13 @@ namespace drafter {
refract::IElement* element = NULL;

if (parameter.node->values.empty()) {
element = LiteralToRefract<T>(MAKE_NODE_INFO(parameter, exampleValue));
if (parameter.node->exampleValue.empty()) {
typedef typename refract::ElementTypeSelector<T>::ElementType ElementType;
element = new ElementType;
}
else {
element = LiteralToRefract<T>(MAKE_NODE_INFO(parameter, exampleValue));
}

if (!parameter.node->defaultValue.empty()) {
element->attributes[SerializeKey::Default] = PrimitiveToRefract(MAKE_NODE_INFO(parameter, defaultValue));
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/api/action-parameters.apib
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

# Group Users

## User [/users/{id}]
## User [/users/{id}{?country,active,votes}]

### Retrieve User [GET]

+ Parameters
+ id: pavan (string, required) - Username
+ country
+ active (boolean)
+ votes (number)

+ Response 200 (application/json)

Expand Down
38 changes: 37 additions & 1 deletion test/fixtures/api/action-parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"title": "User"
},
"attributes": {
"href": "/users/{id}"
"href": "/users/{id}{?country,active,votes}"
},
"content": [
{
Expand Down Expand Up @@ -57,6 +57,42 @@
"content": "pavan"
}
}
},
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "country"
},
"value": {
"element": "string"
}
}
},
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "active"
},
"value": {
"element": "boolean"
}
}
},
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "votes"
},
"value": {
"element": "number"
}
}
}
]
}
Expand Down
99 changes: 87 additions & 12 deletions test/fixtures/api/action-parameters.sourcemap.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"content": [
[
27,
23
46
]
]
}
Expand All @@ -82,13 +82,13 @@
"content": [
[
27,
23
46
]
]
}
]
},
"content": "/users/{id}"
"content": "/users/{id}{?country,active,votes}"
}
},
"content": [
Expand All @@ -103,7 +103,7 @@
"element": "sourceMap",
"content": [
[
50,
73,
25
]
]
Expand All @@ -128,7 +128,7 @@
"element": "sourceMap",
"content": [
[
94,
117,
40
]
]
Expand All @@ -152,7 +152,7 @@
"element": "sourceMap",
"content": [
[
94,
117,
40
]
]
Expand All @@ -169,7 +169,7 @@
"element": "sourceMap",
"content": [
[
94,
117,
40
]
]
Expand All @@ -179,6 +179,81 @@
"content": "pavan"
}
}
},
{
"element": "member",
"content": {
"key": {
"element": "string",
"attributes": {
"sourceMap": [
{
"element": "sourceMap",
"content": [
[
163,
8
]
]
}
]
},
"content": "country"
},
"value": {
"element": "string"
}
}
},
{
"element": "member",
"content": {
"key": {
"element": "string",
"attributes": {
"sourceMap": [
{
"element": "sourceMap",
"content": [
[
177,
17
]
]
}
]
},
"content": "active"
},
"value": {
"element": "boolean"
}
}
},
{
"element": "member",
"content": {
"key": {
"element": "string",
"attributes": {
"sourceMap": [
{
"element": "sourceMap",
"content": [
[
200,
15
]
]
}
]
},
"content": "votes"
},
"value": {
"element": "number"
}
}
}
]
}
Expand All @@ -198,7 +273,7 @@
"element": "sourceMap",
"content": [
[
50,
73,
25
]
]
Expand All @@ -221,7 +296,7 @@
"element": "sourceMap",
"content": [
[
137,
218,
33
]
]
Expand All @@ -235,7 +310,7 @@
"element": "sourceMap",
"content": [
[
137,
218,
33
]
]
Expand All @@ -252,7 +327,7 @@
"element": "sourceMap",
"content": [
[
137,
218,
33
]
]
Expand Down Expand Up @@ -287,7 +362,7 @@
"element": "sourceMap",
"content": [
[
174,
255,
7
]
]
Expand Down
3 changes: 1 addition & 2 deletions test/fixtures/api/request-parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
"element": "number",
"attributes": {
"default": "20"
},
"content": 0
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/fixtures/api/request-parameters.sourcemap.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@
},
"content": "20"
}
},
"content": 0
}
}
}
}
Expand Down

0 comments on commit 4f25f00

Please sign in to comment.