matter_compiler 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/lib/matter_compiler/composer.rb +42 -15
- data/lib/matter_compiler/version.rb +1 -1
- data/test/composer_test.rb +81 -1
- metadata +3 -4
- data/Gemfile.lock +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af6044418ad5bad55bb39e240c75f793c54696f5
|
4
|
+
data.tar.gz: 9624d5754ebccb5e50c1ff6e2b3b1f878e35520e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6c06b29b400c41ee52ab5b9105f4b7480950972db6c2b32a09813bc4396470b2cd09ebeb5505d9813610b9c82e4ba326e9c3b86b8a35501bab549e0ea9b14d6
|
7
|
+
data.tar.gz: 5ce218d30c59d46da378fbb2b6a417ebfec2c0a7d76a176a1a1b09e6311908f2acee3820678627423eb8c216c762a73228295d596f996436fe02b97b84ef2948
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-

|
2
2
|
|
3
3
|
# Matter Compiler [](https://travis-ci.org/apiaryio/matter_compiler)
|
4
4
|
Matter Compiler is a [API Blueprint AST Media Types](https://github.com/apiaryio/api-blueprint-ast) to [API Blueprint](https://apiblueprint.org) conversion tool. It composes an API blueprint from its serialzed AST media-type.
|
@@ -5,13 +5,16 @@ require 'object'
|
|
5
5
|
|
6
6
|
module MatterCompiler
|
7
7
|
|
8
|
+
class BadInputException < Exception
|
9
|
+
end
|
10
|
+
|
8
11
|
class Composer
|
9
|
-
|
10
|
-
# Read AST file
|
12
|
+
|
13
|
+
# Read AST file
|
11
14
|
def self.read_file(file)
|
12
15
|
unless File.readable?(file)
|
13
16
|
abort "Unable to read input ast file: #{file.inspect}"
|
14
|
-
end
|
17
|
+
end
|
15
18
|
input = File.read(file)
|
16
19
|
end
|
17
20
|
|
@@ -31,7 +34,7 @@ module MatterCompiler
|
|
31
34
|
return :yaml_ast
|
32
35
|
else
|
33
36
|
return :unknown_ast
|
34
|
-
end
|
37
|
+
end
|
35
38
|
end
|
36
39
|
|
37
40
|
# Guess format from filename extension.
|
@@ -44,6 +47,26 @@ module MatterCompiler
|
|
44
47
|
self.parse_format(extension[1..-1])
|
45
48
|
end
|
46
49
|
|
50
|
+
def self.parse_json(input)
|
51
|
+
begin
|
52
|
+
ast_hash = JSON.parse(input).deep_symbolize_keys
|
53
|
+
rescue JSON::ParserError
|
54
|
+
raise BadInputException, "Invalid JSON input"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.parse_yaml(input)
|
59
|
+
begin
|
60
|
+
ast_hash = YAML.load(input).deep_symbolize_keys
|
61
|
+
rescue Psych::SyntaxError
|
62
|
+
raise BadInputException, "Invalid YAML input"
|
63
|
+
end
|
64
|
+
if not ast_hash.is_a?(Hash)
|
65
|
+
raise BadInputException, "Invalid AST"
|
66
|
+
end
|
67
|
+
ast_hash
|
68
|
+
end
|
69
|
+
|
47
70
|
# Compose API Blueprint from an AST file.
|
48
71
|
# Returns a string with composed API Blueprint.
|
49
72
|
def self.compose(file = nil, format = nil, set_blueprint_format = false)
|
@@ -51,25 +74,29 @@ module MatterCompiler
|
|
51
74
|
input = nil
|
52
75
|
if file.nil?
|
53
76
|
input = self.read_stdin
|
54
|
-
else
|
77
|
+
else
|
55
78
|
input = self.read_file(file)
|
56
79
|
end
|
80
|
+
input = input.strip
|
57
81
|
|
58
82
|
if input.blank?
|
59
|
-
|
60
|
-
exit
|
83
|
+
abort("Empty input")
|
61
84
|
end
|
62
85
|
|
63
86
|
# Parse input
|
64
87
|
input_format = format ? format : self.guess_format(file)
|
65
88
|
ast_hash = nil;
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
89
|
+
begin
|
90
|
+
case input_format
|
91
|
+
when :json_ast
|
92
|
+
ast_hash = self.parse_json(input)
|
93
|
+
when :yaml_ast
|
94
|
+
ast_hash = self.parse_yaml(input)
|
95
|
+
else
|
96
|
+
raise BadInputException, "Undefined input format"
|
97
|
+
end
|
98
|
+
rescue BadInputException => e
|
99
|
+
abort(e.message)
|
73
100
|
end
|
74
101
|
|
75
102
|
# Check version of the AST
|
@@ -88,7 +115,7 @@ module MatterCompiler
|
|
88
115
|
# TODO: use $stdout for now, add serialization options later
|
89
116
|
puts blueprint.serialize(set_blueprint_format)
|
90
117
|
end
|
91
|
-
|
118
|
+
|
92
119
|
end
|
93
120
|
|
94
121
|
end
|
data/test/composer_test.rb
CHANGED
@@ -1,10 +1,90 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'stringio'
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'matter_compiler/composer'
|
3
5
|
|
6
|
+
|
4
7
|
class ComposerTest < Minitest::Test
|
8
|
+
|
5
9
|
def test_guess_format
|
6
10
|
assert_equal :yaml_ast, MatterCompiler::Composer.guess_format('test.yaml')
|
7
11
|
assert_equal :json_ast, MatterCompiler::Composer.guess_format('test.json')
|
8
12
|
assert_equal :unknown_ast, MatterCompiler::Composer.guess_format('test.txt')
|
9
13
|
end
|
10
|
-
|
14
|
+
|
15
|
+
def test_empty_file_input
|
16
|
+
file = Tempfile.new('test.json')
|
17
|
+
file.close
|
18
|
+
|
19
|
+
stderr = StringIO.new
|
20
|
+
$stderr = stderr
|
21
|
+
|
22
|
+
begin
|
23
|
+
MatterCompiler::Composer.compose(file.path, :json_ast)
|
24
|
+
rescue SystemExit
|
25
|
+
ensure
|
26
|
+
assert_equal "Empty input\n", stderr.string
|
27
|
+
|
28
|
+
file.unlink
|
29
|
+
$stderr = STDERR
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_whitespace_only_file_input
|
34
|
+
file = Tempfile.new('test.json')
|
35
|
+
file.write("\n\n\n\n\n")
|
36
|
+
file.close
|
37
|
+
|
38
|
+
stderr = StringIO.new
|
39
|
+
$stderr = stderr
|
40
|
+
|
41
|
+
begin
|
42
|
+
MatterCompiler::Composer.compose(file.path, :json_ast)
|
43
|
+
rescue SystemExit
|
44
|
+
ensure
|
45
|
+
assert_equal "Empty input\n", stderr.string
|
46
|
+
|
47
|
+
file.unlink
|
48
|
+
$stderr = STDERR
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_corrupted_json_input
|
53
|
+
file = Tempfile.new('test.json')
|
54
|
+
file.write("{\n:-(")
|
55
|
+
file.close
|
56
|
+
|
57
|
+
stderr = StringIO.new
|
58
|
+
$stderr = stderr
|
59
|
+
|
60
|
+
begin
|
61
|
+
MatterCompiler::Composer.compose(file.path, :json_ast)
|
62
|
+
rescue SystemExit
|
63
|
+
ensure
|
64
|
+
assert_equal "Invalid JSON input\n", stderr.string
|
65
|
+
|
66
|
+
file.unlink
|
67
|
+
$stderr = STDERR
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_corrupted_yaml_input
|
72
|
+
file = Tempfile.new('test.yaml')
|
73
|
+
file.write("@@@@@\n:-(")
|
74
|
+
file.close
|
75
|
+
|
76
|
+
stderr = StringIO.new
|
77
|
+
$stderr = stderr
|
78
|
+
|
79
|
+
begin
|
80
|
+
MatterCompiler::Composer.compose(file.path, :yaml_ast)
|
81
|
+
rescue SystemExit
|
82
|
+
ensure
|
83
|
+
assert_equal "Invalid YAML input\n", stderr.string
|
84
|
+
|
85
|
+
file.unlink
|
86
|
+
$stderr = STDERR
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matter_compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zdenek Nemec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,7 +78,6 @@ files:
|
|
78
78
|
- ".gitignore"
|
79
79
|
- ".travis.yml"
|
80
80
|
- Gemfile
|
81
|
-
- Gemfile.lock
|
82
81
|
- LICENSE
|
83
82
|
- README.md
|
84
83
|
- Rakefile
|
@@ -123,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
122
|
version: '0'
|
124
123
|
requirements: []
|
125
124
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.2.
|
125
|
+
rubygems_version: 2.2.2
|
127
126
|
signing_key:
|
128
127
|
specification_version: 4
|
129
128
|
summary: API Blueprint AST to API Blueprint convertor
|
data/Gemfile.lock
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/cucumber/aruba.git
|
3
|
-
revision: 99d8e6a5992af17b014783e775409bc3fd422273
|
4
|
-
specs:
|
5
|
-
aruba (0.5.4)
|
6
|
-
childprocess (>= 0.3.6)
|
7
|
-
cucumber (>= 1.1.1)
|
8
|
-
rspec-expectations (>= 2.7.0)
|
9
|
-
|
10
|
-
PATH
|
11
|
-
remote: .
|
12
|
-
specs:
|
13
|
-
matter_compiler (0.5.0)
|
14
|
-
|
15
|
-
GEM
|
16
|
-
remote: https://rubygems.org/
|
17
|
-
specs:
|
18
|
-
builder (3.2.2)
|
19
|
-
childprocess (0.4.0)
|
20
|
-
ffi (~> 1.0, >= 1.0.11)
|
21
|
-
cucumber (1.3.10)
|
22
|
-
builder (>= 2.1.2)
|
23
|
-
diff-lcs (>= 1.1.3)
|
24
|
-
gherkin (~> 2.12)
|
25
|
-
multi_json (>= 1.7.5, < 2.0)
|
26
|
-
multi_test (>= 0.0.2)
|
27
|
-
diff-lcs (1.2.5)
|
28
|
-
ffi (1.9.3)
|
29
|
-
gherkin (2.12.2)
|
30
|
-
multi_json (~> 1.3)
|
31
|
-
minitest (5.2.1)
|
32
|
-
multi_json (1.8.4)
|
33
|
-
multi_test (0.0.3)
|
34
|
-
rake (10.1.1)
|
35
|
-
rspec-expectations (2.14.4)
|
36
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
37
|
-
|
38
|
-
PLATFORMS
|
39
|
-
ruby
|
40
|
-
|
41
|
-
DEPENDENCIES
|
42
|
-
aruba!
|
43
|
-
bundler (~> 1.5)
|
44
|
-
cucumber
|
45
|
-
matter_compiler!
|
46
|
-
minitest
|
47
|
-
rake
|