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

Commit

Permalink
fix(JSON Schema): Fixes #389
Browse files Browse the repository at this point in the history
  • Loading branch information
w-vi committed Oct 4, 2016
1 parent 0dee552 commit 74a7bc1
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/refract/JSONSchemaVisitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ namespace refract

default:
throw LogicError("Invalid member type of object in MSON definition");

}

}
Expand Down Expand Up @@ -460,9 +460,14 @@ namespace refract
}

if (!av.empty()) {
ArrayElement *a = new ArrayElement;
a->set(av);
addMember("items", a);
if (av.size() == 1) {
addMember("items",av[0]);

} else {
ArrayElement *a = new ArrayElement;
a->set(av);
addMember("items", a);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/schema/array-fixed-inline-samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"attributes": {
"contentType": "application/schema+json"
},
"content": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"type\": \"object\",\n \"properties\": {\n \"address\": {\n \"type\": \"array\",\n \"items\": [\n {\n \"type\": \"string\",\n \"enum\": [\n \"city\"\n ]\n }\n ]\n }\n },\n \"required\": [\n \"address\"\n ]\n}"
"content": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"type\": \"object\",\n \"properties\": {\n \"address\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"string\",\n \"enum\": [\n \"city\"\n ]\n }\n }\n },\n \"required\": [\n \"address\"\n ]\n}"
}
]
}
Expand Down
18 changes: 18 additions & 0 deletions test/fixtures/schema/array-fixed-type-object.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Test [/Test]

+ Attributes (object)

+ id: 12 (number)
+ name: Films you must watch (string, required) - List description
+ medias (array[Media], fixed-type) - References to the medias in the list

# GET /
+ Response 200 (application/json)
+ Attributes (Test)


# Data Structures

## Media(object)
- mediaId: 25 (number, required)
- name: Some name (string, required)
258 changes: 258 additions & 0 deletions test/fixtures/schema/array-fixed-type-object.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
{
"element": "parseResult",
"content": [
{
"element": "category",
"meta": {
"classes": [
"api"
],
"title": ""
},
"content": [
{
"element": "category",
"meta": {
"classes": [
"resourceGroup"
],
"title": ""
},
"content": [
{
"element": "resource",
"meta": {
"title": "Test"
},
"attributes": {
"href": "/Test"
},
"content": [
{
"element": "dataStructure",
"content": [
{
"element": "object",
"meta": {
"id": "Test"
},
"content": [
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "id"
},
"value": {
"element": "number",
"content": 12
}
}
},
{
"element": "member",
"meta": {
"description": "List description"
},
"attributes": {
"typeAttributes": [
"required"
]
},
"content": {
"key": {
"element": "string",
"content": "name"
},
"value": {
"element": "string",
"content": "Films you must watch"
}
}
},
{
"element": "member",
"meta": {
"description": "References to the medias in the list"
},
"attributes": {
"typeAttributes": [
"fixedType"
]
},
"content": {
"key": {
"element": "string",
"content": "medias"
},
"value": {
"element": "array",
"content": [
{
"element": "Media"
}
]
}
}
}
]
}
]
}
]
},
{
"element": "resource",
"meta": {
"title": ""
},
"attributes": {
"href": "/"
},
"content": [
{
"element": "transition",
"meta": {
"title": ""
},
"content": [
{
"element": "httpTransaction",
"content": [
{
"element": "httpRequest",
"attributes": {
"method": "GET"
},
"content": []
},
{
"element": "httpResponse",
"attributes": {
"statusCode": "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": "Test"
}
]
},
{
"element": "asset",
"meta": {
"classes": [
"messageBody"
]
},
"attributes": {
"contentType": "application/json"
},
"content": "{\n \"id\": 12,\n \"name\": \"Films you must watch\",\n \"medias\": [\n {\n \"mediaId\": 25,\n \"name\": \"Some name\"\n }\n ]\n}"
},
{
"element": "asset",
"meta": {
"classes": [
"messageBodySchema"
]
},
"attributes": {
"contentType": "application/schema+json"
},
"content": "{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"type\": \"object\",\n \"properties\": {\n \"id\": {\n \"type\": \"number\"\n },\n \"name\": {\n \"type\": \"string\",\n \"description\": \"List description\"\n },\n \"medias\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"mediaId\": {\n \"type\": \"number\"\n },\n \"name\": {\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"mediaId\",\n \"name\"\n ]\n },\n \"description\": \"References to the medias in the list\"\n }\n },\n \"required\": [\n \"name\"\n ]\n}"
}
]
}
]
}
]
}
]
}
]
},
{
"element": "category",
"meta": {
"classes": [
"dataStructures"
]
},
"content": [
{
"element": "dataStructure",
"content": [
{
"element": "object",
"meta": {
"id": "Media"
},
"content": [
{
"element": "member",
"attributes": {
"typeAttributes": [
"required"
]
},
"content": {
"key": {
"element": "string",
"content": "mediaId"
},
"value": {
"element": "number",
"content": 25
}
}
},
{
"element": "member",
"attributes": {
"typeAttributes": [
"required"
]
},
"content": {
"key": {
"element": "string",
"content": "name"
},
"value": {
"element": "string",
"content": "Some name"
}
}
}
]
}
]
}
]
}
]
}
]
}
1 change: 1 addition & 0 deletions test/test-SchemaTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ TEST_REFRACT("schema", "array-fixed-inline-samples");
TEST_REFRACT("schema", "array-fixed-samples");
TEST_REFRACT("schema", "array-fixed-types-only");
TEST_REFRACT("schema", "array-fixed-type");
TEST_REFRACT("schema", "array-fixed-type-object");

//FIXME: Discuss it with hj, as current drafter seems legit
//boutique version of schema
Expand Down

0 comments on commit 74a7bc1

Please sign in to comment.