swagger-shell 0.0.1 → 0.0.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/swagger/shell.rb +9 -10
- data/lib/swagger/shell/api_struct.rb +12 -6
- data/lib/swagger/shell/doc_loader.rb +10 -2
- data/lib/swagger/shell/interface.rb +9 -7
- data/lib/swagger/shell/user.rb +2 -2
- data/lib/swagger/shell/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1bd6ce946b0365ed91e0ca911f5d9d4436b0ece7
         | 
| 4 | 
            +
              data.tar.gz: 25bbe6155712671baa6d4b83cdc23a6d166722f2
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ee5ed7bfc54c02a84486617a94e68910f4de050bffabcfe02c834677cf15210e41f5edc9983b5ccadb224fe0d362e25283774150a6e0aff9be31c7d67c73f56e
         | 
| 7 | 
            +
              data.tar.gz: ea4d05d4e6a0f5ca2e0719621511af783156456574e4dd30e882944f29ea710d40d688f7d8245524cf05cbeb9b37f639079594445b3ee23ed3fa13fbee278281
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/swagger/shell.rb
    CHANGED
    
    | @@ -8,29 +8,28 @@ require "json" | |
| 8 8 | 
             
            module Swagger
         | 
| 9 9 | 
             
              module Shell
         | 
| 10 10 | 
             
                class << self
         | 
| 11 | 
            +
                  attr_reader :env, :config_api, :config_pry
         | 
| 12 | 
            +
             | 
| 11 13 | 
             
                  def env=(env)
         | 
| 12 14 | 
             
                    @env = env
         | 
| 13 15 | 
             
                  end
         | 
| 14 16 |  | 
| 15 | 
            -
                  def  | 
| 16 | 
            -
                    @ | 
| 17 | 
            +
                  def config_env=(config)
         | 
| 18 | 
            +
                    @config_env_store = hash_to_struct(config)
         | 
| 17 19 | 
             
                  end
         | 
| 18 20 |  | 
| 19 21 | 
             
                  def config_env
         | 
| 20 | 
            -
                    @config_env ||=  | 
| 21 | 
            -
                      raise "not exist env: #{env}" if config.nil?
         | 
| 22 | 
            +
                    @config_env ||= @config_env_store[env].tap do |config|
         | 
| 22 23 | 
             
                      config.docs_url = File.join(config.api_url, config.docs_url) unless config.docs_url.start_with? "http"
         | 
| 23 24 | 
             
                    end
         | 
| 24 25 | 
             
                  end
         | 
| 25 26 |  | 
| 26 | 
            -
                  def config_api
         | 
| 27 | 
            -
                    @config_api  | 
| 28 | 
            -
                      # noting to do
         | 
| 29 | 
            -
                    end
         | 
| 27 | 
            +
                  def config_api=(config)
         | 
| 28 | 
            +
                    @config_api = hash_to_struct(config)
         | 
| 30 29 | 
             
                  end
         | 
| 31 30 |  | 
| 32 | 
            -
                  def config_pry
         | 
| 33 | 
            -
                    @ | 
| 31 | 
            +
                  def config_pry=(config)
         | 
| 32 | 
            +
                    @config_pry = hash_to_struct(config).tap do |config|
         | 
| 34 33 | 
             
                      config.home = config.home.gsub(/^~/, Dir.home) if config.home.start_with?("~/")
         | 
| 35 34 | 
             
                      config.history_path = File.join(config.home, config.history_file)
         | 
| 36 35 | 
             
                      config.users_path = File.join(config.home, config.users_file)
         | 
| @@ -1,24 +1,28 @@ | |
| 1 1 | 
             
            module Swagger
         | 
| 2 2 | 
             
              module Shell
         | 
| 3 3 | 
             
                module ApiGet
         | 
| 4 | 
            +
                  attr_accessor :get_api_info
         | 
| 4 5 | 
             
                  def get(message = {})
         | 
| 5 6 | 
             
                    _get(api_url, message)
         | 
| 6 7 | 
             
                  end
         | 
| 7 8 | 
             
                end
         | 
