swagger-shell 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +45 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/swagger-shell +6 -0
- data/config/env.yml +10 -0
- data/config/swagger-shell.yml +7 -0
- data/lib/swagger/shell/api_struct.rb +171 -0
- data/lib/swagger/shell/doc_loader.rb +35 -0
- data/lib/swagger/shell/interface.rb +73 -0
- data/lib/swagger/shell/user.rb +63 -0
- data/lib/swagger/shell/version.rb +5 -0
- data/lib/swagger/shell.rb +70 -0
- data/swagger-shell.gemspec +34 -0
- metadata +147 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: e597c90a4b76d100bc2b694fb7d389346bb71a4a
         | 
| 4 | 
            +
              data.tar.gz: c41111166cd641a11160ea6d36e9125ee4955af7
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 532e20ab70c63eae78e26ecc26936ccd481b50f1cae09275e25f99123ade51bf507108c2947e0148e44d89e283328cc86903d3e933daaedcd908f95d5dd61ddf
         | 
| 7 | 
            +
              data.tar.gz: e82eb55767a67935952862495cdd6fcb42595124a18f12c250b2de7ad7553eec60325d482636eadd3dad6498cf11c31a663624b56e5683b9eb04cfea7c28ff6e
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: .
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                swagger-shell (0.0.1)
         | 
| 5 | 
            +
                  faraday (~> 0.10)
         | 
| 6 | 
            +
                  parallel (~> 1.12)
         | 
| 7 | 
            +
                  pry (~> 0.11)
         | 
| 8 | 
            +
                  rb-readline (~> 0.5)
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            GEM
         | 
| 11 | 
            +
              remote: https://rubygems.org/
         | 
| 12 | 
            +
              specs:
         | 
| 13 | 
            +
                coderay (1.1.2)
         | 
| 14 | 
            +
                diff-lcs (1.3)
         | 
| 15 | 
            +
                faraday (0.15.4)
         | 
| 16 | 
            +
                  multipart-post (>= 1.2, < 3)
         | 
| 17 | 
            +
                method_source (0.9.2)
         | 
| 18 | 
            +
                multipart-post (2.0.0)
         | 
| 19 | 
            +
                parallel (1.12.1)
         | 
| 20 | 
            +
                pry (0.12.2)
         | 
| 21 | 
            +
                  coderay (~> 1.1.0)
         | 
| 22 | 
            +
                  method_source (~> 0.9.0)
         | 
| 23 | 
            +
                rake (10.5.0)
         | 
| 24 | 
            +
                rb-readline (0.5.5)
         | 
| 25 | 
            +
                rspec (3.8.0)
         | 
| 26 | 
            +
                  rspec-core (~> 3.8.0)
         | 
| 27 | 
            +
                  rspec-expectations (~> 3.8.0)
         | 
| 28 | 
            +
                  rspec-mocks (~> 3.8.0)
         | 
| 29 | 
            +
                rspec-core (3.8.0)
         | 
| 30 | 
            +
                  rspec-support (~> 3.8.0)
         | 
| 31 | 
            +
                rspec-expectations (3.8.2)
         | 
| 32 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 33 | 
            +
                  rspec-support (~> 3.8.0)
         | 
| 34 | 
            +
                rspec-mocks (3.8.0)
         | 
| 35 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 36 | 
            +
                  rspec-support (~> 3.8.0)
         | 
| 37 | 
            +
                rspec-support (3.8.0)
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            PLATFORMS
         | 
| 40 | 
            +
              ruby
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            DEPENDENCIES
         | 
| 43 | 
            +
              rake (~> 10.0)
         | 
| 44 | 
            +
              rspec (~> 3.0)
         | 
| 45 | 
            +
              swagger-shell!
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            # Swagger::Shell
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/swagger/shell`. To experiment with that code, run `bin/console` for an interactive prompt.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            TODO: Delete this and the text above, and describe your gem
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ## Installation
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            Add this line to your application's Gemfile:
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ```ruby
         | 
| 12 | 
            +
            gem 'swagger-shell'
         | 
