Class: ApipieDiff::Normalizer
- Inherits:
-
Object
- Object
- ApipieDiff::Normalizer
- Defined in:
- lib/apipie_diff/normalizer.rb
Instance Method Summary collapse
Instance Method Details
#normalize(docs) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/apipie_diff/normalizer.rb', line 3 def normalize(docs) ensure_key!(docs, 'docs') ensure_key!(docs['docs'], 'resources') normalized = {} resources = docs['docs']['resources'] resources.keys.sort.each do |resource_name| normalized[resource_name] = normalize_resource(resources[resource_name]) end normalized end |
#normalize_method(m) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/apipie_diff/normalizer.rb', line 25 def normalize_method(m) ensure_key!(m, 'params') ensure_key!(m, 'apis') params = m['params'].map do |p| h = slice_hash(p, ['name', 'description', 'validator', 'expected_type', 'validations']) h['description'] = h['description'].strip h end apis = m['apis'].map do |a| h = { 'route' => a['http_method'] + ' ' + a['api_url'], 'short_description' => a['short_description'], } h['deprecated'] = a['deprecated'] unless a['deprecated'].nil? h end { 'apis' => apis, 'params' => params } end |
#normalize_resource(resource) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/apipie_diff/normalizer.rb', line 16 def normalize_resource(resource) ensure_key!(resource, 'methods') resource['methods'] = resource['methods'].inject({}) do |h, m| h.update(m['name'] => normalize_method(m)) end resource end |