oas_rails 0.17.0 → 1.0.0

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: d60145b23d4b27b3fc5f1f58e024cb4ea0df37c6d10932d64b9bc5ce08641e83
4
- data.tar.gz: '099cce8d88c18549bded9eaa2e3f4b9176a1a934f2a511bb3d6af567c18822ed'
3
+ metadata.gz: d23aa895481ff8d0bd25e9d681dcc2bb5738b26306b78a9e76d9366959898e0b
4
+ data.tar.gz: f8160302249f30abd9959c11ce365b5ad5992f7b7b14c5a1ab1cba53ee0ababd
5
5
  SHA512:
6
- metadata.gz: 5bb4524c0f29f381c9e1fa3b351bbb5a860e05a71e83fa7298ec62b68a39f6a2b2a8c21057e1f0a262482d4e565be4e33ff79b490aff2539d074a98dc5506199
7
- data.tar.gz: 22f0679476e47e8e72a7fd77c68d944a75b68fd8b004c030676a84ab8a008433d17530d1a985b75ffdebb55ce56795bf7c14679d65ade303c65732ffe705dfec
6
+ metadata.gz: 2428433ef2f680ad3a0c7ec4a72b1eeaced918977fd5db5fa4919047784583e6cf7369d77091056817ee48cb1597922785c94e53b7ddf8fe00b0ea7d8ef848d4
7
+ data.tar.gz: b046fb2101c8f521c6d5e8b41eae979d363a311355a58dec5ccec6802e4ad4521b9c0f1a5186d525692a8c7df6d1ed1a50afcbc31c54b7bf5d661906d404a168
data/README.md CHANGED
@@ -23,7 +23,7 @@ Explore the interactive documentation live:
23
23
  <https://vimeo.com/1013687332>
24
24
  🎬
25
25
 
26
- ![Screenshot](https://a-chacon.com/assets/images/oas_rails_ui.png)
26
+ ![Screenshot](https://a-chacon.com/oas_core/assets/rails_theme.png)
27
27
 
28
28
  ## Related Projects
29
29
 
@@ -11,10 +11,7 @@ module OasRails
11
11
 
12
12
  def build
13
13
  OasCore::OasRoute.new(
14
- controller_class: controller_class,
15
- controller_action: controller_action,
16
14
  controller: controller,
17
- controller_path: controller_path,
18
15
  method_name: method,
19
16
  verb: verb,
20
17
  path: path,
@@ -30,18 +27,10 @@ module OasRails
30
27
  "#{@rails_route.defaults[:controller].camelize}Controller"
31
28
  end
32
29
 
33
- def controller_action
34
- "#{controller_class}##{@rails_route.defaults[:action]}"
35
- end
36
-
37
30
  def controller
38
31
  @rails_route.defaults[:controller]
39
32
  end
40
33
 
41
- def controller_path
42
- Rails.root.join("app/controllers/#{controller}_controller.rb").to_s
43
- end
44
-
45
34
  def method
46
35
  @rails_route.defaults[:action]
47
36
  end
@@ -1,6 +1,6 @@
1
1
  module OasRails
2
2
  class Configuration < OasCore::Configuration
3
- attr_accessor :autodiscover_request_body, :autodiscover_responses, :ignored_actions, :rapidoc_theme, :layout
3
+ attr_accessor :autodiscover_request_body, :autodiscover_responses, :ignored_actions, :rapidoc_theme, :layout, :source_oas_path
4
4
  attr_reader :route_extractor, :include_mode
5
5
 
6
6
  def initialize
@@ -12,12 +12,21 @@ module OasRails
12
12
  @ignored_actions = []
13
13
  @rapidoc_theme = :rails
14
14
  @layout = nil
15
+ @source_oas_path = nil
15
16
 
16
17
  # TODO: implement
17
18
  # autodiscover_request_body
18
19
  # autodiscover_responses
19
20
  end
20
21
 
22
+ def excluded_columns_incoming
23
+ %i[id created_at updated_at deleted_at]
24
+ end
25
+
26
+ def excluded_columns_outgoing
27
+ []
28
+ end
29
+
21
30
  def include_mode=(value)
22
31
  valid_modes = %i[all with_tags explicit]
23
32
  raise ArgumentError, "include_mode must be one of #{valid_modes}" unless valid_modes.include?(value)
@@ -66,7 +66,7 @@ module OasRails
66
66
  return false if RAILS_DEFAULT_CONTROLLERS.any? { |default| route.defaults[:controller].start_with?(default) }
67
67
  return false if RAILS_DEFAULT_PATHS.any? { |path| route.path.spec.to_s.include?(path) }
68
68
  return false unless route.path.spec.to_s.start_with?(OasRails.config.api_path)
69
- return false if ignore_custom_actions(route)
69
+ return false if ignore_custom_actions?(route)
70
70
 
71
71
  true
72
72
  end
@@ -99,7 +99,7 @@ module OasRails
99
99
  # Support controller name only to ignore all controller actions.
100
100
  # Support ignoring "controller#action"
101
101
  # Ignoring "controller#action" AND "api_path/controller#action"
102
- def ignore_custom_actions(route)
102
+ def ignore_custom_actions?(route)
103
103
  api_path = "#{OasRails.config.api_path.sub(%r{\A/}, '')}/".sub(%r{/+$}, '/')
104
104
  ignored_actions = OasRails.config.ignored_actions.flat_map do |custom_route|
105
105
  if custom_route.start_with?(api_path)
@@ -1,3 +1,3 @@
1
1
  module OasRails
2
- VERSION = "0.17.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/oas_rails.rb CHANGED
@@ -34,9 +34,9 @@ module OasRails
34
34
  OasCore.config = config
35
35
 
36
36
  host_routes = Extractors::RouteExtractor.host_routes
37
- oas = OasCore::Builders::SpecificationBuilder.new.with_oas_routes(host_routes).build
37
+ oas_source = config.source_oas_path ? read_source_oas_file : {}
38
38
 
39
- oas.to_spec
39
+ OasCore.build(host_routes, oas_source: oas_source)
40
40
  end
41
41
 
42
42
  def configure
@@ -47,11 +47,22 @@ module OasRails
47
47
  @config ||= Configuration.new
48
48
  end
49
49
 
50
+ private
51
+
50
52
  def clear_cache
51
53
  return if Rails.env.production?
52
54
 
53
55
  MethodSource.clear_cache
54
56
  OasRails::Extractors::RouteExtractor.clear_cache
55
57
  end
58
+
59
+ def read_source_oas_file
60
+ file_path = Rails.root.join(config.source_oas_path)
61
+ JSON.parse(File.read(file_path), symbolize_names: true)
62
+ rescue Errno::ENOENT => e
63
+ raise "Failed to read source OAS file at #{file_path}: #{e.message}"
64
+ rescue JSON::ParserError => e
65
+ raise "Failed to parse source OAS file at #{file_path}: #{e.message}"
66
+ end
56
67
  end
57
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oas_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - a-chacon
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.4.0
32
+ version: 1.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.4.0
39
+ version: 1.0.0
40
40
  description: OasRails is a Rails engine for generating automatic interactive documentation
41
41
  for your Rails APIs. It generates an OAS 3.1 document and displays it using RapiDoc.
42
42
  email: