diff --git a/.gitmodules b/.gitmodules index f2f1bd59e..fa12fec79 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "ext/snowcrash"] path = ext/snowcrash - url = https://github.com/apiaryio/snowcrash.git + url = https://github.com/goganchic/snowcrash.git [submodule "test/vendor/Catch"] path = test/vendor/Catch url = https://github.com/philsquared/Catch.git diff --git a/drafter.gyp b/drafter.gyp index e62bb9aa0..87aea07c4 100644 --- a/drafter.gyp +++ b/drafter.gyp @@ -132,6 +132,7 @@ "test/test-ElementFactoryTest.cc", "test/test-OneOfTest.cc", "test/test-SyntaxIssuesTest.cc", + "test/test-CommonDataTest.cc", ], 'dependencies': [ "libdrafter", diff --git a/drafter.xcodeproj/project.pbxproj b/drafter.xcodeproj/project.pbxproj index 13120d1c7..f0748f36c 100644 --- a/drafter.xcodeproj/project.pbxproj +++ b/drafter.xcodeproj/project.pbxproj @@ -94,6 +94,7 @@ 40EF03DA1B72134000865990 /* RefractAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 40EF03D81B72134000865990 /* RefractAPI.h */; }; 40EF03DD1B72135E00865990 /* test-RefractAPITest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 40EF03DB1B72135E00865990 /* test-RefractAPITest.cc */; }; 40EF03DE1B72135E00865990 /* test-RefractDataStructureTest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 40EF03DC1B72135E00865990 /* test-RefractDataStructureTest.cc */; }; + 9D3FD1EF1EB5FD5500DD4E11 /* test-CommonDataTest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 9D3FD1EE1EB5FD5500DD4E11 /* test-CommonDataTest.cc */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -215,6 +216,7 @@ 40EF03D81B72134000865990 /* RefractAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RefractAPI.h; path = src/RefractAPI.h; sourceTree = SOURCE_ROOT; }; 40EF03DB1B72135E00865990 /* test-RefractAPITest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "test-RefractAPITest.cc"; path = "test/test-RefractAPITest.cc"; sourceTree = ""; }; 40EF03DC1B72135E00865990 /* test-RefractDataStructureTest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "test-RefractDataStructureTest.cc"; path = "test/test-RefractDataStructureTest.cc"; sourceTree = ""; }; + 9D3FD1EE1EB5FD5500DD4E11 /* test-CommonDataTest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "test-CommonDataTest.cc"; path = "test/test-CommonDataTest.cc"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -276,6 +278,7 @@ 19A129CA1B70ADC300366AA7 /* test-drafter.cc */, 4093675C1CBB90DE0065A78A /* test-ApplyVisitorTest.cc */, 400F54031C598A35004EA235 /* test-CircularReferenceTest.cc */, + 9D3FD1EE1EB5FD5500DD4E11 /* test-CommonDataTest.cc */, 4093675D1CBB90DE0065A78A /* test-ElementFactoryTest.cc */, 40AEF8201CB80C4F000A0DEE /* test-ExtendElementTest.cc */, 40E6DFA01CF494FE009B3FF3 /* test-OneOfTest.cc */, diff --git a/ext/snowcrash b/ext/snowcrash index d3c45a9ef..e97d3b4f7 160000 --- a/ext/snowcrash +++ b/ext/snowcrash @@ -1 +1 @@ -Subproject commit d3c45a9ef9777967de1ea7e7ba6fc578897f8961 +Subproject commit e97d3b4f7489f56deb935e411060bd168e8e7a2a diff --git a/src/RefractAPI.cc b/src/RefractAPI.cc index 85933aa59..21af0f623 100644 --- a/src/RefractAPI.cc +++ b/src/RefractAPI.cc @@ -518,6 +518,25 @@ namespace drafter { return category; } + refract::IElement* CommonDataToRefract(const NodeInfo& element, ConversionContext& context) + { + refract::ArrayElement* commonData = new refract::ArrayElement; + RefractElements content; + + auto respIt = element.node->content.responses.begin(); + auto smIt = element.sourceMap->content.responses.collection.begin(); + + for (; respIt != element.node->content.responses.end(); ++respIt, ++smIt) { + NodeInfo info = NodeInfo(&*respIt, &*smIt); + content.push_back(PayloadToRefract(info, NodeInfo(), context)); + } + + commonData->element(SerializeKey::CommonData); + commonData->set(content); + + return commonData; + } + refract::IElement* ElementToRefract(const NodeInfo& element, ConversionContext& context) { switch (element.node->element) { @@ -529,6 +548,8 @@ namespace drafter { return CopyToRefract(MAKE_NODE_INFO(element, content.copy)); case snowcrash::Element::CategoryElement: return CategoryToRefract(element, context); + case snowcrash::Element::CommonDataElement: + return CommonDataToRefract(element, context); default: // we are not able to get sourcemap info there // It is strongly dependent on type of element. diff --git a/src/Serialize.cc b/src/Serialize.cc index d9cb82ac0..cc22df1b6 100644 --- a/src/Serialize.cc +++ b/src/Serialize.cc @@ -35,6 +35,7 @@ const std::string SerializeKey::Name = "name"; const std::string SerializeKey::Description = "description"; const std::string SerializeKey::DataStructure = "dataStructure"; const std::string SerializeKey::DataStructures = "dataStructures"; +const std::string SerializeKey::CommonData = "commonData"; const std::string SerializeKey::ResourceGroup = "resourceGroup"; const std::string SerializeKey::ResourceGroups = "resourceGroups"; const std::string SerializeKey::Resource = "resource"; diff --git a/src/Serialize.h b/src/Serialize.h index 96a80cf09..f7f8fcb4c 100644 --- a/src/Serialize.h +++ b/src/Serialize.h @@ -63,6 +63,7 @@ namespace drafter { static const std::string Description; static const std::string DataStructure; static const std::string DataStructures; + static const std::string CommonData; static const std::string ResourceGroup; static const std::string ResourceGroups; static const std::string Resource; diff --git a/src/main.cc b/src/main.cc index 81cde0408..03554ca36 100644 --- a/src/main.cc +++ b/src/main.cc @@ -6,10 +6,6 @@ // Copyright (c) 2015 Apiary Inc. All rights reserved. // // -#include "drafter.h" - -#include "snowcrash.h" -#include "SectionParserData.h" // snowcrash::BlueprintParserOptions #include "sos.h" #include "sosJSON.h" @@ -21,10 +17,6 @@ #include "config.h" #include "stream.h" -#include "ConversionContext.h" - -namespace sc = snowcrash; - /** * \brief return instance sos::Serializer based on \param `format` * diff --git a/test/fixtures/common-data/multiple-groups.apib b/test/fixtures/common-data/multiple-groups.apib new file mode 100644 index 000000000..8dcea0698 --- /dev/null +++ b/test/fixtures/common-data/multiple-groups.apib @@ -0,0 +1,33 @@ +# API name + +# Group Users + +This group should have only common response 500 + +## Common Data + ++ Response 500 + +## User [/users] + +### List all users [GET] + ++ Response 200 (application/json) + + Attributes + + users (array) + +# Group Comments + +This group should have only common response 404 + +## Common Data + ++ Response 404 (application/json) + +## Comment [/comments] + +### List all comments [GET] + ++ Response 200 (application/json) + + Attributes + + comments (array) diff --git a/test/fixtures/common-data/multiple-groups.json b/test/fixtures/common-data/multiple-groups.json new file mode 100644 index 000000000..082ef03af --- /dev/null +++ b/test/fixtures/common-data/multiple-groups.json @@ -0,0 +1,350 @@ +{ + "element": "parseResult", + "content": [ + { + "element": "category", + "meta": { + "classes": [ + "api" + ], + "title": "API name" + }, + "content": [ + { + "element": "category", + "meta": { + "classes": [ + "resourceGroup" + ], + "title": "Users" + }, + "content": [ + { + "element": "copy", + "content": "This group should have only common response 500" + }, + { + "element": "commonData", + "content": [ + { + "element": "httpResponse", + "attributes": { + "statusCode": "500" + }, + "content": [] + } + ] + }, + { + "element": "resource", + "meta": { + "title": "User" + }, + "attributes": { + "href": "/users" + }, + "content": [ + { + "element": "transition", + "meta": { + "title": "List all users" + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": "GET" + }, + "content": [] + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": "500" + }, + "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": "object", + "content": [ + { + "element": "member", + "content": { + "key": { + "element": "string", + "content": "users" + }, + "value": { + "element": "array" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"users\": []\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 \"users\": {}\n }\n}" + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "element": "category", + "meta": { + "classes": [ + "resourceGroup" + ], + "title": "Comments" + }, + "content": [ + { + "element": "copy", + "content": "This group should have only common response 404" + }, + { + "element": "commonData", + "content": [ + { + "element": "httpResponse", + "attributes": { + "statusCode": "404", + "headers": { + "element": "httpHeaders", + "content": [ + { + "element": "member", + "content": { + "key": { + "element": "string", + "content": "Content-Type" + }, + "value": { + "element": "string", + "content": "application/json" + } + } + } + ] + } + }, + "content": [] + } + ] + }, + { + "element": "resource", + "meta": { + "title": "Comment" + }, + "attributes": { + "href": "/comments" + }, + "content": [ + { + "element": "transition", + "meta": { + "title": "List all comments" + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": "GET" + }, + "content": [] + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": "404", + "headers": { + "element": "httpHeaders", + "content": [ + { + "element": "member", + "content": { + "key": { + "element": "string", + "content": "Content-Type" + }, + "value": { + "element": "string", + "content": "application/json" + } + } + } + ] + } + }, + "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": "object", + "content": [ + { + "element": "member", + "content": { + "key": { + "element": "string", + "content": "comments" + }, + "value": { + "element": "array" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"comments\": []\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 \"comments\": {}\n }\n}" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} diff --git a/test/fixtures/common-data/nested.apib b/test/fixtures/common-data/nested.apib new file mode 100644 index 000000000..004dc65fa --- /dev/null +++ b/test/fixtures/common-data/nested.apib @@ -0,0 +1,29 @@ +# API name + +# Common Data + ++ Response 404 (application/json) + + Attributes + + status: not_found + +# Group Users + +Actions of this section should have both common responses + +## Common Data + ++ Response 500 + +## User [/users] + +### List all users [GET] + ++ Response 200 (application/json) + + Attributes + + users (array) + +### User info [GET /users/{id}] + ++ Response 200 (application/json) + + Attributes + + user (object) diff --git a/test/fixtures/common-data/nested.json b/test/fixtures/common-data/nested.json new file mode 100644 index 000000000..5409b3c48 --- /dev/null +++ b/test/fixtures/common-data/nested.json @@ -0,0 +1,527 @@ +{ + "element": "parseResult", + "content": [ + { + "element": "category", + "meta": { + "classes": [ + "api" + ], + "title": "API name" + }, + "content": [ + { + "element": "commonData", + "content": [ + { + "element": "httpResponse", + "attributes": { + "statusCode": "404", + "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", + "content": { + "key": { + "element": "string", + "content": "status" + }, + "value": { + "element": "string", + "content": "not_found" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"status\": \"not_found\"\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 \"status\": {\n \"type\": \"string\"\n }\n }\n}" + } + ] + } + ] + }, + { + "element": "category", + "meta": { + "classes": [ + "resourceGroup" + ], + "title": "Users" + }, + "content": [ + { + "element": "copy", + "content": "Actions of this section should have both common responses" + }, + { + "element": "commonData", + "content": [ + { + "element": "httpResponse", + "attributes": { + "statusCode": "500" + }, + "content": [] + } + ] + }, + { + "element": "resource", + "meta": { + "title": "User" + }, + "attributes": { + "href": "/users" + }, + "content": [ + { + "element": "transition", + "meta": { + "title": "List all users" + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": "GET" + }, + "content": [] + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": "404", + "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", + "content": { + "key": { + "element": "string", + "content": "status" + }, + "value": { + "element": "string", + "content": "not_found" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"status\": \"not_found\"\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 \"status\": {\n \"type\": \"string\"\n }\n }\n}" + } + ] + } + ] + }, + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": "GET" + }, + "content": [] + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": "500" + }, + "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": "object", + "content": [ + { + "element": "member", + "content": { + "key": { + "element": "string", + "content": "users" + }, + "value": { + "element": "array" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"users\": []\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 \"users\": {}\n }\n}" + } + ] + } + ] + } + ] + }, + { + "element": "transition", + "meta": { + "title": "User info" + }, + "attributes": { + "href": "/users/{id}" + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": "GET" + }, + "content": [] + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": "404", + "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", + "content": { + "key": { + "element": "string", + "content": "status" + }, + "value": { + "element": "string", + "content": "not_found" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"status\": \"not_found\"\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 \"status\": {\n \"type\": \"string\"\n }\n }\n}" + } + ] + } + ] + }, + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": "GET" + }, + "content": [] + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": "500" + }, + "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": "object", + "content": [ + { + "element": "member", + "content": { + "key": { + "element": "string", + "content": "user" + }, + "value": { + "element": "object" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"user\": {}\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 \"user\": {\n \"type\": \"object\",\n \"properties\": {}\n }\n }\n}" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} diff --git a/test/fixtures/common-data/simple.apib b/test/fixtures/common-data/simple.apib new file mode 100644 index 000000000..13af58b46 --- /dev/null +++ b/test/fixtures/common-data/simple.apib @@ -0,0 +1,25 @@ +# API name + +# Common Data + ++ Response 404 (application/json) + + Attributes + + status: not_found + +# Group Users + +Actions of this section should have common response 404 + +## User [/users] + +### List all users [GET] + ++ Response 200 (application/json) + + Attributes + + users (array) + +### User info [GET /users/{id}] + ++ Response 200 (application/json) + + Attributes + + user (object) diff --git a/test/fixtures/common-data/simple.json b/test/fixtures/common-data/simple.json new file mode 100644 index 000000000..0f00af379 --- /dev/null +++ b/test/fixtures/common-data/simple.json @@ -0,0 +1,477 @@ +{ + "element": "parseResult", + "content": [ + { + "element": "category", + "meta": { + "classes": [ + "api" + ], + "title": "API name" + }, + "content": [ + { + "element": "commonData", + "content": [ + { + "element": "httpResponse", + "attributes": { + "statusCode": "404", + "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", + "content": { + "key": { + "element": "string", + "content": "status" + }, + "value": { + "element": "string", + "content": "not_found" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"status\": \"not_found\"\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 \"status\": {\n \"type\": \"string\"\n }\n }\n}" + } + ] + } + ] + }, + { + "element": "category", + "meta": { + "classes": [ + "resourceGroup" + ], + "title": "Users" + }, + "content": [ + { + "element": "copy", + "content": "Actions of this section should have common response 404" + }, + { + "element": "resource", + "meta": { + "title": "User" + }, + "attributes": { + "href": "/users" + }, + "content": [ + { + "element": "transition", + "meta": { + "title": "List all users" + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": "GET" + }, + "content": [] + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": "404", + "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", + "content": { + "key": { + "element": "string", + "content": "status" + }, + "value": { + "element": "string", + "content": "not_found" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"status\": \"not_found\"\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 \"status\": {\n \"type\": \"string\"\n }\n }\n}" + } + ] + } + ] + }, + { + "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": "object", + "content": [ + { + "element": "member", + "content": { + "key": { + "element": "string", + "content": "users" + }, + "value": { + "element": "array" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"users\": []\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 \"users\": {}\n }\n}" + } + ] + } + ] + } + ] + }, + { + "element": "transition", + "meta": { + "title": "User info" + }, + "attributes": { + "href": "/users/{id}" + }, + "content": [ + { + "element": "httpTransaction", + "content": [ + { + "element": "httpRequest", + "attributes": { + "method": "GET" + }, + "content": [] + }, + { + "element": "httpResponse", + "attributes": { + "statusCode": "404", + "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", + "content": { + "key": { + "element": "string", + "content": "status" + }, + "value": { + "element": "string", + "content": "not_found" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"status\": \"not_found\"\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 \"status\": {\n \"type\": \"string\"\n }\n }\n}" + } + ] + } + ] + }, + { + "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": "object", + "content": [ + { + "element": "member", + "content": { + "key": { + "element": "string", + "content": "user" + }, + "value": { + "element": "object" + } + } + } + ] + } + ] + }, + { + "element": "asset", + "meta": { + "classes": [ + "messageBody" + ] + }, + "attributes": { + "contentType": "application/json" + }, + "content": "{\n \"user\": {}\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 \"user\": {\n \"type\": \"object\",\n \"properties\": {}\n }\n }\n}" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] +} diff --git a/test/test-CommonDataTest.cc b/test/test-CommonDataTest.cc new file mode 100644 index 000000000..93a5fb365 --- /dev/null +++ b/test/test-CommonDataTest.cc @@ -0,0 +1,8 @@ + +#include "draftertest.h" + +using namespace draftertest; + +TEST_REFRACT("common-data", "simple"); +TEST_REFRACT("common-data", "nested"); +TEST_REFRACT("common-data", "multiple-groups");