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

Commit

Permalink
Fix #318
Browse files Browse the repository at this point in the history
warn on property of type `object` with string value definition e.g:
- key: value (object)
  • Loading branch information
Jiri Kratochvil committed May 20, 2016
1 parent aca5f3a commit 7c1881e
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext/snowcrash
2 changes: 1 addition & 1 deletion src/RefractDataStructure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ namespace drafter {

std::for_each(typeSections.begin(), typeSections.end(), ExtractTypeSection<T>(data, context, value));

if (!value.node->valueDefinition.values.empty() && (valuesCount != data.values.size())) {
if (valuesCount != data.values.size()) {
// there are some values coming from TypeSections -> move first value into examples
MoveFirstValueToSample<T>()(value, data);
}
Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/render/issue-318.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# GET /
- Response 200 (application/json)
- Attribute (A)

# Data Structures

## O (object)

## A
- explicit: value (object)

- implicit: value
- key: value

- named: value (O)

248 changes: 248 additions & 0 deletions test/fixtures/render/issue-318.ast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
{
"_version": "2.2",
"ast": {
"_version": "4.0",
"metadata": [],
"name": "",
"description": "",
"element": "category",
"resourceGroups": [
{
"name": "",
"description": "",
"resources": [
{
"element": "resource",
"name": "",
"description": "",
"uriTemplate": "/",
"model": {},
"parameters": [],
"actions": [
{
"name": "",
"description": "",
"method": "GET",
"parameters": [],
"attributes": {
"relation": "",
"uriTemplate": ""
},
"content": [],
"examples": [
{
"name": "",
"description": "",
"requests": [],
"responses": [
{
"name": "200",
"description": "",
"headers": [
{
"name": "Content-Type",
"value": "application/json"
}
],
"body": "{\n \"explicit\": {},\n \"implicit\": {\n \"key\": \"value\"\n },\n \"named\": {}\n}",
"schema": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"type\": \"object\",\n \"properties\": {\n \"explicit\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"implicit\": {\n \"type\": \"object\",\n \"properties\": {\n \"key\": {\n \"type\": \"string\"\n }\n }\n },\n \"named\": {\n \"type\": \"object\",\n \"properties\": {}\n }\n }\n}",
"content": [
{
"element": "dataStructure",
"content": [
{
"element": "A"
}
]
}
]
}
]
}
]
}
],
"content": []
}
]
}
],
"content": [
{
"element": "category",
"content": [
{
"element": "resource",
"name": "",
"description": "",
"uriTemplate": "/",
"model": {},
"parameters": [],
"actions": [
{
"name": "",
"description": "",
"method": "GET",
"parameters": [],
"attributes": {
"relation": "",
"uriTemplate": ""
},
"content": [],
"examples": [
{
"name": "",
"description": "",
"requests": [],
"responses": [
{
"name": "200",
"description": "",
"headers": [
{
"name": "Content-Type",
"value": "application/json"
}
],
"body": "{\n \"explicit\": {},\n \"implicit\": {\n \"key\": \"value\"\n },\n \"named\": {}\n}",
"schema": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"type\": \"object\",\n \"properties\": {\n \"explicit\": {\n \"type\": \"object\",\n \"properties\": {}\n },\n \"implicit\": {\n \"type\": \"object\",\n \"properties\": {\n \"key\": {\n \"type\": \"string\"\n }\n }\n },\n \"named\": {\n \"type\": \"object\",\n \"properties\": {}\n }\n }\n}",
"content": [
{
"element": "dataStructure",
"content": [
{
"element": "A"
}
]
}
]
}
]
}
]
}
],
"content": []
}
]
},
{
"element": "category",
"content": [
{
"element": "dataStructure",
"content": [
{
"element": "object",
"meta": {
"id": "O"
}
}
]
},
{
"element": "dataStructure",
"content": [
{
"element": "object",
"meta": {
"id": "A"
},
"content": [
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "explicit"
},
"value": {
"element": "object"
}
}
},
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "implicit"
},
"value": {
"element": "object",
"content": [
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "key"
},
"value": {
"element": "string",
"content": "value"
}
}
}
]
}
}
},
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "named"
},
"value": {
"element": "O"
}
}
}
]
}
]
}
]
}
]
},
"error": {
"code": 0,
"message": "",
"location": []
},
"warnings": [
{
"code": 8,
"message": "'object' with value definition. You should use type definition without value eg. '- key (object)'",
"location": [
{
"index": 102,
"length": 28
}
]
},
{
"code": 8,
"message": "'object' with value definition. You should use type definition without value eg. '- key (object)'",
"location": [
{
"index": 130,
"length": 36
}
]
},
{
"code": 8,
"message": "'object' with value definition. You should use type definition without value eg. '- key (object)'",
"location": [
{
"index": 166,
"length": 20
}
]
}
]
}
1 change: 1 addition & 0 deletions test/test-RenderTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ TEST_AST("render", "action-request-attributes");
TEST_AST("render", "object-array-string");

TEST_AST("render", "issue-246");
TEST_AST("render", "issue-318");

0 comments on commit 7c1881e

Please sign in to comment.