swagger-shell 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: e597c90a4b76d100bc2b694fb7d389346bb71a4a
4
- data.tar.gz: c41111166cd641a11160ea6d36e9125ee4955af7
3
+ metadata.gz: 1bd6ce946b0365ed91e0ca911f5d9d4436b0ece7
4
+ data.tar.gz: 25bbe6155712671baa6d4b83cdc23a6d166722f2
5
5
  SHA512:
6
- metadata.gz: 532e20ab70c63eae78e26ecc26936ccd481b50f1cae09275e25f99123ade51bf507108c2947e0148e44d89e283328cc86903d3e933daaedcd908f95d5dd61ddf
7
- data.tar.gz: e82eb55767a67935952862495cdd6fcb42595124a18f12c250b2de7ad7553eec60325d482636eadd3dad6498cf11c31a663624b56e5683b9eb04cfea7c28ff6e
6
+ metadata.gz: ee5ed7bfc54c02a84486617a94e68910f4de050bffabcfe02c834677cf15210e41f5edc9983b5ccadb224fe0d362e25283774150a6e0aff9be31c7d67c73f56e
7
+ data.tar.gz: ea4d05d4e6a0f5ca2e0719621511af783156456574e4dd30e882944f29ea710d40d688f7d8245524cf05cbeb9b37f639079594445b3ee23ed3fa13fbee278281
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- swagger-shell (0.0.1)
4
+ swagger-shell (0.0.2)
5
5
  faraday (~> 0.10)
6
6
  parallel (~> 1.12)
7
7
  pry (~> 0.11)
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 env
16
- @env
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 ||= 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_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 ||= hash_to_struct(YAML.load_file("config/swagger-shell.yml")["api"]).tap do |_config| # TODO: pass outside
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
- @config_local ||= hash_to_struct(YAML.load_file("config/swagger-shell.yml")["pry"]).tap do |config| # TODO: pass outside
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: nil)
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 |api_method|
59
- hash[api_method] = ""
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
- root_api.add_api(path_keys, api2["operations"].first["method"])
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, api_info: api_info)
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 # TODO: implement
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 :p
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
- 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
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
@@ -6,10 +6,10 @@ module Swagger
6
6
  def load_sample
7
7
  id = list.sample
8
8
  return if id.nil?
9
- load_by(id)
9
+ load(id)
10
10
  end
11
11
 
12
- def load_by(id)
12
+ def load(id)
13
13
  @id = id
14
14
  @info = YAML.load_file("#{users_path}/#{Swagger::Shell.env}.#{@id}.yml")
15
15
  end
@@ -1,5 +1,5 @@
1
1
  module Swagger
2
2
  module Shell
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
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.1
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-03 00:00:00.000000000 Z
11
+ date: 2019-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday