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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec98b52096f95c7c03aaa61a7f27555f5d595ab83ac15510e49fbdc600cbb3a0
4
- data.tar.gz: e3fc7d6e0aa537ea08c727e89aec68b2e66986f5e4e1e53ebd6f74733bde6b8b
3
+ metadata.gz: d703f01c7c60de48b48ae223cd9c2e3a94a8639bb866eca234298331ad746d2a
4
+ data.tar.gz: 9e88b9e21dc1b1d00357fcf8bdf2b6952676c5237369d7d950e97b379727e731
5
5
  SHA512:
6
- metadata.gz: 2b18bf2403a99460ded8be2c85efc08b28ffa8616d35628dbdb0806f58613e426acf48eff05d6f0c74bc0e602ed9a0bb6bc69e3604818b6b7a1ba9f1c4f38848
7
- data.tar.gz: c566c502480ff527e5e8a6451bebd5b8629c714fb41a27faa486a311fb8a20ee85aea14d1c89c211fe20e6dd63e768027d678593341178d89177cda3f24512df
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 = @reynard.servers.map(&:url).find do |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&.split('/')&.last
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&.split('/')&.last
122
- end
134
+ return unless ref
123
135
 
124
- def object_name(_schema)
125
- 'Book'
136
+ self.class.normalize_model_name(ref&.split('/')&.last)
126
137
  end
127
138
  end
128
139
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Reynard
4
- VERSION = '0.0.9'
4
+ VERSION = '0.1.0'
5
5
  end
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.9
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-04 00:00:00.000000000 Z
11
+ date: 2021-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json