| 8 9 |  | 
| 9 10 | 
             
                module ApiPost
         | 
| 11 | 
            +
                  attr_accessor :post_api_info
         | 
| 10 12 | 
             
                  def post(message = {})
         | 
| 11 13 | 
             
                    _post(api_url, message)
         | 
| 12 14 | 
             
                  end
         | 
| 13 15 | 
             
                end
         | 
| 14 16 |  | 
| 15 17 | 
             
                module ApiPut
         | 
| 18 | 
            +
                  attr_accessor :put_api_info
         | 
| 16 19 | 
             
                  def put(message = {})
         | 
| 17 20 | 
             
                    _put(api_url, message)
         | 
| 18 21 | 
             
                  end
         | 
| 19 22 | 
             
                end
         | 
| 20 23 |  | 
| 21 24 | 
             
                module ApiDelete
         | 
| 25 | 
            +
                  attr_accessor :delete_api_info
         | 
| 22 26 | 
             
                  def delete(message = {})
         | 
| 23 27 | 
             
                    _delete(api_url, message)
         | 
| 24 28 | 
             
                  end
         | 
| @@ -45,9 +49,9 @@ module Swagger | |
| 45 49 | 
             
                    root? ? "api" : @key
         | 
| 46 50 | 
             
                  end
         | 
