redsnow 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.gitmodules +3 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/Rakefile +36 -0
- data/Vagrantfile +20 -0
- data/ext/snowcrash/Makefile +64 -0
- data/ext/snowcrash/Vagrantfile +20 -0
- data/ext/snowcrash/bin/snowcrash +0 -0
- data/ext/snowcrash/common.gypi +163 -0
- data/ext/snowcrash/config.gypi +10 -0
- data/ext/snowcrash/config.mk +5 -0
- data/ext/snowcrash/configure +213 -0
- data/ext/snowcrash/provisioning.sh +15 -0
- data/ext/snowcrash/snowcrash.gyp +141 -0
- data/ext/snowcrash/src/ActionParser.h +503 -0
- data/ext/snowcrash/src/AssetParser.h +215 -0
- data/ext/snowcrash/src/BlockUtility.h +186 -0
- data/ext/snowcrash/src/Blueprint.h +283 -0
- data/ext/snowcrash/src/BlueprintParser.h +347 -0
- data/ext/snowcrash/src/BlueprintParserCore.h +190 -0
- data/ext/snowcrash/src/BlueprintSection.h +140 -0
- data/ext/snowcrash/src/BlueprintUtility.h +126 -0
- data/ext/snowcrash/src/CBlueprint.cc +600 -0
- data/ext/snowcrash/src/CBlueprint.h +354 -0
- data/ext/snowcrash/src/CSourceAnnotation.cc +140 -0
- data/ext/snowcrash/src/CSourceAnnotation.h +106 -0
- data/ext/snowcrash/src/CodeBlockUtility.h +189 -0
- data/ext/snowcrash/src/DescriptionSectionUtility.h +156 -0
- data/ext/snowcrash/src/HTTP.cc +46 -0
- data/ext/snowcrash/src/HTTP.h +105 -0
- data/ext/snowcrash/src/HeaderParser.h +289 -0
- data/ext/snowcrash/src/ListBlockUtility.h +273 -0
- data/ext/snowcrash/src/ListUtility.h +95 -0
- data/ext/snowcrash/src/MarkdownBlock.cc +176 -0
- data/ext/snowcrash/src/MarkdownBlock.h +93 -0
- data/ext/snowcrash/src/MarkdownParser.cc +266 -0
- data/ext/snowcrash/src/MarkdownParser.h +88 -0
- data/ext/snowcrash/src/ParameterDefinitonParser.h +570 -0
- data/ext/snowcrash/src/ParametersParser.h +252 -0
- data/ext/snowcrash/src/Parser.cc +71 -0
- data/ext/snowcrash/src/Parser.h +29 -0
- data/ext/snowcrash/src/ParserCore.cc +120 -0
- data/ext/snowcrash/src/ParserCore.h +82 -0
- data/ext/snowcrash/src/PayloadParser.h +672 -0
- data/ext/snowcrash/src/Platform.h +54 -0
- data/ext/snowcrash/src/RegexMatch.h +32 -0
- data/ext/snowcrash/src/ResourceGroupParser.h +195 -0
- data/ext/snowcrash/src/ResourceParser.h +584 -0
- data/ext/snowcrash/src/SectionUtility.h +142 -0
- data/ext/snowcrash/src/Serialize.cc +52 -0
- data/ext/snowcrash/src/Serialize.h +69 -0
- data/ext/snowcrash/src/SerializeJSON.cc +601 -0
- data/ext/snowcrash/src/SerializeJSON.h +21 -0
- data/ext/snowcrash/src/SerializeYAML.cc +336 -0
- data/ext/snowcrash/src/SerializeYAML.h +21 -0
- data/ext/snowcrash/src/SourceAnnotation.h +177 -0
- data/ext/snowcrash/src/StringUtility.h +109 -0
- data/ext/snowcrash/src/SymbolTable.h +83 -0
- data/ext/snowcrash/src/UriTemplateParser.cc +195 -0
- data/ext/snowcrash/src/UriTemplateParser.h +243 -0
- data/ext/snowcrash/src/Version.h +39 -0
- data/ext/snowcrash/src/csnowcrash.cc +23 -0
- data/ext/snowcrash/src/csnowcrash.h +38 -0
- data/ext/snowcrash/src/posix/RegexMatch.cc +99 -0
- data/ext/snowcrash/src/snowcrash.cc +18 -0
- data/ext/snowcrash/src/snowcrash.h +41 -0
- data/ext/snowcrash/src/snowcrash/snowcrash.cc +170 -0
- data/ext/snowcrash/src/win/RegexMatch.cc +78 -0
- data/ext/snowcrash/sundown/CONTRIBUTING.md +10 -0
- data/ext/snowcrash/sundown/Makefile +83 -0
- data/ext/snowcrash/sundown/Makefile.win +33 -0
- data/ext/snowcrash/sundown/examples/smartypants.c +72 -0
- data/ext/snowcrash/sundown/examples/sundown.c +80 -0
- data/ext/snowcrash/sundown/html/houdini.h +37 -0
- data/ext/snowcrash/sundown/html/houdini_href_e.c +108 -0
- data/ext/snowcrash/sundown/html/houdini_html_e.c +84 -0
- data/ext/snowcrash/sundown/html/html.c +647 -0
- data/ext/snowcrash/sundown/html/html.h +77 -0
- data/ext/snowcrash/sundown/html/html_smartypants.c +389 -0
- data/ext/snowcrash/sundown/html_block_names.txt +25 -0
- data/ext/snowcrash/sundown/src/autolink.c +297 -0
- data/ext/snowcrash/sundown/src/autolink.h +51 -0
- data/ext/snowcrash/sundown/src/buffer.c +225 -0
- data/ext/snowcrash/sundown/src/buffer.h +96 -0
- data/ext/snowcrash/sundown/src/html_blocks.h +206 -0
- data/ext/snowcrash/sundown/src/markdown.c +2701 -0
- data/ext/snowcrash/sundown/src/markdown.h +147 -0
- data/ext/snowcrash/sundown/src/src_map.c +200 -0
- data/ext/snowcrash/sundown/src/src_map.h +58 -0
- data/ext/snowcrash/sundown/src/stack.c +81 -0
- data/ext/snowcrash/sundown/src/stack.h +29 -0
- data/ext/snowcrash/sundown/sundown.def +20 -0
- data/ext/snowcrash/tools/gyp/AUTHORS +11 -0
- data/ext/snowcrash/tools/gyp/DEPS +24 -0
- data/ext/snowcrash/tools/gyp/OWNERS +1 -0
- data/ext/snowcrash/tools/gyp/PRESUBMIT.py +120 -0
- data/ext/snowcrash/tools/gyp/buildbot/buildbot_run.py +190 -0
- data/ext/snowcrash/tools/gyp/codereview.settings +10 -0
- data/ext/snowcrash/tools/gyp/data/win/large-pdb-shim.cc +12 -0
- data/ext/snowcrash/tools/gyp/gyp +8 -0
- data/ext/snowcrash/tools/gyp/gyp.bat +5 -0
- data/ext/snowcrash/tools/gyp/gyp_main.py +18 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSNew.py +340 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSProject.py +208 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSSettings.py +1063 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSToolFile.py +58 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUserFile.py +147 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSUtil.py +267 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/MSVSVersion.py +409 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.py +537 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/__init__.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/common.py +521 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/common.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/easy_xml.py +157 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/flock_tool.py +49 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.py +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/__init__.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/android.py +1069 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/cmake.py +1143 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/dump_dependency_json.py +81 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/eclipse.py +335 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypd.py +87 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/gypsh.py +56 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.py +2181 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/make.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/msvs.py +3335 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/ninja.py +2156 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.py +1224 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/generator/xcode.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/input.py +2809 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/input.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/mac_tool.py +510 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/msvs_emulation.py +972 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/ninja_syntax.py +160 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/ordered_dict.py +289 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/win_tool.py +292 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.py +1440 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.py +2889 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xcodeproj_file.pyc +0 -0
- data/ext/snowcrash/tools/gyp/pylib/gyp/xml_fix.py +69 -0
- data/ext/snowcrash/tools/gyp/pylintrc +307 -0
- data/ext/snowcrash/tools/gyp/samples/samples +81 -0
- data/ext/snowcrash/tools/gyp/samples/samples.bat +5 -0
- data/ext/snowcrash/tools/gyp/setup.py +19 -0
- data/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.pbfilespec +27 -0
- data/ext/snowcrash/tools/gyp/tools/Xcode/Specifications/gyp.xclangspec +226 -0
- data/ext/snowcrash/tools/gyp/tools/emacs/gyp.el +252 -0
- data/ext/snowcrash/tools/gyp/tools/graphviz.py +100 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_gyp.py +155 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_sln.py +168 -0
- data/ext/snowcrash/tools/gyp/tools/pretty_vcproj.py +329 -0
- data/ext/snowcrash/tools/homebrew/snowcrash.rb +11 -0
- data/ext/snowcrash/vcbuild.bat +184 -0
- data/lib/redsnow.rb +31 -0
- data/lib/redsnow/binding.rb +132 -0
- data/lib/redsnow/blueprint.rb +365 -0
- data/lib/redsnow/object.rb +18 -0
- data/lib/redsnow/parseresult.rb +107 -0
- data/lib/redsnow/version.rb +4 -0
- data/provisioning.sh +20 -0
- data/redsnow.gemspec +35 -0
- data/test/_helper.rb +15 -0
- data/test/fixtures/sample-api-ast.json +97 -0
- data/test/fixtures/sample-api.apib +20 -0
- data/test/redsnow_binding_test.rb +35 -0
- data/test/redsnow_parseresult_test.rb +50 -0
- data/test/redsnow_test.rb +285 -0
- metadata +358 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# Essential extensions to base object class
|
2
|
+
module RedSnow
|
3
|
+
# Class from MatterCompiler as ascendant
|
4
|
+
class Object
|
5
|
+
|
6
|
+
# Symbolizes keys of a hash
|
7
|
+
def deep_symbolize_keys
|
8
|
+
return self.inject({}){|memo, (k,v)| memo[k.to_sym] = v.deep_symbolize_keys; memo} if self.is_a? Hash
|
9
|
+
return self.inject([]){|memo, v | memo << v.deep_symbolize_keys; memo} if self.is_a? Array
|
10
|
+
return self
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns true if object is nil or empty, false otherwise
|
14
|
+
def blank?
|
15
|
+
respond_to?(:empty?) ? empty? : !self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module RedSnow
|
2
|
+
|
3
|
+
# Parse Result
|
4
|
+
# @see https://github.com/apiaryio/api-blueprint-ast/blob/master/Parse%20Result.md
|
5
|
+
# @param ast [Blueprint]
|
6
|
+
# @param error [Hash] Description of a parsing error as occurred during parsing. If this field is present and code different from 0 then the content of ast field should be ignored.
|
7
|
+
# @param warnings [Array<Hash>] Ordered array of parser warnings as occurred during the parsing.
|
8
|
+
class ParseResult
|
9
|
+
attr_accessor :ast
|
10
|
+
attr_accessor :error
|
11
|
+
attr_accessor :warnings
|
12
|
+
|
13
|
+
# Version key
|
14
|
+
VERSION_KEY = :_version
|
15
|
+
# Supported version of Api Blueprint
|
16
|
+
SUPPORTED_VERSIONS = ["2.0"]
|
17
|
+
|
18
|
+
# @param result_handle [FFI::Pointer]
|
19
|
+
def initialize(blueprint_handle, result_handle)
|
20
|
+
|
21
|
+
@ast = Blueprint.new(blueprint_handle)
|
22
|
+
warnings = RedSnow::Binding.sc_warnings_handler(result_handle)
|
23
|
+
warningsSize = RedSnow::Binding.sc_warnings_size(warnings)
|
24
|
+
@warnings = Array.new
|
25
|
+
for index in 0..(warningsSize - 1) do
|
26
|
+
sc_warning_handler = RedSnow::Binding.sc_warning_handler(warnings, index)
|
27
|
+
|
28
|
+
warning = Hash.new
|
29
|
+
warning[:message] = RedSnow::Binding.sc_warning_message(sc_warning_handler)
|
30
|
+
warning[:code] = RedSnow::Binding.sc_warning_code(sc_warning_handler)
|
31
|
+
warning[:ok] = RedSnow::Binding.sc_warning_ok(sc_warning_handler)
|
32
|
+
|
33
|
+
sc_location_handler = RedSnow::Binding.sc_location_handler(sc_warning_handler)
|
34
|
+
sc_location_size = RedSnow::Binding.sc_location_size(sc_location_handler)
|
35
|
+
warning[:location] = Array.new
|
36
|
+
if sc_location_size > 0
|
37
|
+
for index in 0..(sc_location_size - 1)
|
38
|
+
location = Location.new(sc_location_handler, index)
|
39
|
+
warning[:location] << location
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@warnings << warning
|
43
|
+
end
|
44
|
+
|
45
|
+
error_handler = RedSnow::Binding.sc_error_handler(result_handle)
|
46
|
+
@error = Hash.new
|
47
|
+
@error[:message] = RedSnow::Binding.sc_error_message(error_handler)
|
48
|
+
@error[:code] = RedSnow::Binding.sc_error_code(error_handler)
|
49
|
+
@error[:ok] = RedSnow::Binding.sc_error_ok(error_handler)
|
50
|
+
|
51
|
+
sc_location_handler = RedSnow::Binding.sc_location_handler(error_handler)
|
52
|
+
sc_location_size = RedSnow::Binding.sc_location_size(sc_location_handler)
|
53
|
+
@error[:location] = Array.new
|
54
|
+
if sc_location_size > 0
|
55
|
+
for index in 0..(sc_location_size - 1) do
|
56
|
+
location = Location.new(sc_location_handler, index)
|
57
|
+
@error[:location] << location
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Array of possibly non-continuous blocks of the source API Blueprint.
|
64
|
+
# @param index [Number] Zero-based index of the character where warning has occurred.
|
65
|
+
# @param length [Number] Number of the characters from index where warning has occurred.
|
66
|
+
class Location
|
67
|
+
|
68
|
+
attr_accessor :index
|
69
|
+
attr_accessor :length
|
70
|
+
|
71
|
+
# @param location_hander [FFI:Pointer]
|
72
|
+
# @param index [Number]
|
73
|
+
def initialize(location_hander, index)
|
74
|
+
@length = RedSnow::Binding.sc_location_length(location_hander, index)
|
75
|
+
@index = RedSnow::Binding.sc_location_location(location_hander, index)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
# Warnning Codes
|
81
|
+
# @see https://github.com/apiaryio/snowcrash/blob/master/src/SourceAnnotation.h#L128
|
82
|
+
class WarningCodes
|
83
|
+
NoWarning = 0
|
84
|
+
APINameWarning = 1
|
85
|
+
DuplicateWarning = 2
|
86
|
+
FormattingWarning = 3
|
87
|
+
RedefinitionWarning = 4
|
88
|
+
IgnoringWarning = 5
|
89
|
+
EmptyDefinitionWarning = 6
|
90
|
+
NotEmptyDefinitionWarning = 7
|
91
|
+
LogicalErrorWarning = 8
|
92
|
+
DeprecatedWarning = 9
|
93
|
+
IndentationWarning = 10
|
94
|
+
AmbiguityWarning = 11
|
95
|
+
URIWarning = 12
|
96
|
+
|
97
|
+
end
|
98
|
+
# Error Codes
|
99
|
+
# @see https://github.com/apiaryio/snowcrash/blob/master/src/SourceAnnotation.h#L113
|
100
|
+
class ErrorCodes
|
101
|
+
NoError = 0
|
102
|
+
ApplicationError = 1
|
103
|
+
BusinessError = 2
|
104
|
+
SymbolError = 3
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
data/provisioning.sh
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# GCC 4.7
|
4
|
+
sudo apt-get update -y
|
5
|
+
sudo apt-get install -y python-software-properties
|
6
|
+
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
7
|
+
sudo apt-get update -y
|
8
|
+
sudo apt-get install -y gcc-4.7 g++-4.7 gdb build-essential git-core curl mc vim
|
9
|
+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
|
10
|
+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
|
11
|
+
|
12
|
+
#sudo update-alternatives --config gcc
|
13
|
+
|
14
|
+
# Ruby
|
15
|
+
gem install bundler
|
16
|
+
# RVM
|
17
|
+
curl -sSL https://get.rvm.io | bash -s stable
|
18
|
+
/home/vagrant/.rvm/bin/rvm install 2.1.0
|
19
|
+
rvm ruby-2.1.0
|
20
|
+
gem install bundler
|
data/redsnow.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'redsnow/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "redsnow"
|
8
|
+
gem.version = RedSnow::VERSION
|
9
|
+
gem.authors = ["Ladislav Prskavec"]
|
10
|
+
gem.email = ["ladislav@apiary.io"]
|
11
|
+
gem.description = %q{Ruby bindings for Snow Crash}
|
12
|
+
gem.summary = %q{Ruby bindings for Snow Crash}
|
13
|
+
gem.homepage = "https://github.com/apiaryio/redsnow"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.files << Dir[ 'ext/snowcrash/**/*' ].reject { |f| f =~ /cmdline|test|features|README*|LICENSE|Gemfile*|\.xcode*/ }
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib", "ext"]
|
21
|
+
|
22
|
+
gem.required_ruby_version = '>= 1.9.3'
|
23
|
+
|
24
|
+
gem.extensions = %w(Rakefile)
|
25
|
+
|
26
|
+
gem.add_dependency "ffi", "~> 1.9.3"
|
27
|
+
gem.add_dependency "rake", "~> 10.3.2"
|
28
|
+
gem.add_dependency "yard", "~> 0.8.7.4"
|
29
|
+
|
30
|
+
gem.add_development_dependency "shoulda"
|
31
|
+
gem.add_development_dependency "mocha"
|
32
|
+
gem.add_development_dependency "turn"
|
33
|
+
gem.add_development_dependency "unindent"
|
34
|
+
|
35
|
+
end
|
data/test/_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'turn' unless ENV["TM_FILEPATH"] || ENV["CI"]
|
6
|
+
require 'mocha'
|
7
|
+
require File.join(File.expand_path('../../lib/redsnow.rb', __FILE__))
|
8
|
+
|
9
|
+
class Test::Unit::TestCase
|
10
|
+
|
11
|
+
def fixture_file(name)
|
12
|
+
File.read File.expand_path("../fixtures/#{name}", __FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
{
|
2
|
+
"_version": "2.0",
|
3
|
+
"metadata": [
|
4
|
+
{
|
5
|
+
"name": "FORMAT",
|
6
|
+
"value": "1A"
|
7
|
+
}
|
8
|
+
],
|
9
|
+
"name": "",
|
10
|
+
"description": "",
|
11
|
+
"resourceGroups": [
|
12
|
+
{
|
13
|
+
"name": "Messages",
|
14
|
+
"description": "",
|
15
|
+
"resources": [
|
16
|
+
{
|
17
|
+
"name": "Message",
|
18
|
+
"description": "",
|
19
|
+
"uriTemplate": "/messages/{id}",
|
20
|
+
"model": {},
|
21
|
+
"parameters": [
|
22
|
+
{
|
23
|
+
"name": "id",
|
24
|
+
"description": "Id of a message",
|
25
|
+
"type": "",
|
26
|
+
"required": true,
|
27
|
+
"default": "",
|
28
|
+
"example": "",
|
29
|
+
"values": [
|
30
|
+
{
|
31
|
+
"value": "1"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"value": "2"
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"value": "3"
|
38
|
+
}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
],
|
42
|
+
"actions": [
|
43
|
+
{
|
44
|
+
"name": "Retrieve Message",
|
45
|
+
"description": "",
|
46
|
+
"method": "GET",
|
47
|
+
"parameters": [],
|
48
|
+
"examples": [
|
49
|
+
{
|
50
|
+
"name": "",
|
51
|
+
"description": "",
|
52
|
+
"requests": [],
|
53
|
+
"responses": [
|
54
|
+
{
|
55
|
+
"name": "200",
|
56
|
+
"description": "",
|
57
|
+
"headers": [
|
58
|
+
{
|
59
|
+
"name": "Content-Type",
|
60
|
+
"value": "text/plain"
|
61
|
+
}
|
62
|
+
],
|
63
|
+
"body": "Hello World!\n",
|
64
|
+
"schema": ""
|
65
|
+
}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
]
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"name": "Delete Message",
|
72
|
+
"description": "",
|
73
|
+
"method": "DELETE",
|
74
|
+
"parameters": [],
|
75
|
+
"examples": [
|
76
|
+
{
|
77
|
+
"name": "",
|
78
|
+
"description": "",
|
79
|
+
"requests": [],
|
80
|
+
"responses": [
|
81
|
+
{
|
82
|
+
"name": "204",
|
83
|
+
"description": "",
|
84
|
+
"headers": [],
|
85
|
+
"body": "",
|
86
|
+
"schema": ""
|
87
|
+
}
|
88
|
+
]
|
89
|
+
}
|
90
|
+
]
|
91
|
+
}
|
92
|
+
]
|
93
|
+
}
|
94
|
+
]
|
95
|
+
}
|
96
|
+
]
|
97
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
FORMAT: 1A
|
2
|
+
|
3
|
+
# Group Messages
|
4
|
+
|
5
|
+
# Message [/messages/{id}]
|
6
|
+
|
7
|
+
+ Parameters
|
8
|
+
+ id ... Id of a message
|
9
|
+
+ Values
|
10
|
+
+ `1`
|
11
|
+
+ `2`
|
12
|
+
+ `3`
|
13
|
+
|
14
|
+
## Retrieve Message [GET]
|
15
|
+
+ Response 200 (text/plain)
|
16
|
+
|
17
|
+
Hello World!
|
18
|
+
|
19
|
+
## Delete Message [DELETE]
|
20
|
+
+ Response 204
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require '_helper'
|
2
|
+
|
3
|
+
class RedSnowBindingTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "RedSnow Binding" do
|
6
|
+
should "convert API Blueprint to AST" do
|
7
|
+
|
8
|
+
blueprint = FFI::MemoryPointer.new :pointer
|
9
|
+
result = FFI::MemoryPointer.new :pointer
|
10
|
+
|
11
|
+
ret = RedSnow::Binding.sc_c_parse("meta: data\nfoo:bar\n#XXXX\ndescription for it", 0, result, blueprint)
|
12
|
+
|
13
|
+
blueprint = blueprint.get_pointer(0)
|
14
|
+
result = result.get_pointer(0)
|
15
|
+
assert_equal "XXXX", RedSnow::Binding.sc_blueprint_name(blueprint)
|
16
|
+
|
17
|
+
assert_equal "description for it", RedSnow::Binding.sc_blueprint_description(blueprint)
|
18
|
+
|
19
|
+
meta_data_col = RedSnow::Binding.sc_metadata_collection_handle(blueprint)
|
20
|
+
assert_equal 2, RedSnow::Binding.sc_metadata_collection_size(meta_data_col)
|
21
|
+
|
22
|
+
warnings = RedSnow::Binding.sc_warnings_handler(result)
|
23
|
+
assert_equal 0, RedSnow::Binding.sc_warnings_size(warnings)
|
24
|
+
|
25
|
+
error = RedSnow::Binding.sc_error_handler(result)
|
26
|
+
assert_equal '', RedSnow::Binding.sc_error_message(error)
|
27
|
+
assert_equal 0, RedSnow::Binding.sc_error_code(error)
|
28
|
+
assert_equal 0, RedSnow::Binding.sc_error_ok(error)
|
29
|
+
|
30
|
+
RedSnow::Binding.sc_blueprint_free(blueprint)
|
31
|
+
RedSnow::Binding.sc_result_free(result)
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require '_helper'
|
2
|
+
require 'unindent'
|
3
|
+
|
4
|
+
class RedSnowParseResultTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context "Simple API" do
|
7
|
+
setup do
|
8
|
+
@result = RedSnow.parse("# My API")
|
9
|
+
end
|
10
|
+
|
11
|
+
should "have name" do
|
12
|
+
assert_equal "My API", @result.ast.name
|
13
|
+
end
|
14
|
+
|
15
|
+
should "don't have error" do
|
16
|
+
assert_equal 0, @result.error[:ok]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "Simple API with warning" do
|
21
|
+
setup do
|
22
|
+
@source = <<-STR
|
23
|
+
FORMAT: 1A
|
24
|
+
# My API
|
25
|
+
## GET /
|
26
|
+
STR
|
27
|
+
@result = RedSnow.parse(@source.unindent)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "have name" do
|
31
|
+
assert_equal "My API", @result.ast.name
|
32
|
+
end
|
33
|
+
|
34
|
+
should "don't have error" do
|
35
|
+
assert_equal 0, @result.error[:code]
|
36
|
+
end
|
37
|
+
|
38
|
+
should "have some warning" do
|
39
|
+
assert_equal RedSnow::WarningCodes::EmptyDefinitionWarning, @result.warnings[0][:code]
|
40
|
+
assert_equal "no response defined for 'GET /'", @result.warnings[0][:message]
|
41
|
+
|
42
|
+
assert_equal 20, @result.warnings[0][:location][0].index
|
43
|
+
assert_equal 9, @result.warnings[0][:location][0].length
|
44
|
+
|
45
|
+
assert_equal "## GET /\n", @source.unindent[20..@source.unindent.length]
|
46
|
+
# Line in blueprint
|
47
|
+
assert_equal 3, @source.unindent[0..20].lines.count
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
require '_helper'
|
2
|
+
require 'unindent'
|
3
|
+
|
4
|
+
class RedSnowParsingTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# https://github.com/apiaryio/protagonist/blob/master/test/parser-test.coffee
|
7
|
+
context "API Blueprint parser" do
|
8
|
+
|
9
|
+
context "API" do
|
10
|
+
setup do
|
11
|
+
@result = RedSnow.parse("# My API")
|
12
|
+
end
|
13
|
+
|
14
|
+
should "have name" do
|
15
|
+
assert_equal "My API", @result.ast.name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "API" do
|
20
|
+
setup do
|
21
|
+
source = <<-STR
|
22
|
+
**description**
|
23
|
+
STR
|
24
|
+
|
25
|
+
@result = RedSnow.parse(source.unindent)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "have description" do
|
29
|
+
assert_equal "", @result.ast.name
|
30
|
+
assert_equal "**description**\n", @result.ast.description
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "Group" do
|
35
|
+
setup do
|
36
|
+
source = <<-STR
|
37
|
+
# Group Name
|
38
|
+
_description_
|
39
|
+
STR
|
40
|
+
|
41
|
+
@result = RedSnow.parse(source.unindent)
|
42
|
+
end
|
43
|
+
should "have resource group" do
|
44
|
+
assert_equal 1, @result.ast.resource_groups.count
|
45
|
+
assert_equal "Name", @result.ast.resource_groups[0].name
|
46
|
+
assert_equal "_description_\n", @result.ast.resource_groups[0].description
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "Resource" do
|
51
|
+
|
52
|
+
setup do
|
53
|
+
|
54
|
+
source = <<-STR
|
55
|
+
# My Resource [/resource]
|
56
|
+
Resource description
|
57
|
+
|
58
|
+
+ Model (text/plain)
|
59
|
+
|
60
|
+
Hello World
|
61
|
+
|
62
|
+
## Retrieve Resource [GET]
|
63
|
+
Method description
|
64
|
+
|
65
|
+
+ Response 200 (text/plain)
|
66
|
+
|
67
|
+
Response description
|
68
|
+
|
69
|
+
+ Headers
|
70
|
+
|
71
|
+
X-Response-Header: Fighter
|
72
|
+
|
73
|
+
+ Body
|
74
|
+
|
75
|
+
Y.T.
|
76
|
+
|
77
|
+
+ Schema
|
78
|
+
|
79
|
+
Kourier
|
80
|
+
|
81
|
+
## Delete Resource [DELETE]
|
82
|
+
|
83
|
+
+ Response 200
|
84
|
+
|
85
|
+
[My Resource][]
|
86
|
+
|
87
|
+
STR
|
88
|
+
|
89
|
+
@result = RedSnow.parse(source.unindent)
|
90
|
+
@resourceGroup = @result.ast.resource_groups[0]
|
91
|
+
@resource = @resourceGroup.resources[0]
|
92
|
+
@action = @resource.actions[0]
|
93
|
+
end
|
94
|
+
|
95
|
+
should "have resource group" do
|
96
|
+
assert_equal 1, @result.ast.resource_groups.count
|
97
|
+
assert_equal "", @resourceGroup.name
|
98
|
+
assert_equal "", @resourceGroup.description
|
99
|
+
assert_equal 1, @resourceGroup.resources.count
|
100
|
+
end
|
101
|
+
|
102
|
+
should "have resource" do
|
103
|
+
assert_equal "/resource", @resource.uri_template
|
104
|
+
assert_equal "My Resource", @resource.name
|
105
|
+
assert_equal "Resource description\n\n", @resource.description
|
106
|
+
end
|
107
|
+
|
108
|
+
should "have resource model" do
|
109
|
+
assert_equal "My Resource", @resource.model.name
|
110
|
+
assert_equal "", @resource.model.description
|
111
|
+
assert_equal "Hello World\n", @resource.model.body
|
112
|
+
assert_equal 1, @resource.model.headers.collection.count
|
113
|
+
assert_equal "Content-Type", @resource.model.headers.collection[0][:name]
|
114
|
+
assert_equal "text/plain", @resource.model.headers.collection[0][:value]
|
115
|
+
end
|
116
|
+
|
117
|
+
should "have actions" do
|
118
|
+
assert_equal 2, @resource.actions.count
|
119
|
+
assert_equal "GET", @action.method
|
120
|
+
assert_equal "Retrieve Resource", @action.name
|
121
|
+
assert_equal "Method description\n\n", @action.description
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
context "parses blueprint metadata" do
|
127
|
+
setup do
|
128
|
+
source = <<-STR
|
129
|
+
FORMAT: 1A
|
130
|
+
A: 1
|
131
|
+
B: 2
|
132
|
+
C: 3
|
133
|
+
|
134
|
+
# API Name
|
135
|
+
STR
|
136
|
+
|
137
|
+
@result = RedSnow.parse(source.unindent)
|
138
|
+
@metadata = @result.ast.metadata.collection
|
139
|
+
end
|
140
|
+
|
141
|
+
should "have metadata" do
|
142
|
+
assert_equal 'FORMAT', @metadata[0][:name]
|
143
|
+
assert_equal '1A', @metadata[0][:value]
|
144
|
+
|
145
|
+
assert_equal 'A', @metadata[1][:name]
|
146
|
+
assert_equal '1', @metadata[1][:value]
|
147
|
+
|
148
|
+
assert_equal 'B', @metadata[2][:name]
|
149
|
+
assert_equal '2', @metadata[2][:value]
|
150
|
+
|
151
|
+
assert_equal 'C', @metadata[3][:name]
|
152
|
+
assert_equal '3', @metadata[3][:value]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "parses resource parameters" do
|
157
|
+
setup do
|
158
|
+
source = <<-STR
|
159
|
+
# /machine{?limit}
|
160
|
+
|
161
|
+
+ Parameters
|
162
|
+
+ limit = `20` (optional, number, `42`) ... This is a limit
|
163
|
+
+ Values
|
164
|
+
+ `20`
|
165
|
+
+ `42`
|
166
|
+
+ `53`
|
167
|
+
|
168
|
+
## GET
|
169
|
+
|
170
|
+
+ Response 204
|
171
|
+
STR
|
172
|
+
|
173
|
+
@result = RedSnow.parse(source.unindent)
|
174
|
+
@resourceGroup = @result.ast.resource_groups[0]
|
175
|
+
@resource = @resourceGroup.resources[0]
|
176
|
+
@parameter = @resource.parameters.collection[0]
|
177
|
+
@values = @parameter.values
|
178
|
+
end
|
179
|
+
|
180
|
+
should "have parameters" do
|
181
|
+
assert_equal 'limit', @parameter.name
|
182
|
+
assert_equal 'This is a limit', @parameter.description
|
183
|
+
assert_equal 'number', @parameter.type
|
184
|
+
assert_equal :optional, @parameter.use
|
185
|
+
assert_equal '20', @parameter.default_value
|
186
|
+
assert_equal '42', @parameter.example_value
|
187
|
+
assert_equal 3, @parameter.values.count
|
188
|
+
|
189
|
+
|
190
|
+
assert_equal '20', @values[0]
|
191
|
+
assert_equal '42', @values[1]
|
192
|
+
assert_equal '53', @values[2]
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "parses action parameters" do
|
197
|
+
setup do
|
198
|
+
source = <<-STR
|
199
|
+
# GET /coupons/{id}
|
200
|
+
|
201
|
+
+ Parameters
|
202
|
+
+ id (number, `1001`) ... Id of coupon
|
203
|
+
|
204
|
+
+ Response 204
|
205
|
+
STR
|
206
|
+
|
207
|
+
@result = RedSnow.parse(source.unindent)
|
208
|
+
@resourceGroup = @result.ast.resource_groups[0]
|
209
|
+
@resource = @resourceGroup.resources[0]
|
210
|
+
@action = @resource.actions[0]
|
211
|
+
@parameter = @action.parameters.collection[0]
|
212
|
+
end
|
213
|
+
|
214
|
+
should "have parameters" do
|
215
|
+
assert_equal 'id', @parameter.name
|
216
|
+
assert_equal :undefined, @parameter.use
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context "parses multiple transactions" do
|
221
|
+
setup do
|
222
|
+
source = <<-STR
|
223
|
+
## Notes Collection [/notes?id={id}&testingGroup={testtingGroup}&collection={collection}]
|
224
|
+
### Create a Note [POST]
|
225
|
+
+ Request Create a note
|
226
|
+
|
227
|
+
+ Headers
|
228
|
+
|
229
|
+
Content-Type: application/json
|
230
|
+
Prefer: creating
|
231
|
+
|
232
|
+
+ Body
|
233
|
+
|
234
|
+
{ "title": "Buy cheese and bread for breakfast." }
|
235
|
+
|
236
|
+
+ Response 201 (application/json)
|
237
|
+
|
238
|
+
{ "id": 3, "title": "Buy cheese and bread for breakfast." }
|
239
|
+
|
240
|
+
+ Request Unable to create note
|
241
|
+
|
242
|
+
+ Headers
|
243
|
+
|
244
|
+
Content-Type: application/json
|
245
|
+
Prefer: testing
|
246
|
+
|
247
|
+
|
248
|
+
+ Body
|
249
|
+
|
250
|
+
{ "ti": "Buy cheese and bread for breakfast." }
|
251
|
+
|
252
|
+
+ Response 500
|
253
|
+
|
254
|
+
{ "error": "can't create record" }
|
255
|
+
STR
|
256
|
+
@result = RedSnow.parse(source.unindent)
|
257
|
+
@resourceGroup = @result.ast.resource_groups[0]
|
258
|
+
@examples = @resourceGroup.resources[0].actions[0].examples
|
259
|
+
end
|
260
|
+
|
261
|
+
should "have multiple requests and responses" do
|
262
|
+
assert_equal 2, @examples.count
|
263
|
+
assert_equal 1, @examples[0].requests.count
|
264
|
+
assert_equal 1, @examples[0].responses.count
|
265
|
+
assert_equal "", @examples[0].name
|
266
|
+
assert_equal "", @examples[0].description
|
267
|
+
assert_equal "Create a note", @examples[0].requests[0].name
|
268
|
+
assert_equal "Content-Type", @examples[0].requests[0].headers.collection[0][:name]
|
269
|
+
assert_equal "application/json", @examples[0].requests[0].headers.collection[0][:value]
|
270
|
+
assert_equal "Prefer", @examples[0].requests[0].headers.collection[1][:name]
|
271
|
+
assert_equal "creating", @examples[0].requests[0].headers.collection[1][:value]
|
272
|
+
assert_equal "201", @examples[0].responses[0].name
|
273
|
+
assert_equal "Unable to create note", @examples[1].requests[0].name
|
274
|
+
assert_equal "Content-Type", @examples[1].requests[0].headers.collection[0][:name]
|
275
|
+
assert_equal "application/json", @examples[1].requests[0].headers.collection[0][:value]
|
276
|
+
assert_equal "Prefer", @examples[1].requests[0].headers.collection[1][:name]
|
277
|
+
assert_equal "testing", @examples[1].requests[0].headers.collection[1][:value]
|
278
|
+
assert_equal '{ "ti": "Buy cheese and bread for breakfast." }' + "\n", @examples[1].requests[0].body
|
279
|
+
assert_equal "500", @examples[1].responses[0].name
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|