Class: Joshua::PostmanSchema
- Inherits:
-
Object
- Object
- Joshua::PostmanSchema
- Defined in:
- lib/doc/postman_schema.rb
Instance Method Summary collapse
-
#initialize(api) ⇒ PostmanSchema
constructor
A new instance of PostmanSchema.
- #postman ⇒ Object
- #raw ⇒ Object
Constructor Details
#initialize(api) ⇒ PostmanSchema
Returns a new instance of PostmanSchema.
5 6 7 |
# File 'lib/doc/postman_schema.rb', line 5 def initialize api @api = api end |
Instance Method Details
#postman ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/doc/postman_schema.rb', line 9 def postman out = { info: { _postman_id: request.url, _bearer_token: @api[:bearer], name: request.host, schema: "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, item: [] } for api_name, raw_data in raw hash = {} hash[:name] = api_name hash[:item] = [] for type in [:collection, :member] next unless raw_data[type] if raw_data[type] items = [] for key, value in raw_data[type] items.push postman_add_method( type: type, object_name: api_name, name: key, item: value ) end hash[:item].push *items # to have it grouped by collection or member methods # hash[:item].push(name: type, item: items) end end out[:item].push hash end @api[:development] ? JSON.pretty_generate(out) : out.to_json end |
#raw ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/doc/postman_schema.rb', line 52 def raw unwanted = %w(all member collection) {}.tap do |doc| for el in Joshua.documented doc[el.to_s.sub(/Api$/, '').underscore] = el.opts.filter do |k, v| for k1, v1 in v if v1.is_a?(Hash) for k2 in v1.keys # remove Typero v1.delete(k2) if k2.to_s.start_with?('_') end end end !unwanted.include?(k.to_s.split('_')[1]) end end end end |