| 47 51 |  | 
| 48 | 
            -
                  def add_api(path_keys, method, api_info | 
| 52 | 
            +
                  def add_api(path_keys, method, api_info = nil)
         | 
| 49 53 | 
             
                    find_or_create_api_struct(path_keys).tap do |api_struct|
         | 
| 50 | 
            -
                      api_struct.add_api_module(method) if api_struct
         | 
| 54 | 
            +
                      api_struct.add_api_module(method, api_info) if api_struct
         | 
| 51 55 | 
             
                    end
         | 
| 52 56 | 
             
                  end
         | 
| 53 57 |  | 
| @@ -55,8 +59,8 @@ module Swagger | |
| 55 59 | 
             
                    @children.each_with_object({}) do |key, hash|
         | 
| 56 60 | 
             
                      hash.merge!(instance_variable_get("@#{key}").api_list)
         | 
| 57 61 | 
             
                    end.tap do |hash|
         | 
| 58 | 
            -
                      api_methods.each do | | 
| 59 | 
            -
                        hash[ | 
| 62 | 
            +
                      api_methods.each do |method|
         | 
| 63 | 
            +
                        hash[(api_ancestors.map(&:method_key) << method).join(".")] = send("#{method}_api_info")
         | 
| 60 64 | 
             
                      end
         | 
| 61 65 | 
             
                    end
         | 
| 62 66 | 
             
                  end
         | 
| @@ -68,7 +72,8 @@ module Swagger | |
| 68 72 |  | 
| 69 73 | 
             
                  def api_methods
         | 
| 70 74 | 
             
                    %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)
         | 
| 75 | 
            +
                      # (api_ancestors.map(&:method_key) << method).join(".") if singleton_class.include? self.class.module_class(method)
         | 
| 76 | 
            +
                      method if singleton_class.include? self.class.module_class(method)
         | 
| 72 77 | 
             
                    end.compact
         | 
| 73 78 | 
             
                  end
         | 
| 74 79 |  | 
| @@ -80,8 +85,9 @@ module Swagger | |
| 80 85 | 
             
                    end.reverse
         | 
| 81 86 | 
             
                  end
         | 
| 82 87 |  | 
| 83 | 
            -
                  def add_api_module(method)
         | 
| 88 | 
            +
                  def add_api_module(method, api_info)
         | 
| 84 89 | 
             
                    extend self.class.module_class(method)
         | 
| 90 | 
            +
                    send("#{method}_api_info=", api_info)
         | 
| 85 91 | 
             
                  end
         | 
| 86 92 |  | 
| 87 93 | 
             
                  def child(path_key)
         | 
| @@ -16,7 +16,15 @@ module Swagger | |
| 16 16 | 
             
                            path = api2["path"].gsub(/^#{Swagger::Shell.config_api.ignore_top_url}/, "")
         | 
| 17 17 | 
             
                            path_keys = path.split("/").reject {|s| s == "" }.tap {|p| p.last.gsub!(".json", "") }
         | 
| 18 18 |  | 
| 19 | 
            -
                             | 
| 19 | 
            +
                            info = api2["operations"].first
         | 
| 20 | 
            +
                            api_info = OpenStruct.new(
         | 
| 21 | 
            +
                              summary: info["summary"],
         | 
| 22 | 
            +
                              notes: info["notes"],
         | 
| 23 | 
            +
                              parameters: info["parameters"],
         | 
| 24 | 
            +
                              response_messages: info["responseMessages"],
         | 
| 25 | 
            +
                              nickname: info["nickname"],
         | 
| 26 | 
            +
                            )
         | 
| 27 | 
            +
                            root_api.add_api(path_keys, info["method"], api_info)
         | 
| 20 28 | 
             
                          end
         | 
| 21 29 | 
             
                        end
         | 
| 22 30 | 
             
                      elsif swagger_version == "2.0"
         | 
| @@ -24,7 +32,7 @@ module Swagger | |
| 24 32 | 
             
                          methods.each do |method, api_info|
         | 
| 25 33 | 
             
                            # TODO: ignore path
         | 
| 26 34 | 
             
                            path_keys = path.split("/").reject {|s| s == "" } # TODO: format // .tap {|p| p.last.gsub!(".json", "") }
         | 
| 27 | 
            -
                            root_api.add_api(path_keys, method | 
| 35 | 
            +
                            root_api.add_api(path_keys, method) # TODO: api_info
         | 
| 28 36 | 
             
                          end
         | 
| 29 37 | 
             
                        end
         | 
| 30 38 | 
             
                      end
         | 
| @@ -44,15 +44,15 @@ module Swagger | |
| 44 44 |  | 
| 45 45 | 
             
                  # output API list
         | 
| 46 46 | 
             
                  #
         | 
| 47 | 
            -
                  # option | 
| 47 | 
            +
                  # option
         | 
| 48 48 | 
             
                  # p: output parameter name
         | 
| 49 49 | 
             
                  # s: output summary
         | 
| 50 50 | 
             
                  #
         | 
| 51 51 | 
             
                  # no option output summary.
         | 
| 52 52 | 
             
                  #
         | 
| 53 53 | 
             
                  # e.g.:
         | 
| 54 | 
            -
                  # swagger-shell(main)> apis : | 
| 55 | 
            -
                  def apis(option =  | 
| 54 | 
            +
                  # swagger-shell(main)> apis :ps
         | 
| 55 | 
            +
                  def apis(option = :ps)
         | 
| 56 56 | 
             
                    option = option.to_s
         | 
| 57 57 |  | 
| 58 58 | 
             
                    with_parameter = option.include?("p")
         | 
| @@ -61,11 +61,13 @@ module Swagger | |
| 61 61 | 
             
                    api_list = api.api_list
         | 
| 62 62 | 
             
                    max_key_size = api_list.keys.map(&:size).max
         | 
| 63 63 | 
             
                    api_list.sort.each do |api, operation|
         | 
| 64 | 
            -
                       | 
| 65 | 
            -
                       | 
| 66 | 
            -
                       | 
| 67 | 
            -
             | 
| 64 | 
            +
                      comments = []
         | 
| 65 | 
            +
                      comments << operation.summary if with_summary
         | 
| 66 | 
            +
                      comments << "(#{(operation.parameters || []).map {|p| p["name"][8..-2] }.map {|n| "#{n}:" }.join(", ")})" if with_parameter
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                      puts "#{api}#{" " * (max_key_size - api.size)} # #{comments.join(" ")}"
         | 
| 68 69 | 
             
                    end
         | 
| 70 | 
            +
             | 
| 69 71 | 
             
                    nil
         | 
| 70 72 | 
             
                  end
         | 
| 71 73 | 
             
                end
         | 
    
        data/lib/swagger/shell/user.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: swagger-shell
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Junya Tokumori
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2019-04- | 
| 11 | 
            +
            date: 2019-04-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faraday
         |