Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common data #468

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions drafter.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"test/test-ElementFactoryTest.cc",
"test/test-OneOfTest.cc",
"test/test-SyntaxIssuesTest.cc",
"test/test-CommonDataTest.cc",
],
'dependencies': [
"libdrafter",
Expand Down
3 changes: 3 additions & 0 deletions drafter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 = "<group>"; };
40EF03DC1B72135E00865990 /* test-RefractDataStructureTest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "test-RefractDataStructureTest.cc"; path = "test/test-RefractDataStructureTest.cc"; sourceTree = "<group>"; };
9D3FD1EE1EB5FD5500DD4E11 /* test-CommonDataTest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "test-CommonDataTest.cc"; path = "test/test-CommonDataTest.cc"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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 */,
Expand Down
21 changes: 21 additions & 0 deletions src/RefractAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,25 @@ namespace drafter {
return category;
}

refract::IElement* CommonDataToRefract(const NodeInfo<snowcrash::Element>& 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<snowcrash::Response> info = NodeInfo<snowcrash::Response>(&*respIt, &*smIt);
content.push_back(PayloadToRefract(info, NodeInfo<snowcrash::Action>(), context));
}

commonData->element(SerializeKey::CommonData);
commonData->set(content);

return commonData;
}

refract::IElement* ElementToRefract(const NodeInfo<snowcrash::Element>& element, ConversionContext& context)
{
switch (element.node->element) {
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/Serialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions src/Serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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`
*
Expand Down
33 changes: 33 additions & 0 deletions test/fixtures/common-data/multiple-groups.apib
Original file line number Diff line number Diff line change
@@ -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)
Loading