| 13 | 
            +
            ```
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            And then execute:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ bundle
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            Or install it yourself as:
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                $ gem install swagger-shell
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ## Usage
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            TODO: Write usage instructions here
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            ## Development
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            ## Contributing
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/swagger-shell.
         | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/console
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "bundler/setup"
         | 
| 4 | 
            +
            require "swagger/shell"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            # You can add fixtures and/or initialization code here to make experimenting
         | 
| 7 | 
            +
            # with your gem easier. You can also use a different console, if you like.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            # (If you use this, don't forget to add pry to your Gemfile!)
         | 
| 10 | 
            +
            # require "pry"
         | 
| 11 | 
            +
            # Pry.start
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            require "irb"
         | 
| 14 | 
            +
            IRB.start(__FILE__)
         | 
    
        data/bin/setup
    ADDED
    
    
    
        data/bin/swagger-shell
    ADDED
    
    
    
        data/config/env.yml
    ADDED
    
    
| @@ -0,0 +1,171 @@ | |
| 1 | 
            +
            module Swagger
         | 
| 2 | 
            +
              module Shell
         | 
| 3 | 
            +
                module ApiGet
         | 
| 4 | 
            +
                  def get(message = {})
         | 
| 5 | 
            +
                    _get(api_url, message)
         | 
| 6 | 
            +
                  end
         | 
| 7 | 
            +
                end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                module ApiPost
         | 
| 10 | 
            +
                  def post(message = {})
         | 
| 11 | 
            +
                    _post(api_url, message)
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                module ApiPut
         | 
| 16 | 
            +
                  def put(message = {})
         | 
| 17 | 
            +
                    _put(api_url, message)
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                module ApiDelete
         | 
| 22 | 
            +
                  def delete(message = {})
         | 
| 23 | 
            +
                    _delete(api_url, message)
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                class ApiStruct
         | 
| 28 | 
            +
                  attr_reader :parent, :children
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  def initialize(key, parent = nil)
         | 
| 31 | 
            +
                    @key = key
         | 
| 32 | 
            +
                    @parent = parent
         | 
| 33 | 
            +
                    @children = []
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  def root?
         | 
| 37 | 
            +
                    @parent.nil?
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def api_key
         | 
| 41 | 
            +
                    @key
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  def method_key
         | 
| 45 | 
            +
                    root? ? "api" : @key
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  def add_api(path_keys, method, api_info: nil)
         | 
| 49 | 
            +
                    find_or_create_api_struct(path_keys).tap do |api_struct|
         | 
| 50 | 
            +
                      api_struct.add_api_module(method) if api_struct
         | 
| 51 | 
            +
                    end
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  def api_list
         | 
| 55 | 
            +
                    @children.each_with_object({}) do |key, hash|
         | 
| 56 | 
            +
                      hash.merge!(instance_variable_get("@#{key}").api_list)
         | 
| 57 | 
            +
                    end.tap do |hash|
         | 
| 58 | 
            +
                      api_methods.each do |api_method|
         | 
| 59 | 
            +
                        hash[api_method] = ""
         | 
| 60 | 
            +
                      end
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  def api_url
         | 
| 65 | 
            +
                    # TODO: Is there simply + no problem? If possible, pass from outside.
         | 
| 66 | 
            +
                    Swagger::Shell.config_api.ignore_top_url + api_ancestors.map(&:api_key).join("/")
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                  def api_methods
         | 
| 70 | 
            +
                    %i[get post put delete].map do |method|
         | 
| 71 | 
            +
                      (api_ancestors.map(&:method_key) << method).join(".") if singleton_class.include? self.class.module_class(method)
         | 
| 72 | 
            +
                    end.compact
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                  def api_ancestors
         | 
| 76 | 
            +
                    loop.inject([self]) do |parents|
         | 
| 77 | 
            +
                      break parents if parents.last.parent.nil?
         | 
| 78 | 
            +
                      parents << parents.last.parent
         | 
| 79 | 
            +
                      parents
         | 
| 80 | 
            +
                    end.reverse
         | 
| 81 | 
            +
                  end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  def add_api_module(method)
         | 
| 84 | 
            +
                    extend self.class.module_class(method)
         | 
| 85 | 
            +
                  end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                  def child(path_key)
         | 
| 88 | 
            +
                    # not implement url with id (i.g.: hoge/111/age)
         | 
| 89 | 
            +
                    # TODO: (i.g.: api.hoge(111).age.post )
         | 
| 90 | 
            +
                    return nil if /\A\{\w+\}\Z/.match(path_key)
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                    unless respond_to? path_key
         | 
| 93 | 
            +
                      instance_variable_set("@#{path_key}", ApiStruct.new(path_key,self))
         | 
| 94 | 
            +
                      instance_eval <<-RUBY
         | 
| 95 | 
            +
                        def self.#{path_key}
         | 
| 96 | 
            +
                          @#{path_key}
         | 
| 97 | 
            +
                        end
         | 
| 98 | 
            +
                      RUBY
         | 
| 99 | 
            +
                      @children << path_key.to_sym
         | 
| 100 | 
            +
                    end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                    instance_variable_get("@#{path_key}")
         | 
| 103 | 
            +
                  end
         | 
| 104 | 
            +
             | 
| 105 | 
            +
                  def user
         | 
| 106 | 
            +
                    Swagger::Shell.user
         | 
| 107 | 
            +
                  end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                  def self.module_class(method)
         | 
| 110 | 
            +
                    camelize_name = method.to_s.dup.tap {|s| s[0] = s[0].upcase }
         | 
| 111 | 
            +
                    Swagger::Shell.const_get("Api#{camelize_name}")
         | 
| 112 | 
            +
                  end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                  private
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                  def hook_request_body(body)
         | 
| 117 | 
            +
                    body
         | 
| 118 | 
            +
                  end
         | 
| 119 | 
            +
             | 
| 120 | 
            +
                  def hook_request_headers
         | 
| 121 | 
            +
                    Swagger::Shell.config_env.request_headers.to_h
         | 
| 122 | 
            +
                  end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                  def hook_response_body(body)
         | 
| 125 | 
            +
                    # TODO: need to implement expect for json
         | 
| 126 | 
            +
                    JSON.parse body, symbolize_names: true
         | 
| 127 | 
            +
                  end
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                  def find_or_create_api_struct(path_keys)
         | 
| 130 | 
            +
                    path_keys.inject(self) do |api_struct, path_key|
         | 
| 131 | 
            +
                      break nil if api_struct.nil?
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                      api_struct.child(path_key)
         | 
| 134 | 
            +
                    end
         | 
| 135 | 
            +
                  end
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                  def _get(url, message = {})
         | 
| 138 | 
            +
                    _request(:get, url, message)
         | 
| 139 | 
            +
                  end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                  def _post(url, message = {})
         | 
| 142 | 
            +
                    _request(:post, url, message)
         | 
| 143 | 
            +
                  end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                  def _put(url, message = {})
         | 
| 146 | 
            +
                    _request(:put, url, message)
         | 
| 147 | 
            +
                  end
         | 
| 148 | 
            +
             | 
| 149 | 
            +
                  def _delete(url, message = {})
         | 
| 150 | 
            +
                    _request(:delete, url, message)
         | 
| 151 | 
            +
                  end
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                  def _request(method, url, params = {})
         | 
| 154 | 
            +
                    res = begin
         | 
| 155 | 
            +
                      client = Faraday.new(:url => Swagger::Shell.config_env.api_url)
         | 
| 156 | 
            +
                      client.public_send(method) do |req|
         | 
| 157 | 
            +
                        req.url url
         | 
| 158 | 
            +
                        hook_request_headers.each do |k, v|
         | 
| 159 | 
            +
                          req.headers[k] = v.to_s
         | 
| 160 | 
            +
                        end
         | 
| 161 | 
            +
                        req.body = hook_request_body(params).to_json
         | 
| 162 | 
            +
                      end
         | 
| 163 | 
            +
                    rescue => e
         | 
| 164 | 
            +
                      raise e
         | 
| 165 | 
            +
                    end
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                    hook_response_body(res.body)
         | 
| 168 | 
            +
                  end
         | 
| 169 | 
            +
                end
         | 
| 170 | 
            +
              end
         | 
| 171 | 
            +
            end
         | 
| @@ -0,0 +1,35 @@ | |
| 1 | 
            +
            module Swagger
         | 
| 2 | 
            +
              module Shell
         | 
| 3 | 
            +
                class DocLoader
         | 
| 4 | 
            +
                  def load(url)
         | 
| 5 | 
            +
                    api_docs = JSON.parse(Faraday.new(url: url).get.body)
         | 
| 6 | 
            +
                    swagger_version = api_docs["swaggerVersion"] || api_docs["swagger"]
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    ApiStruct.new(api_docs["basePath"]).tap do |root_api|
         | 
| 9 | 
            +
                      # TODO: refactor
         | 
| 10 | 
            +
                      if swagger_version == "1.2"
         | 
| 11 | 
            +
                        api_docs["apis"].each do |api|
         | 
| 12 | 
            +
                          api_body = JSON.parse Faraday.new(url: url + api["path"].gsub("{format}", :json.to_s)).get.body
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                          api_body["apis"].each do |api2|
         | 
| 15 | 
            +
                            # 冗長なパスを排除
         | 
| 16 | 
            +
                            path = api2["path"].gsub(/^#{Swagger::Shell.config_api.ignore_top_url}/, "")
         | 
| 17 | 
            +
                            path_keys = path.split("/").reject {|s| s == "" }.tap {|p| p.last.gsub!(".json", "") }
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                            root_api.add_api(path_keys, api2["operations"].first["method"])
         | 
| 20 | 
            +
                          end
         | 
| 21 | 
            +
                        end
         | 
| 22 | 
            +
                      elsif swagger_version == "2.0"
         | 
| 23 | 
            +
                        api_docs["paths"].each do |path, methods|
         | 
| 24 | 
            +
                          methods.each do |method, api_info|
         | 
| 25 | 
            +
                            # TODO: ignore path
         | 
| 26 | 
            +
                            path_keys = path.split("/").reject {|s| s == "" } # TODO: format // .tap {|p| p.last.gsub!(".json", "") }
         | 
| 27 | 
            +
                            root_api.add_api(path_keys, method, api_info: api_info)
         | 
| 28 | 
            +
                          end
         | 
| 29 | 
            +
                        end
         | 
| 30 | 
            +
                      end
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
            end
         | 
| @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            require "pry"
         | 
| 2 | 
            +
            require "json"
         | 
| 3 | 
            +
            require "faraday"
         | 
| 4 | 
            +
            require "fileutils"
         | 
| 5 | 
            +
            require "yaml"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module Swagger
         | 
| 8 | 
            +
              module Shell
         | 
| 9 | 
            +
                module Interface
         | 
| 10 | 
            +
                  def start_shell
         | 
| 11 | 
            +
                    Pry.config.prompt_name = Swagger::Shell.config_pry.prompt_name || "swagger-shell"
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    FileUtils.mkdir_p(Swagger::Shell.config_pry.home)
         | 
| 14 | 
            +
                    Pry.config.history.file = Swagger::Shell.config_pry.history_path || "~/.swagger-shell/history"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    bootstrap
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                    Pry.history.load
         | 
| 19 | 
            +
                    Pry.start
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def api
         | 
| 23 | 
            +
                    Swagger::Shell.api
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def user
         | 
| 27 | 
            +
                    Swagger::Shell.user
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  def bootstrap
         | 
| 31 | 
            +
                    user.load_sample
         | 
| 32 | 
            +
                    begin
         | 
| 33 | 
            +
                      if user.info.nil?
         | 
| 34 | 
            +
                        user.create
         | 
| 35 | 
            +
                        puts "create user_id: #{user.id}"
         | 
| 36 | 
            +
                      else
         | 
| 37 | 
            +
                        user.login
         | 
| 38 | 
            +
                        puts "load user_id: #{user.id}"
         | 
| 39 | 
            +
                      end
         | 
| 40 | 
            +
                    rescue
         | 
| 41 | 
            +
                      puts "failed load user_id: #{user.id}"
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  # output API list
         | 
| 46 | 
            +
                  #
         | 
| 47 | 
            +
                  # option # TODO: implement
         | 
| 48 | 
            +
                  # p: output parameter name
         | 
| 49 | 
            +
                  # s: output summary
         | 
| 50 | 
            +
                  #
         | 
| 51 | 
            +
                  # no option output summary.
         | 
| 52 | 
            +
                  #
         | 
| 53 | 
            +
                  # e.g.:
         | 
| 54 | 
            +
                  # swagger-shell(main)> apis :p
         | 
| 55 | 
            +
                  def apis(option = "")
         | 
| 56 | 
            +
                    option = option.to_s
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                    with_parameter = option.include?("p")
         | 
| 59 | 
            +
                    with_summary = option.include?("s") || option.size.zero?
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                    api_list = api.api_list
         | 
| 62 | 
            +
                    max_key_size = api_list.keys.map(&:size).max
         | 
| 63 | 
            +
                    api_list.sort.each do |api, operation|
         | 
| 64 | 
            +
                      output = "#{api}#{" " * (max_key_size - api.size)}"
         | 
| 65 | 
            +
                      output += " # #{(operation["parameters"] || []).map {|p| p["name"][8..-2] }.join(" ")}" if with_parameter
         | 
| 66 | 
            +
                      output += " # #{operation["summary"]}" if with_summary
         | 
| 67 | 
            +
                      puts output
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
                    nil
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
            end
         | 
| @@ -0,0 +1,63 @@ | |
| 1 | 
            +
            module Swagger
         | 
| 2 | 
            +
              module Shell
         | 
| 3 | 
            +
                class User
         | 
| 4 | 
            +
                  attr_reader :id, :info
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def load_sample
         | 
| 7 | 
            +
                    id = list.sample
         | 
| 8 | 
            +
                    return if id.nil?
         | 
| 9 | 
            +
                    load_by(id)
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def load_by(id)
         | 
| 13 | 
            +
                    @id = id
         | 
| 14 | 
            +
                    @info = YAML.load_file("#{users_path}/#{Swagger::Shell.env}.#{@id}.yml")
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def list
         | 
| 18 | 
            +
                    Dir.glob("#{users_path}/#{Swagger::Shell.env}.*.yml").map {|f| File.basename(f, ".yml").gsub(/^#{Swagger::Shell.env}\./, "") }
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  def clean!
         | 
| 22 | 
            +
                    Dir.glob("#{users_path}/#{Swagger::Shell.env}.*.yml") {|f| File.delete f }
         | 
| 23 | 
            +
                    @info = nil
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def save(id, info)
         | 
| 27 | 
            +
                    @id = id
         | 
| 28 | 
            +
                    @info = info
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                    save_to_yml(@id, @info)
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def create
         | 
| 34 | 
            +
                    # need to override
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  def login
         | 
| 38 | 
            +
                    # need to override
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  # patch
         | 
| 42 | 
            +
                  def debug
         | 
| 43 | 
            +
                    command = "open #{Swagger::Shell.config_env.debug_url}/#{id}"
         | 
| 44 | 
            +
                    puts command
         | 
| 45 | 
            +
                    `#{command}`
         | 
