reynard 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/reynard/specification.rb +17 -6
- data/lib/reynard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d703f01c7c60de48b48ae223cd9c2e3a94a8639bb866eca234298331ad746d2a
|
4
|
+
data.tar.gz: 9e88b9e21dc1b1d00357fcf8bdf2b6952676c5237369d7d950e97b379727e731
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1cccaf532a955569236a07c5c8861519cf58c0c2abe3cdf218a8a57619a41d650e9f7226ccdb1a6ef1fddfe412cd9780032dcf8f68ecf995cd2176bb8774642
|
7
|
+
data.tar.gz: 56acfbbabfea8a77e76cbee676bd0b397a608994f03f774022fd54d4e65fad06730de36aa9b122767edddb229f854eff9e8819d8a93d506ee5af66d799d18e82
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ reynard.base_url('http://test.example.com/v1')
|
|
40
40
|
You also have access to all servers in the specification so you can automatically select one however you want.
|
41
41
|
|
42
42
|
```ruby
|
43
|
-
base_url =
|
43
|
+
base_url = reynard.servers.map(&:url).find do |url|
|
44
44
|
/staging/.match(url)
|
45
45
|
end
|
46
46
|
reynard.base_url(base_url)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rack'
|
4
|
+
|
3
5
|
class Reynard
|
4
6
|
# Wraps the YAML representation of an OpenAPI specification.
|
5
7
|
class Specification
|
@@ -88,6 +90,15 @@ class Reynard
|
|
88
90
|
false
|
89
91
|
end
|
90
92
|
|
93
|
+
def self.normalize_model_name(name)
|
94
|
+
# 1. Unescape encoded characters to create an UTF-8 string
|
95
|
+
# 2. Replace all non-alphabetic characters with a space (not allowed in Ruby constant)
|
96
|
+
# 3. Camelcase
|
97
|
+
Rack::Utils.unescape_path(name)
|
98
|
+
.gsub(/[^[:alpha:]]/, ' ')
|
99
|
+
.gsub(/(\s+)([[:alpha:]])/) { Regexp.last_match(2).upcase }
|
100
|
+
end
|
101
|
+
|
91
102
|
private
|
92
103
|
|
93
104
|
def read
|
@@ -105,7 +116,7 @@ class Reynard
|
|
105
116
|
next unless cursor.respond_to?(:key?) && cursor&.key?('$ref')
|
106
117
|
|
107
118
|
# We currenly only supply references inside the document starting with #/.
|
108
|
-
path = cursor['$ref'][2..].split('/') + path
|
119
|
+
path = Rack::Utils.unescape_path(cursor['$ref'][2..]).split('/') + path
|
109
120
|
cursor = data
|
110
121
|
end
|
111
122
|
cursor
|
@@ -113,16 +124,16 @@ class Reynard
|
|
113
124
|
|
114
125
|
def schema_name(response)
|
115
126
|
ref = response.dig('schema', '$ref')
|
116
|
-
ref
|
127
|
+
return unless ref
|
128
|
+
|
129
|
+
self.class.normalize_model_name(ref&.split('/')&.last)
|
117
130
|
end
|
118
131
|
|
119
132
|
def item_schema_name(schema)
|
120
133
|
ref = schema.dig('items', '$ref')
|
121
|
-
ref
|
122
|
-
end
|
134
|
+
return unless ref
|
123
135
|
|
124
|
-
|
125
|
-
'Book'
|
136
|
+
self.class.normalize_model_name(ref&.split('/')&.last)
|
126
137
|
end
|
127
138
|
end
|
128
139
|
end
|
data/lib/reynard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reynard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manfred Stienstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|