Skip to content

Commit

Permalink
added silent option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario.RuizSanchez committed Sep 27, 2019
1 parent 614ecfd commit 9bc6855
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ In case no options supplied:
-f, --create_files It will create a file per module
-T, --tags_module It will be used the tags key to create the module name
-F, --fixed_module all the requests will be under the module Requests
-s, --silent It will display only errors
```


Expand Down
4 changes: 4 additions & 0 deletions bin/open_api_import
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ optparse = OptionParser.new do |opts|
options[:name_for_module] = :fixed
end

opts.on("-s", "--silent", "It will display only errors") do
options[:name_for_module] = :fixed
end


end

Expand Down
11 changes: 6 additions & 5 deletions lib/open_api_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class OpenApiImport
# operation_id: it will be used the operationId field but using the snake_case version, for example for listUsers: list_users
# operationId: it will be used the operationId field like it is, for example: listUsers
# @param name_for_module [Symbol]. (:path, :path_file, :fixed, :tags, :tags_file) (default: :path). How the module names will be created.
# @param silent [Boolean]. (default: false) It will display only errors.
# path: It will be used the first folder of the path to create the module name, for example the path /users/list will be in the module Users and all the requests from all modules in the same file.
# path_file: It will be used the first folder of the path to create the module name, for example the path /users/list will be in the module Users and each module will be in a new requests file.
# tags: It will be used the tags key to create the module name, for example the tags: [users,list] will create the module UsersList and all the requests from all modules in the same file.
Expand All @@ -29,7 +30,7 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses
f = File.new("#{swagger_file}_open_api_import.log", "w")
f.sync = true
@logger = Logger.new f
puts "Logs file: #{swagger_file}_open_api_import.log"
puts "Logs file: #{swagger_file}_open_api_import.log" unless silent
rescue StandardError => e
warn "Not possible to create the Logger file"
warn e
Expand Down Expand Up @@ -559,7 +560,7 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses
File.open(requests_file_path, "w") { |file| file.write(output_txt) }
res_rufo = `rufo #{requests_file_path}`
message = "** Requests file: #{swagger_file}.rb that contains the code of the requests after importing the Swagger file"
puts message
puts message unless silent
@logger.info message
@logger.error " Error formating with rufo" unless res_rufo.to_s.match?(/\AFormat:.+$\s*\z/)
@logger.error " Syntax Error: #{`ruby -c #{requests_file_path}`}" unless `ruby -c #{requests_file_path}`.include?("Syntax OK")
Expand All @@ -571,7 +572,7 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses

requires_txt = ""
message = "** Generated files that contain the code of the requests after importing the Swagger file: "
puts message
puts message unless silent
@logger.info message
files.each do |mod, out_mod|
output = output_header + out_mod + output_footer
Expand All @@ -581,7 +582,7 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses
File.open(requests_file_path, "w") { |file| file.write(output_txt) }
res_rufo = `rufo #{requests_file_path}`
message = " - #{requests_file_path}"
puts message
puts message unless silent
@logger.info message
@logger.error " Error formating with rufo" unless res_rufo.to_s.match?(/\AFormat:.+$\s*\z/)
@logger.error " Syntax Error: #{`ruby -c #{requests_file_path}`}" unless `ruby -c #{requests_file_path}`.include?("Syntax OK")
Expand All @@ -592,7 +593,7 @@ def self.from(swagger_file, create_method_name: :operation_id, include_responses
res_rufo = `rufo #{requests_file_path}`
message = "** File that contains all the requires for all Request files: \n"
message += " - #{requests_file_path} "
puts message
puts message unless silent
@logger.info message
@logger.error " Error formating with rufo" unless res_rufo.to_s.match?(/\AFormat:.+$\s*\z/)
@logger.error " Syntax Error: #{`ruby -c #{requests_file_path}`}" unless `ruby -c #{requests_file_path}`.include?("Syntax OK")
Expand Down
4 changes: 2 additions & 2 deletions open_api_import.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'open_api_import'
s.version = '0.8.9'
s.version = '0.9.0'
s.summary = "OpenApiImport -- Import a Swagger or Open API file and create a Ruby Request Hash file including all requests and responses with all the examples. The file can be in JSON or YAML"
s.description = "OpenApiImport -- Import a Swagger or Open API file and create a Ruby Request Hash file including all requests and responses with all the examples. The file can be in JSON or YAML"
s.authors = ["Mario Ruiz"]
Expand All @@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.extra_rdoc_files = ["LICENSE","README.md"]
s.homepage = 'https://github.com/MarioRuiz/open_api_import'
s.license = 'MIT'
s.add_runtime_dependency 'oas_parser', '~> 0.19', '>= 0.19.0'
s.add_runtime_dependency 'oas_parser', '~> 0.22', '>= 0.22.2'
s.add_runtime_dependency 'rufo', '~> 0.7', '>= 0.7.0'
s.add_runtime_dependency 'nice_hash', '~> 1.15', '>= 1.15.3'
s.add_development_dependency 'rspec', '~> 3.8', '>= 3.8.0'
Expand Down

0 comments on commit 9bc6855

Please sign in to comment.