openapi_slicer 0.2.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8744fe9d1b6b20b35be818a6d72ce220dc842e88743e4316f29cb3f028782f4
4
- data.tar.gz: fb0b98678a68e967469c45d45037ed2e615f9d7c8abe243453fcc352ed7e76a7
3
+ metadata.gz: 06440de76c8b9af004855a5b38b2aa3b40e2c291a2b54ee016749f9a18cd8294
4
+ data.tar.gz: 653470d28f973a0d179ba731ba463599c1ba94d6c474b0075c4e49c2a8b2915c
5
5
  SHA512:
6
- metadata.gz: 23d23c70de64a90e318abf6f96eca542ebb5359e4b15a5e41f999341313285975ce12d23a3c51f34c88bf73106811e868dc69da0f3594f2fbc240d777b9855ac
7
- data.tar.gz: 1c3af05393b57aa18f718a2236da15d7df0ce2a5a3d8bb52700461b189307ef313024c3ea8cafa8854f4cc6873e73b3ccc624eff2102fbddb010014193681c91
6
+ metadata.gz: 3efadbe9b5d54e30785c587e97537d2891d7c20e54da8a3a97ca464a00b85d0fddbbdb926b05f844debb298757e04958d5d6587cc003cd44907696fd0b2c864e
7
+ data.tar.gz: 89713c336fca787c152bf998a79d6849a0650006a8b01e5837607506f44cf0d259bfcc155feb85ef51d8d0d36b685d25da73be57a49b9e9d892b57e7740e0d5c
@@ -9,19 +9,22 @@ require "set"
9
9
  # (schemas, parameters, etc.) are included.
10
10
  class OpenapiSlicer
11
11
  # The current version of the OpenapiSlicer
12
- VERSION = "0.2.1"
12
+ VERSION = "0.2.2"
13
13
 
14
14
  # @return [Hash] the OpenAPI specification loaded from the file
15
15
  attr_accessor :spec
16
+ attr_reader :prettify
16
17
 
17
18
  # Initializes the OpenapiSlicer.
18
19
  #
19
20
  # @param file_path [String] the path to the OpenAPI spec file (JSON or YAML)
21
+ # @param prettify [Boolean] (true) prettify JSON if true, otherwise compress JSON
20
22
  # @raise [RuntimeError] if the file is not a JSON or YAML file
21
- def initialize(file_path:)
23
+ def initialize(file_path:, prettify: true)
22
24
  raise "Invalid file type. Only JSON and YAML are supported." unless file_path.match?(/\.(json|ya?ml)$/)
23
25
 
24
26
  @file_path = file_path
27
+ @prettify = prettify
25
28
  @spec = load_spec(file_path)
26
29
  @components = {}
27
30
  @tags = Set.new
@@ -46,7 +49,7 @@ class OpenapiSlicer
46
49
  result = filter(regex)
47
50
  File.open(target_file, "w") do |f|
48
51
  if target_file.match?(/\.json$/)
49
- f.write(result.to_json)
52
+ f.write(prettify ? JSON.pretty_generate(result) : result.to_json)
50
53
  else
51
54
  f.write(result.to_yaml)
52
55
  end
@@ -40,6 +40,11 @@ class OpenapiSlicerCLI
40
40
  options[:output_file] = file
41
41
  end
42
42
 
43
+ opts.on("-p", "--prettify", "Prettify JS output") do |prettify|
44
+ options[:prettify] = prettify
45
+ end
46
+ options[:prettify] = true unless options.key?(:prettify)
47
+
43
48
  opts.on("-h", "--help", "Displays Help") do
44
49
  puts opts
45
50
  exit
@@ -65,7 +70,7 @@ class OpenapiSlicerCLI
65
70
  parse_options
66
71
  validate_options
67
72
 
68
- slicer = OpenapiSlicer.new(file_path: options[:input_file])
73
+ slicer = OpenapiSlicer.new(file_path: options[:input_file], prettify: options[:prettify])
69
74
  if options[:output_file]
70
75
  slicer.export(options[:regex], options[:output_file])
71
76
  puts "File created: #{options[:output_file]}"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_slicer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheScubaGeek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-01 00:00:00.000000000 Z
11
+ date: 2024-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wannabe_bool
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -56,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
70
  - !ruby/object:Gem::Version
57
71
  version: '0'
58
72
  requirements: []
59
- rubygems_version: 3.5.11
73
+ rubygems_version: 3.5.20
60
74
  signing_key:
61
75
  specification_version: 4
62
76
  summary: A tool to slice OpenAPI specs based on regular expressions