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

Fix issue #519 #587

Closed
wants to merge 1 commit 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
12 changes: 11 additions & 1 deletion src/refract/JsonValue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,26 @@ namespace

so::Array result{};
if (e.empty()) {
if (options.test(FIXED_TYPE_FLAG))
LOG(warning) << "empty fixedType ArrayElement in backend";

auto alt = renderSampleOrDefault(e, inherit_flags(options));
if (alt.first)
return std::move(alt.second);
} else
} else {
if (options.test(FIXED_TYPE_FLAG)) {
auto alt = renderSampleOrDefault(e, inherit_flags(options));
if (alt.first)
return std::move(alt.second);
}

for (const auto& entry : e.get()) {
assert(entry);
renderItem(result, *entry, inherit_or_pass_flags(options, *entry));
if (options.test(FIXED_TYPE_FLAG))
break;
}
}

return so::Value{ result };
}
Expand Down
18 changes: 18 additions & 0 deletions test/fixtures/render/issue-519.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# API

## GET /users

+ Response 200 (application/json)
+ Attributes
+ users (array[User], fixed-type)
+ Sample
+ (User)
+ username: doe
+ (User)
+ username: tim

## Data Structures

### User

+ username: kyle
266 changes: 266 additions & 0 deletions test/fixtures/render/issue-519.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
{
"element": "parseResult",
"content": [
{
"element": "category",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "api"
}
]
},
"title": {
"element": "string",
"content": "API"
}
},
"content": [
{
"element": "resource",
"meta": {
"title": {
"element": "string",
"content": ""
}
},
"attributes": {
"href": {
"element": "string",
"content": "/users"
}
},
"content": [
{
"element": "transition",
"meta": {
"title": {
"element": "string",
"content": ""
}
},
"content": [
{
"element": "httpTransaction",
"content": [
{
"element": "httpRequest",
"attributes": {
"method": {
"element": "string",
"content": "GET"
}
},
"content": []
},
{
"element": "httpResponse",
"attributes": {
"statusCode": {
"element": "string",
"content": "200"
},
"headers": {
"element": "httpHeaders",
"content": [
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "Content-Type"
},
"value": {
"element": "string",
"content": "application/json"
}
}
}
]
}
},
"content": [
{
"element": "dataStructure",
"content": {
"element": "object",
"content": [
{
"element": "member",
"attributes": {
"typeAttributes": {
"element": "array",
"content": [
{
"element": "string",
"content": "fixedType"
}
]
}
},
"content": {
"key": {
"element": "string",
"content": "users"
},
"value": {
"element": "array",
"attributes": {
"samples": {
"element": "array",
"content": [
{
"element": "array",
"content": [
{
"element": "User",
"content": [
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "username"
},
"value": {
"element": "string",
"content": "doe"
}
}
}
]
},
{
"element": "User",
"content": [
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "username"
},
"value": {
"element": "string",
"content": "tim"
}
}
}
]
}
]
}
]
}
},
"content": [
{
"element": "User"
}
]
}
}
}
]
}
},
{
"element": "asset",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "messageBody"
}
]
}
},
"attributes": {
"contentType": {
"element": "string",
"content": "application/json"
}
},
"content": "{\n \"users\": [\n {\n \"username\": \"doe\"\n },\n {\n \"username\": \"tim\"\n }\n ]\n}"
},
{
"element": "asset",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "messageBodySchema"
}
]
}
},
"attributes": {
"contentType": {
"element": "string",
"content": "application/schema+json"
}
},
"content": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"type\": \"object\",\n \"properties\": {\n \"users\": {\n \"type\": \"array\",\n \"items\": {\n \"anyOf\": [\n {\n \"type\": \"object\",\n \"properties\": {\n \"username\": {\n \"type\": \"string\"\n }\n }\n }\n ]\n }\n }\n }\n}"
}
]
}
]
}
]
}
]
},
{
"element": "category",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "dataStructures"
}
]
}
},
"content": [
{
"element": "dataStructure",
"content": {
"element": "object",
"meta": {
"id": {
"element": "string",
"content": "User"
}
},
"content": [
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "username"
},
"value": {
"element": "string",
"content": "kyle"
}
}
}
]
}
}
]
}
]
}
]
}
1 change: 1 addition & 0 deletions test/test-RenderTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ TEST_REFRACT("render", "fixed-named-type");
TEST_REFRACT("render", "mixin-override");

TEST_REFRACT("render", "issue-547");
TEST_REFRACT("render", "issue-519");