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

Commit

Permalink
Merge pull request #498 from apiaryio/klokane/enum
Browse files Browse the repository at this point in the history
Conform to new Enum Element definition
  • Loading branch information
tjanc authored Sep 22, 2017
2 parents 25e3310 + b640f99 commit 77284fd
Show file tree
Hide file tree
Showing 58 changed files with 2,254 additions and 1,275 deletions.
2 changes: 1 addition & 1 deletion drafter.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@

"src/refract/Build.h",

"src/refract/AppendDecorator.h",
"src/refract/ElementInserter.h",
"src/refract/Query.h",
"src/refract/Query.cc",
Expand Down Expand Up @@ -348,6 +347,7 @@
"test/test-ElementFactoryTest.cc",
"test/test-OneOfTest.cc",
"test/test-SyntaxIssuesTest.cc",
"test/test-ElementDataTest.cc",
],
'dependencies': [
"libdrafter",
Expand Down
4 changes: 0 additions & 4 deletions drafter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
19A1298F1B70ABE100366AA7 /* SerializeResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 19A129791B70ABE100366AA7 /* SerializeResult.h */; };
19A129921B70ABE100366AA7 /* stream.h in Headers */ = {isa = PBXBuildFile; fileRef = 19A1297C1B70ABE100366AA7 /* stream.h */; };
19A129931B70ABE100366AA7 /* Version.h in Headers */ = {isa = PBXBuildFile; fileRef = 19A1297D1B70ABE100366AA7 /* Version.h */; };
19A129AF1B70AC9A00366AA7 /* AppendDecorator.h in Headers */ = {isa = PBXBuildFile; fileRef = 19A129971B70AC9A00366AA7 /* AppendDecorator.h */; };
19A129B01B70AC9A00366AA7 /* ComparableVisitor.cc in Sources */ = {isa = PBXBuildFile; fileRef = 19A129981B70AC9A00366AA7 /* ComparableVisitor.cc */; };
19A129B11B70AC9A00366AA7 /* ComparableVisitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 19A129991B70AC9A00366AA7 /* ComparableVisitor.h */; };
19A129B21B70AC9A00366AA7 /* Element.cc in Sources */ = {isa = PBXBuildFile; fileRef = 19A1299A1B70AC9A00366AA7 /* Element.cc */; };
Expand Down Expand Up @@ -141,7 +140,6 @@
19A129791B70ABE100366AA7 /* SerializeResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SerializeResult.h; path = src/SerializeResult.h; sourceTree = SOURCE_ROOT; };
19A1297C1B70ABE100366AA7 /* stream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = stream.h; path = src/stream.h; sourceTree = SOURCE_ROOT; };
19A1297D1B70ABE100366AA7 /* Version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Version.h; path = src/Version.h; sourceTree = SOURCE_ROOT; };
19A129971B70AC9A00366AA7 /* AppendDecorator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppendDecorator.h; path = src/refract/AppendDecorator.h; sourceTree = SOURCE_ROOT; };
19A129981B70AC9A00366AA7 /* ComparableVisitor.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ComparableVisitor.cc; path = src/refract/ComparableVisitor.cc; sourceTree = SOURCE_ROOT; };
19A129991B70AC9A00366AA7 /* ComparableVisitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ComparableVisitor.h; path = src/refract/ComparableVisitor.h; sourceTree = SOURCE_ROOT; };
19A1299A1B70AC9A00366AA7 /* Element.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Element.cc; path = src/refract/Element.cc; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -291,7 +289,6 @@
19A129961B70AC7B00366AA7 /* refract */ = {
isa = PBXGroup;
children = (
19A129971B70AC9A00366AA7 /* AppendDecorator.h */,
400F53F61C5989F1004EA235 /* Build.h */,
19A129981B70AC9A00366AA7 /* ComparableVisitor.cc */,
19A129991B70AC9A00366AA7 /* ComparableVisitor.h */,
Expand Down Expand Up @@ -424,7 +421,6 @@
400F53FD1C5989F1004EA235 /* Build.h in Headers */,
40D03D4F1C182FBD008AD2EF /* VisitorUtils.h in Headers */,
19A129B81B70AC9A00366AA7 /* IsExpandableVisitor.h in Headers */,
19A129AF1B70AC9A00366AA7 /* AppendDecorator.h in Headers */,
40DDBDD81BE14EA700B10819 /* RefractSourceMap.h in Headers */,
19A129931B70ABE100366AA7 /* Version.h in Headers */,
19A129921B70ABE100366AA7 /* stream.h in Headers */,
Expand Down
50 changes: 50 additions & 0 deletions features/fixtures/refract.sourcemap.json
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,31 @@
"meta": {
"description": {
"element": "string",
"attributes": {
"sourceMap": {
"element": "array",
"content": [
{
"element": "sourceMap",
"content": [
{
"element": "array",
"content": [
{
"element": "number",
"content": 200
},
{
"element": "number",
"content": 102
}
]
}
]
}
]
}
},
"content": "<attribute property description>"
}
},
Expand Down Expand Up @@ -3086,6 +3111,31 @@
"meta": {
"description": {
"element": "string",
"attributes": {
"sourceMap": {
"element": "array",
"content": [
{
"element": "sourceMap",
"content": [
{
"element": "array",
"content": [
{
"element": "number",
"content": 1647
},
{
"element": "number",
"content": 117
}
]
}
]
}
]
}
},
"content": "<data structure property description>"
}
},
Expand Down
32 changes: 32 additions & 0 deletions features/fixtures/refract.sourcemap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,22 @@ content:
meta:
description:
element: "string"
attributes:
sourceMap:
element: "array"
content:
-
element: "sourceMap"
content:
-
element: "array"
content:
-
element: "number"
content: 200
-
element: "number"
content: 102
content: "<attribute property description>"
content:
key:
Expand Down Expand Up @@ -2013,6 +2029,22 @@ content:
meta:
description:
element: "string"
attributes:
sourceMap:
element: "array"
content:
-
element: "sourceMap"
content:
-
element: "array"
content:
-
element: "number"
content: 1647
-
element: "number"
content: 117
content: "<data structure property description>"
content:
key:
Expand Down
4 changes: 4 additions & 0 deletions src/ConversionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ namespace drafter
{
return registry;
}
inline const refract::Registry& GetNamedTypesRegistry() const
{
return registry;
}

ConversionContext(const WrapperOptions& options) : options(options)
{
Expand Down
62 changes: 62 additions & 0 deletions src/ElementData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// ElementData.h
// drafter
//
// Created by Jiri Kratochvil on 08/08/17.
// Copyright (c) 2017 Apiary Inc. All rights reserved.
//
#ifndef DRAFTER_ELEMENTDATA_H
#define DRAFTER_ELEMENTDATA_H

#include "RefractSourceMap.h"

namespace drafter
{

template <typename T>
struct IsPrimitive {
using ValueType = typename T::ValueType;
using type = std::integral_constant<bool,
!std::is_same<ValueType, refract::RefractElements>::value
&& !std::is_same<ValueType, refract::IElement*>::value>;
};

template <typename T>
struct ElementData {
using ElementType = T;

using ValueType = typename ElementType::ValueType;
using ValueSourceMapType = snowcrash::SourceMap<ValueType>;


//typedef typename std::conditional<std::is_same<ValueType, refract::RefractElements>::value
// || std::is_same<ValueType, refract::IElement*>::value, // check for primitive values
// std::false_type,
// std::true_type>::type IsPrimitive;

// This is required because snowcrash internal stuctures holds data
// for primitive types as "string" for complex types as "element array"
// it will be converted into apropriated element type once all required data are colected

using StoredType = typename std::conditional<IsPrimitive<T>::type::value,
std::string, // for primitive values, we will hold data as string
refract::RefractElements // for complex types, we will hold elements
>::type;

using ElementInfo = std::tuple<StoredType, ValueSourceMapType>; // [value, sourceMap]
using DescriptionInfo = std::tuple<std::string, snowcrash::SourceMap<std::string> >; // [description, sourceMap]

using ElementInfoContainer = std::vector<ElementInfo>;
using DescriptionInfoContainer = std::vector<DescriptionInfo>;

ElementInfoContainer values;
ElementInfoContainer defaults;
ElementInfoContainer samples;
ElementInfoContainer enumerations;

DescriptionInfoContainer descriptions;
};

} // namespace drafter

#endif // #ifndef DRAFTER_ELEMENTDATA_H
Loading

0 comments on commit 77284fd

Please sign in to comment.