| 46 | 
            +
                    nil
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  private
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  def save_to_yml(filename, data)
         | 
| 52 | 
            +
                    FileUtils.mkdir_p(users_path)
         | 
| 53 | 
            +
                    open("#{users_path}/#{Swagger::Shell.env}.#{filename}.yml","w") do |f|
         | 
| 54 | 
            +
                      YAML.dump(data, f)
         | 
| 55 | 
            +
                    end
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  def users_path
         | 
| 59 | 
            +
                    Swagger::Shell.config_pry.users_path
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
            end
         | 
| @@ -0,0 +1,70 @@ | |
| 1 | 
            +
            require "swagger/shell/api_struct"
         | 
| 2 | 
            +
            require "swagger/shell/doc_loader"
         | 
| 3 | 
            +
            require "swagger/shell/interface"
         | 
| 4 | 
            +
            require "swagger/shell/user"
         | 
| 5 | 
            +
            require "swagger/shell/version"
         | 
| 6 | 
            +
            require "json"
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            module Swagger
         | 
| 9 | 
            +
              module Shell
         | 
| 10 | 
            +
                class << self
         | 
| 11 | 
            +
                  def env=(env)
         | 
| 12 | 
            +
                    @env = env
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def env
         | 
| 16 | 
            +
                    @env
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  def config_env
         | 
| 20 | 
            +
                    @config_env ||= hash_to_struct(YAML.load_file("config/env.yml")[env.to_s]).tap do |config|  # TODO: pass outside
         | 
| 21 | 
            +
                      raise "not exist env: #{env}" if config.nil?
         | 
| 22 | 
            +
                      config.docs_url = File.join(config.api_url, config.docs_url) unless config.docs_url.start_with? "http"
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  def config_api
         | 
| 27 | 
            +
                    @config_api ||= hash_to_struct(YAML.load_file("config/swagger-shell.yml")["api"]).tap do |_config|  # TODO: pass outside
         | 
| 28 | 
            +
                      # noting to do
         | 
| 29 | 
            +
                    end
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  def config_pry
         | 
| 33 | 
            +
                    @config_local ||= hash_to_struct(YAML.load_file("config/swagger-shell.yml")["pry"]).tap do |config| # TODO: pass outside
         | 
| 34 | 
            +
                      config.home = config.home.gsub(/^~/, Dir.home) if config.home.start_with?("~/")
         | 
| 35 | 
            +
                      config.history_path = File.join(config.home, config.history_file)
         | 
| 36 | 
            +
                      config.users_path = File.join(config.home, config.users_file)
         | 
| 37 | 
            +
                    end
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def user
         | 
