mini-apivore 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/mini_apivore.rb +3 -2
- data/lib/mini_apivore/http_codes.rb +1 -0
- data/lib/mini_apivore/swagger_checker.rb +6 -3
- data/lib/mini_apivore/to_param.rb +84 -0
- data/lib/mini_apivore/validation.rb +2 -2
- data/lib/mini_apivore/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 22b3e64224e3cb029e8c3111796f6fc1efeb95fc1de2aa74ff52ad5016754e3e
|
4
|
+
data.tar.gz: 5152527ad6fefca981afd144ad63cef076572e9102d8e2a2a3d2ba949eeabbe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ae18ce44b6d6698cd8f2471aec7b9c664a8b5dd8ce33f3d25bf75a7b78263e08e1c63328e086a0af3429308d52d97897244a5552b956b3b901333c7eeeced40
|
7
|
+
data.tar.gz: 7368f20fb149e79f122b41c1fe76704b6bfe8a4c22c9422152d1f37961334fbec36e24e1697712182c7cd057f2d1995cdbd6c8b2ceb998198f7c06069c439bb2
|
data/lib/mini_apivore.rb
CHANGED
@@ -5,6 +5,7 @@ require 'mini_apivore/swagger'
|
|
5
5
|
require 'mini_apivore/swagger_checker'
|
6
6
|
require 'mini_apivore/validation'
|
7
7
|
require 'mini_apivore/http_codes'
|
8
|
+
require 'mini_apivore/to_param'
|
8
9
|
|
9
10
|
module MiniApivore
|
10
11
|
SWAGGER_CHECKERS = {}
|
@@ -34,8 +35,8 @@ module MiniApivore
|
|
34
35
|
#---- class methods -----------
|
35
36
|
module ClassMethods
|
36
37
|
|
37
|
-
def init_swagger( swagger_path )
|
38
|
-
SWAGGER_CHECKERS[self] ||= MiniApivore::SwaggerChecker.instance_for(swagger_path)
|
38
|
+
def init_swagger( swagger_path, schema= '' )
|
39
|
+
SWAGGER_CHECKERS[self] ||= MiniApivore::SwaggerChecker.instance_for(swagger_path, schema)
|
39
40
|
end
|
40
41
|
|
41
42
|
def runnable_methods
|
@@ -4,8 +4,8 @@ module MiniApivore
|
|
4
4
|
class SwaggerChecker
|
5
5
|
PATH_TO_CHECKER_MAP = {}
|
6
6
|
|
7
|
-
def self.instance_for(path)
|
8
|
-
PATH_TO_CHECKER_MAP[path] ||= new(path)
|
7
|
+
def self.instance_for(path, schema = '' )
|
8
|
+
PATH_TO_CHECKER_MAP[path] ||= new(path, schema)
|
9
9
|
end
|
10
10
|
|
11
11
|
def has_path?(path)
|
@@ -64,8 +64,9 @@ module MiniApivore
|
|
64
64
|
|
65
65
|
attr_reader :mappings
|
66
66
|
|
67
|
-
def initialize(swagger_path)
|
67
|
+
def initialize(swagger_path, schema )
|
68
68
|
@swagger_path = swagger_path
|
69
|
+
@schema = schema
|
69
70
|
load_swagger_doc!
|
70
71
|
validate_swagger!
|
71
72
|
setup_mappings!
|
@@ -77,6 +78,8 @@ module MiniApivore
|
|
77
78
|
end
|
78
79
|
|
79
80
|
def fetch_swagger!
|
81
|
+
return @schema unless @schema.empty?
|
82
|
+
|
80
83
|
if File.exist?( swagger_path )
|
81
84
|
JSON.parse( File.read(swagger_path) )
|
82
85
|
else
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "cgi"
|
2
|
+
|
3
|
+
class Object
|
4
|
+
# Alias of <tt>to_s</tt>.
|
5
|
+
def to_param
|
6
|
+
to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
# Converts an object into a string suitable for use as a URL query string,
|
10
|
+
# using the given <tt>key</tt> as the param name.
|
11
|
+
def to_query(key)
|
12
|
+
"#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
|
13
|
+
end
|
14
|
+
end unless Object.method_defined?( :to_param )
|
15
|
+
|
16
|
+
class NilClass
|
17
|
+
# Returns +self+.
|
18
|
+
def to_param
|
19
|
+
self
|
20
|
+
end
|
21
|
+
end unless NilClass.method_defined?( :to_param )
|
22
|
+
|
23
|
+
class TrueClass
|
24
|
+
# Returns +self+.
|
25
|
+
def to_param
|
26
|
+
self
|
27
|
+
end
|
28
|
+
end unless TrueClass.method_defined?( :to_param )
|
29
|
+
|
30
|
+
class FalseClass
|
31
|
+
# Returns +self+.
|
32
|
+
def to_param
|
33
|
+
self
|
34
|
+
end
|
35
|
+
end unless FalseClass.method_defined?( :to_param )
|
36
|
+
|
37
|
+
class Array
|
38
|
+
# Calls <tt>to_param</tt> on all its elements and joins the result with
|
39
|
+
# slashes. This is used by <tt>url_for</tt> in Action Pack.
|
40
|
+
def to_param
|
41
|
+
collect(&:to_param).join "/"
|
42
|
+
end
|
43
|
+
|
44
|
+
# Converts an array into a string suitable for use as a URL query string,
|
45
|
+
# using the given +key+ as the param name.
|
46
|
+
#
|
47
|
+
# ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
|
48
|
+
def to_query(key)
|
49
|
+
prefix = "#{key}[]"
|
50
|
+
|
51
|
+
if empty?
|
52
|
+
nil.to_query(prefix)
|
53
|
+
else
|
54
|
+
collect { |value| value.to_query(prefix) }.join "&"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end unless Array.method_defined?( :to_param )
|
58
|
+
|
59
|
+
class Hash
|
60
|
+
# Returns a string representation of the receiver suitable for use as a URL
|
61
|
+
# query string:
|
62
|
+
#
|
63
|
+
# {name: 'David', nationality: 'Danish'}.to_query
|
64
|
+
# # => "name=David&nationality=Danish"
|
65
|
+
#
|
66
|
+
# An optional namespace can be passed to enclose key names:
|
67
|
+
#
|
68
|
+
# {name: 'David', nationality: 'Danish'}.to_query('user')
|
69
|
+
# # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
|
70
|
+
#
|
71
|
+
# The string pairs "key=value" that conform the query string
|
72
|
+
# are sorted lexicographically in ascending order.
|
73
|
+
#
|
74
|
+
# This method is also aliased as +to_param+.
|
75
|
+
def to_query(namespace = nil)
|
76
|
+
collect do |key, value|
|
77
|
+
unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
|
78
|
+
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
79
|
+
end
|
80
|
+
end.compact.sort! * "&"
|
81
|
+
end
|
82
|
+
|
83
|
+
alias_method :to_param, :to_query
|
84
|
+
end unless Hash.method_defined?( :to_param )
|
@@ -20,7 +20,7 @@ module MiniApivore
|
|
20
20
|
|
21
21
|
def check_route( verb, path, expected_response_code, params = {} )
|
22
22
|
prepare_action_env( verb, path, expected_response_code, params )
|
23
|
-
assert( match?, failure_message )
|
23
|
+
assert( match?, "Failure message: #{failure_message},\n fullpath: #{full_path}, \n params causing failure:#{params}" )
|
24
24
|
end
|
25
25
|
|
26
26
|
def match?
|
@@ -82,7 +82,7 @@ module MiniApivore
|
|
82
82
|
key = param.first
|
83
83
|
dkey = data && ( data[key] || data[key.to_sym] )
|
84
84
|
if dkey
|
85
|
-
path = path.gsub "{#{key}}", dkey.
|
85
|
+
path = path.gsub "{#{key}}", dkey.to_param
|
86
86
|
else
|
87
87
|
raise URI::InvalidURIError, "No substitution data found for {#{key}}"\
|
88
88
|
" to test the path #{path}.", caller
|
data/lib/mini_apivore/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini-apivore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|
@@ -70,18 +70,18 @@ dependencies:
|
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 12.3.3
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
83
|
-
description: "
|
84
|
-
schema "
|
82
|
+
version: 12.3.3
|
83
|
+
description: " Minitest adaptation of apivore gem,\n Provides
|
84
|
+
a tool for testing your application api against your swagger schema "
|
85
85
|
email:
|
86
86
|
- leshchuk@gmail.com
|
87
87
|
executables: []
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/mini_apivore/http_codes.rb
|
97
97
|
- lib/mini_apivore/swagger.rb
|
98
98
|
- lib/mini_apivore/swagger_checker.rb
|
99
|
+
- lib/mini_apivore/to_param.rb
|
99
100
|
- lib/mini_apivore/validation.rb
|
100
101
|
- lib/mini_apivore/version.rb
|
101
102
|
homepage: https://github.com/alekseyl/mini-apivore
|
@@ -119,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
120
|
- !ruby/object:Gem::Version
|
120
121
|
version: '0'
|
121
122
|
requirements: []
|
122
|
-
|
123
|
-
rubygems_version: 2.6.13
|
123
|
+
rubygems_version: 3.0.1
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Minitest adaptation of an apivore gem
|