oas_rails 0.6.0 → 0.8.0

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
  SHA256:
3
- metadata.gz: 1f833de18481bb481d9f698a2f10a3b7f1a1512623cd335932659736f94b2161
4
- data.tar.gz: 343243f10ae846b8eb42ca75cdd3d69332fe19b41192959bb355603fa2148242
3
+ metadata.gz: 9f6ca8d23d3c1444692414da580ff981df420ae1777b683c47a95fa4e8eb49da
4
+ data.tar.gz: c4dabc58b9f2b3eaf7cf3fd67cd6fd1a983804b69362453145c1bfd61c478e46
5
5
  SHA512:
6
- metadata.gz: 3e41ce594245affa26d85f05bba1fbdb1b6dacbb1d112c42aaa63c0837654a56d4afdd9eb442bc7000f3ceda90fb254aea5712a5e2d3aeff58d1505d869957a3
7
- data.tar.gz: 1be4b42da76e635d82ee95f663ea9ca950873b2c6037779598cfa0c284076a022a05aaeb772dd66f5a08b76bedbac7be3ac27453db0a07a4be8e7e0b3213bca9
6
+ metadata.gz: f582e886f520f48e82a4fa82b68ab24002be9abfcc62a616590d6ed6bf08206f85330e6567d100c4bec543085bcff26c7b7ddf6aea84324335e59b2a6cdaf81c
7
+ data.tar.gz: 28230b3cf7afd61cf6bb0bad6c8cd7211ed8e388d95d81ba301166b1bded8759549fb9404938d47b73d1703323bf5db82b567ea8dc042146b74df4a6b7b17bff
data/README.md CHANGED
@@ -107,6 +107,7 @@ Then fill it with your data. Below are the available configuration options:
107
107
  - `config.autodiscover_request_body`: Automatically detects request bodies for create/update methods. Default is `true`.
108
108
  - `config.autodiscover_responses`: Automatically detects responses from controller renders. Default is `true`.
109
109
  - `config.api_path`: Sets the API path if your API is under a different namespace.
110
+ - `config.ignored_actions`: Sets an array with the controller or controller#action. No necessary to add api_path before.
110
111
 
111
112
  ### Authentication Settings
112
113
 
@@ -164,13 +165,13 @@ Documents the request body needed by the endpoint. The structure is optional if
164
165
 
165
166
  **Example**:
166
167
 
167
- `# @request_body The user to be created [!Hash{user: {name: String, age: Integer, password: String}}]`
168
+ `# @request_body The user to be created [!Hash{user: Hash{name: String, age: Integer, password: String}}]`
168
169
 
169
170
  `# @request_body The user to be created [!User]`
170
171
 
171
172
  `# @request_body The user to be created [User]`
172
173
 
173
- `# @request_body The user to be created [!Hash{user: {name: String, age: Integer, password: String, surnames: Array<String>, coords: Hash{lat: String, lng: String}}}]`
174
+ `# @request_body The user to be created [!Hash{user: Hash{name: String, age: Integer, password: String, surnames: Array<String>, coords: Hash{lat: String, lng: String}}}]`
174
175
 
175
176
  </details>
176
177
 
@@ -1,10 +1,11 @@
1
1
  module OasRails
2
2
  class OasRailsController < ApplicationController
3
- layout false
3
+ # Include URL help if the layout is a user-customized layout.
4
+ include Rails.application.routes.url_helpers
4
5
 
5
6
  def index
6
7
  respond_to do |format|
7
- format.html
8
+ format.html { render "index", layout: OasRails.config.layout }
8
9
  format.json do
9
10
  render json: OasRails.build.to_json, status: :ok
10
11
  end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= OasRails.config.info.title %></title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+ <meta charset="utf-8">
8
+ <!-- Important: rapi-doc uses utf8 characters -->
9
+ </head>
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -1,27 +1,15 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Oas rails</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
- <meta charset="utf-8">
8
- <!-- Important: rapi-doc uses utf8 characters -->
9
- <script type="module" src="https://unpkg.com/rapidoc/dist/rapidoc-min.js"></script>
10
- </head>
11
- <body>
12
- <rapi-doc
13
- spec-url = "<%= OasRails::Engine.routes.find_script_name({}) %>.json"
14
- theme = "dark"
15
- bg-color="#0F172A"
16
- text-color= "#f7f7f7"
17
- show-header = 'false'
18
- primary-color = "#2de410"
19
- font-size="largest"
20
- show-method-in-nav-bar="as-colored-text"
21
- nav-text-color="#f7f7f7"
22
- nav-item-spacing="relaxed"
23
- allow-spec-file-download="true"
24
- >
25
- </rapi-doc>
26
- </body>
27
- </html>
1
+ <script type="module" src="https://unpkg.com/rapidoc/dist/rapidoc-min.js"></script>
2
+ <rapi-doc
3
+ spec-url = "<%= OasRails::Engine.routes.find_script_name({}) %>.json"
4
+ theme = "dark"
5
+ bg-color="#0F172A"
6
+ text-color= "#f7f7f7"
7
+ show-header = 'false'
8
+ primary-color = "#2de410"
9
+ font-size="largest"
10
+ show-method-in-nav-bar="as-colored-text"
11
+ nav-text-color="#f7f7f7"
12
+ nav-item-spacing="relaxed"
13
+ allow-spec-file-download="true"
14
+ >
15
+ </rapi-doc>
@@ -2,6 +2,7 @@
2
2
  OasRails.configure do |config|
3
3
  # Basic Information about the API
4
4
  config.info.title = 'OasRails'
5
+ config.info.version = '1.0.0'
5
6
  config.info.summary = 'OasRails: Automatic Interactive API Documentation for Rails'
6
7
  config.info.description = <<~HEREDOC
7
8
  # Welcome to OasRails
@@ -62,6 +63,15 @@ OasRails.configure do |config|
62
63
  # API path configuration if your API is under a different namespace
63
64
  # config.api_path = "/"
64
65
 
66
+ # Apply your custom layout. Should be the name of your layout file
67
+ # Example: "application" if file named application.html.erb
68
+ # Default: false
69
+ # config.layout = "application"
70
+
71
+ # Excluding custom controlers or controlers#action
72
+ # Example: ["projects", "users#new"]
73
+ # config.ignored_actions = []
74
+
65
75
  # #######################
66
76
  # Authentication Settings
67
77
  # #######################
@@ -1,10 +1,12 @@
1
1
  module OasRails
2
2
  class Configuration
3
3
  attr_accessor :info,
4
+ :layout,
4
5
  :default_tags_from,
5
6
  :autodiscover_request_body,
6
7
  :autodiscover_responses,
7
8
  :api_path,
9
+ :ignored_actions,
8
10
  :security_schemas,
9
11
  :authenticate_all_routes_by_default,
10
12
  :set_default_responses,
@@ -14,6 +16,7 @@ module OasRails
14
16
 
15
17
  def initialize
16
18
  @info = Spec::Info.new
19
+ @layout = false
17
20
  @servers = default_servers
18
21
  @tags = []
19
22
  @swagger_version = '3.1.0'
@@ -21,6 +24,7 @@ module OasRails
21
24
  @autodiscover_request_body = true
22
25
  @autodiscover_responses = true
23
26
  @api_path = "/"
27
+ @ignored_actions = []
24
28
  @authenticate_all_routes_by_default = true
25
29
  @security_schema = nil
26
30
  @security_schemas = {}
@@ -93,6 +93,7 @@ module OasRails
93
93
  return false if RAILS_DEFAULT_CONTROLLERS.any? { |default| route.defaults[:controller].start_with?(default) }
94
94
  return false if RAILS_DEFAULT_PATHS.any? { |path| route.path.spec.to_s.include?(path) }
95
95
  return false unless route.path.spec.to_s.start_with?(OasRails.config.api_path)
96
+ return false if ignore_custom_actions(route)
96
97
 
97
98
  true
98
99
  end
@@ -119,6 +120,27 @@ module OasRails
119
120
  controller_class.instance_methods.include?(action_name.to_sym)
120
121
  end
121
122
  end
123
+
124
+ # Ignore user-specified paths in initializer configuration.
125
+ # Sanitize api_path by removing the "/" if it starts with that, and adding "/" if it ends without that.
126
+ # Support controller name only to ignore all controller actions.
127
+ # Support ignoring "controller#action"
128
+ # Ignoring "controller#action" AND "api_path/controller#action"
129
+ def ignore_custom_actions(route)
130
+ api_path = "#{OasRails.config.api_path.sub(%r{\A/}, '')}/".sub(%r{/+$}, '/')
131
+ ignored_actions = OasRails.config.ignored_actions.flat_map do |custom_route|
132
+ if custom_route.start_with?(api_path)
133
+ [custom_route]
134
+ else
135
+ ["#{api_path}#{custom_route}", custom_route]
136
+ end
137
+ end
138
+
139
+ controller_action = "#{route.defaults[:controller]}##{route.defaults[:action]}"
140
+ controller_only = route.defaults[:controller]
141
+
142
+ ignored_actions.include?(controller_action) || ignored_actions.include?(controller_only)
143
+ end
122
144
  end
123
145
  end
124
146
  end
@@ -1,3 +1,3 @@
1
1
  module OasRails
2
- VERSION = "0.6.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -15,7 +15,7 @@ module OasRails
15
15
  # @param text [String] The tag text to parse.
16
16
  # @return [RequestBodyExampleTag] The parsed request body example tag object.
17
17
  def parse_tag_with_request_body_example(tag_name, text)
18
- description, _, hash = extract_description_type_and_content(text, process_content: true)
18
+ description, _, hash = extract_description_type_and_content(text, process_content: true, expresion: /^(.*?)\[([^\]]*)\](.*)$/m)
19
19
  RequestBodyExampleTag.new(tag_name, description, content: hash)
20
20
  end
21
21
 
@@ -52,8 +52,8 @@ module OasRails
52
52
  # @param text [String] The text to parse.
53
53
  # @param process_content [Boolean] Whether to evaluate the content as a hash.
54
54
  # @return [Array] An array containing the description, type, and content or remaining text.
55
- def extract_description_type_and_content(text, process_content: false)
56
- match = text.match(/^(.*?)\s*\[(.*)\]\s*(.*)$/)
55
+ def extract_description_type_and_content(text, process_content: false, expresion: /^(.*?)\s*\[(.*)\]\s*(.*)$/)
56
+ match = text.match(expresion)
57
57
  raise ArgumentError, "Invalid tag format: #{text}" if match.nil?
58
58
 
59
59
  description = match[1].strip
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oas_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - a-chacon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-26 00:00:00.000000000 Z
11
+ date: 2024-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source