| 41 | 
            +
                    @user ||= User.new
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  def api
         | 
| 45 | 
            +
                    @aip ||= DocLoader.new.load(config_env.docs_url)
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  def registered_interfaces
         | 
| 49 | 
            +
                    @registered_interfaces ||= []
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  def register_interface(interface_module)
         | 
| 53 | 
            +
                    registered_interfaces << interface_module
         | 
| 54 | 
            +
                  end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  def start(main, env = nil)
         | 
| 57 | 
            +
                    self.env = env || :default
         | 
| 58 | 
            +
                    main.extend Swagger::Shell::Interface
         | 
| 59 | 
            +
                    registered_interfaces.each do |interface|
         | 
| 60 | 
            +
                      main.extend interface
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
                    main.start_shell
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  def hash_to_struct(hash)
         | 
| 66 | 
            +
                    JSON.parse hash.to_json, object_class: OpenStruct
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            lib = File.expand_path("../lib", __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require "swagger/shell/version"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "swagger-shell"
         | 
| 8 | 
            +
              spec.version       = Swagger::Shell::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Junya Tokumori"]
         | 
| 10 | 
            +
              spec.email         = ["rimokuto@gmail.com"]
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              spec.summary       = "swagger-shell"
         | 
| 13 | 
            +
              spec.description   = "shell cli for swagger"
         | 
| 14 | 
            +
              spec.homepage      = "https://github.com/rimokuto/swagger-shell"
         | 
| 15 | 
            +
              spec.license       = "MIT"
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              # Specify which files should be added to the gem when it is released.
         | 
| 18 | 
            +
              # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
         | 
| 19 | 
            +
              spec.files         = Dir.chdir(File.expand_path('..', __FILE__)) do
         | 
| 20 | 
            +
                `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
              spec.bindir        = "exe"
         | 
| 23 | 
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 24 | 
            +
              spec.require_paths = ["lib"]
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              spec.add_dependency "faraday", "~> 0.10" # TODO: net/http
         | 
| 27 | 
            +
              spec.add_dependency "parallel", "~> 1.12"
         | 
| 28 | 
            +
              spec.add_dependency "pry", "~> 0.11"
         | 
| 29 | 
            +
              spec.add_dependency "rb-readline", "~> 0.5" # TODO: if possible to delete
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              # spec.add_development_dependency "bundler", "~> 1.16"
         | 
| 32 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 33 | 
            +
              spec.add_development_dependency "rspec", "~> 3.0"
         | 
| 34 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,147 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: swagger-shell
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Junya Tokumori
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2019-04-03 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: faraday
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '0.10'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '0.10'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: parallel
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '1.12'
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '1.12'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: pry
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0.11'
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0.11'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: rb-readline
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - "~>"
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0.5'
         | 
| 62 | 
            +
              type: :runtime
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - "~>"
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0.5'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: rake
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - "~>"
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '10.0'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - "~>"
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '10.0'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: rspec
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - "~>"
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '3.0'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - "~>"
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '3.0'
         | 
| 97 | 
            +
            description: shell cli for swagger
         | 
| 98 | 
            +
            email:
         | 
| 99 | 
            +
            - rimokuto@gmail.com
         | 
| 100 | 
            +
            executables: []
         | 
| 101 | 
            +
            extensions: []
         | 
| 102 | 
            +
            extra_rdoc_files: []
         | 
| 103 | 
            +
            files:
         | 
| 104 | 
            +
            - ".gitignore"
         | 
| 105 | 
            +
            - ".rspec"
         | 
| 106 | 
            +
            - ".travis.yml"
         | 
| 107 | 
            +
            - Gemfile
         | 
| 108 | 
            +
            - Gemfile.lock
         | 
| 109 | 
            +
            - README.md
         | 
| 110 | 
            +
            - Rakefile
         | 
| 111 | 
            +
            - bin/console
         | 
| 112 | 
            +
            - bin/setup
         | 
| 113 | 
            +
            - bin/swagger-shell
         | 
| 114 | 
            +
            - config/env.yml
         | 
| 115 | 
            +
            - config/swagger-shell.yml
         | 
| 116 | 
            +
            - lib/swagger/shell.rb
         | 
| 117 | 
            +
            - lib/swagger/shell/api_struct.rb
         | 
| 118 | 
            +
            - lib/swagger/shell/doc_loader.rb
         | 
| 119 | 
            +
            - lib/swagger/shell/interface.rb
         | 
| 120 | 
            +
            - lib/swagger/shell/user.rb
         | 
| 121 | 
            +
            - lib/swagger/shell/version.rb
         | 
| 122 | 
            +
            - swagger-shell.gemspec
         | 
| 123 | 
            +
            homepage: https://github.com/rimokuto/swagger-shell
         | 
| 124 | 
            +
            licenses:
         | 
| 125 | 
            +
            - MIT
         | 
| 126 | 
            +
            metadata: {}
         | 
| 127 | 
            +
            post_install_message: 
         | 
| 128 | 
            +
            rdoc_options: []
         | 
| 129 | 
            +
            require_paths:
         | 
| 130 | 
            +
            - lib
         | 
| 131 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 132 | 
            +
              requirements:
         | 
| 133 | 
            +
              - - ">="
         | 
| 134 | 
            +
                - !ruby/object:Gem::Version
         | 
| 135 | 
            +
                  version: '0'
         | 
| 136 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 137 | 
            +
              requirements:
         | 
| 138 | 
            +
              - - ">="
         | 
| 139 | 
            +
                - !ruby/object:Gem::Version
         | 
| 140 | 
            +
                  version: '0'
         | 
| 141 | 
            +
            requirements: []
         | 
| 142 | 
            +
            rubyforge_project: 
         | 
| 143 | 
            +
            rubygems_version: 2.4.5.5
         | 
| 144 | 
            +
            signing_key: 
         | 
| 145 | 
            +
            specification_version: 4
         | 
| 146 | 
            +
            summary: swagger-shell
         | 
| 147 | 
            +
            test_files: []
         |