oas_rails 0.14.0 → 0.16.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: 041c5783e2bbbedca71601a21756f2d90398bed275866c6214935965a47766f8
4
- data.tar.gz: 4ea6110ed149c0d90b2c47e980f06abb8ef9c6efad7aa35699e23a8e95017fb6
3
+ metadata.gz: 44055a7f28caf66419b7450458c652bfa88b28459669f856b35a83dc4a25f228
4
+ data.tar.gz: 188cafd5d14c17fe5055850af9fd712d086f135a20aa70e9640a29721a7656cf
5
5
  SHA512:
6
- metadata.gz: bd3d0eb79205462ca026002e5bbb64898704d1c2576320568a5332cb50dccf5e7044a7cc12aab06344d583b4d6a7aa0cdf6901f2a9ddbd0509ca305ef3f9dd96
7
- data.tar.gz: fcaf3d373fed62a411de505665b6f1c288834902d009fc0d5c1d399693a0a7011b00e3df77a2fce6c77d10113044430e9ffe03ee87400976e8d9bdaca23fa631
6
+ metadata.gz: 927cdf58a97c24ad7e6956bc09086b1baa221ec796cea3ccb08fc988a6ed92a4707097b956a00ac888cefaea4e238f48c49c6b197b96b08b4f48f0c6fd194c40
7
+ data.tar.gz: b64572ca08987c1461fe2ae799a3771021dc534e18a35b0f394181ad2fdfe7d8a46dd6124caf56aff2745476c2eacc795df72ca3b6ddbc73fce4146dc581a023
@@ -5,6 +5,7 @@ module OasRails
5
5
  @context = context || :incoming
6
6
  @specification = specification
7
7
  @media_type = Spec::MediaType.new(specification)
8
+ @content_type = "application/json"
8
9
  end
9
10
 
10
11
  def with_schema(schema)
@@ -19,6 +20,12 @@ module OasRails
19
20
  self
20
21
  end
21
22
 
23
+ def with_content_type(content_type)
24
+ @content_type = content_type if content_type.present?
25
+
26
+ self
27
+ end
28
+
22
29
  def with_examples_from_tags(tags)
23
30
  @media_type.examples = @media_type.examples.merge(tags.each_with_object({}).with_index(1) do |(example, result), _index|
24
31
  key = example.text.downcase.gsub(' ', '_')
@@ -47,7 +54,7 @@ module OasRails
47
54
 
48
55
  def build
49
56
  {
50
- "application/json": @media_type
57
+ @content_type => @media_type
51
58
  }
52
59
  end
53
60
  end
@@ -52,7 +52,7 @@ module OasRails
52
52
  end
53
53
 
54
54
  def path
55
- Extractors::RouteExtractor.clean_route(@rails_route.path.spec.to_s)
55
+ OasRails.config.route_extractor.clean_route(@rails_route.path.spec.to_s)
56
56
  end
57
57
 
58
58
  def source_string
@@ -6,8 +6,8 @@ module OasRails
6
6
  @path_item = Spec::PathItem.new(specification)
7
7
  end
8
8
 
9
- def from_path(path, route_extractor: Extractors::RouteExtractor)
10
- route_extractor.host_routes_by_path(path).each do |oas_route|
9
+ def from_path(path)
10
+ OasRails.config.route_extractor.host_routes_by_path(path).each do |oas_route|
11
11
  oas_route.verb.downcase.split("|").each do |v|
12
12
  @path_item.add_operation(v, OperationBuilder.new(@specification).from_oas_route(oas_route).build)
13
13
  end
@@ -19,10 +19,10 @@ module OasRails
19
19
 
20
20
  def from_tags(tag:, examples_tags: [])
21
21
  if Utils.active_record_class?(tag.klass)
22
- from_model_class(klass: tag.klass, description: tag.text, required: tag.required, examples_tags:)
22
+ from_model_class(klass: tag.klass, description: tag.text, required: tag.required, content_type: tag.content_type, examples_tags:)
23
23
  else
24
24
  @request_body.description = tag.text
25
- @request_body.content = ContentBuilder.new(@specification, :incoming).with_schema(tag.schema).with_examples_from_tags(examples_tags).build
25
+ @request_body.content = ContentBuilder.new(@specification, :incoming).with_schema(tag.schema).with_examples_from_tags(examples_tags).with_content_type(tag.content_type).build
26
26
  @request_body.required = tag.required
27
27
  end
28
28
 
@@ -31,7 +31,7 @@ module OasRails
31
31
 
32
32
  def from_model_class(klass:, **kwargs)
33
33
  @request_body.description = kwargs[:description] || klass.to_s
34
- @request_body.content = ContentBuilder.new(@specification, :incoming).from_model_class(klass).with_examples_from_tags(kwargs[:examples_tags] || {}).build
34
+ @request_body.content = ContentBuilder.new(@specification, :incoming).from_model_class(klass).with_examples_from_tags(kwargs[:examples_tags] || {}).with_content_type(kwargs[:content_type]).build
35
35
  @request_body.required = kwargs[:required]
36
36
 
37
37
  self
@@ -15,7 +15,7 @@ module OasRails
15
15
  :use_model_names,
16
16
  :rapidoc_theme
17
17
 
18
- attr_reader :servers, :tags, :security_schema, :include_mode, :response_body_of_default
18
+ attr_reader :servers, :tags, :security_schema, :include_mode, :response_body_of_default, :route_extractor
19
19
 
20
20
  def initialize
21
21
  @info = Spec::Info.new
@@ -38,6 +38,7 @@ module OasRails
38
38
  @use_model_names = false
39
39
  @rapidoc_theme = :rails
40
40
  @include_mode = :all
41
+ @route_extractor = Extractors::RouteExtractor
41
42
 
42
43
  @possible_default_responses.each do |response|
43
44
  method_name = "response_body_of_#{response}="
@@ -74,6 +75,19 @@ module OasRails
74
75
  @tags = value.map { |t| Spec::Tag.new(name: t[:name], description: t[:description]) }
75
76
  end
76
77
 
78
+ def route_extractor=(value)
79
+ unless value.respond_to?(:host_routes) &&
80
+ value.respond_to?(:host_routes_by_path) &&
81
+ value.respond_to?(:clear_cache) &&
82
+ value.respond_to?(:host_paths) &&
83
+ value.respond_to?(:clean_route)
84
+ raise ArgumentError,
85
+ "Route extractor must have the following methods: host_routes, host_routes_by_path, clear_cache, host_paths, and clean_route"
86
+ end
87
+
88
+ @route_extractor = value
89
+ end
90
+
77
91
  def excluded_columns_incoming
78
92
  %i[id created_at updated_at deleted_at]
79
93
  end
@@ -62,7 +62,7 @@ module OasRails
62
62
 
63
63
  if Utils.active_record_class?(klass)
64
64
  schema = Builders::EsquemaBuilder.build_outgoing_schema(klass:)
65
- if test_singularity(maybe_a_model)
65
+ if test_singularity?(maybe_a_model)
66
66
  build_singular_model_schema_and_examples(maybe_a_model, errors, klass, schema)
67
67
  else
68
68
  build_array_model_schema_and_examples(maybe_a_model, klass, schema)
@@ -118,7 +118,7 @@ module OasRails
118
118
  #
119
119
  # @param str [String] The string to test.
120
120
  # @return [Boolean] True if the string is a singular model, false otherwise.
121
- def test_singularity(str)
121
+ def test_singularity?(str)
122
122
  str.pluralize != str && str.singularize == str
123
123
  end
124
124
 
@@ -124,6 +124,7 @@ module OasRails
124
124
  when 'nil' then { type: "null" }
125
125
  when 'date' then { type: "string", format: "date" }
126
126
  when 'datetime' then { type: "string", format: "date-time" }
127
+ when 'file' then { type: "string", format: "binary" }
127
128
  else type.to_s.downcase
128
129
  end
129
130
  end
@@ -13,8 +13,8 @@ module OasRails
13
13
  @delete = nil
14
14
  end
15
15
 
16
- def fill_from(path, route_extractor: Extractors::RouteExtractor)
17
- route_extractor.host_routes_by_path(path).each do |oas_route|
16
+ def fill_from(path)
17
+ OasRails.config.route_extractor.host_routes_by_path(path).each do |oas_route|
18
18
  add_operation(oas_route.verb.downcase, Spec::Operation.new(@specification).fill_from(oas_route))
19
19
  end
20
20
 
@@ -20,8 +20,8 @@ module OasRails
20
20
  @paths = Spec::Paths.new(self)
21
21
  end
22
22
 
23
- def build(route_extractor: Extractors::RouteExtractor)
24
- route_extractor.host_paths.each do |path|
23
+ def build
24
+ OasRails.config.route_extractor.host_paths.each do |path|
25
25
  @paths.add_path(path)
26
26
  end
27
27
  end
@@ -31,7 +31,7 @@ module OasRails
31
31
  # @return [void]
32
32
  def clear_cache
33
33
  MethodSource.clear_cache
34
- Extractors::RouteExtractor.clear_cache
34
+ OasRails.config.route_extractor.clear_cache
35
35
  end
36
36
 
37
37
  def oas_fields
@@ -1,3 +1,3 @@
1
1
  module OasRails
2
- VERSION = "0.14.0"
2
+ VERSION = "0.16.0"
3
3
  end
@@ -6,8 +6,8 @@ module OasRails
6
6
  # @param text [String] The tag text to parse.
7
7
  # @return [RequestBodyTag] The parsed request body tag object.
8
8
  def parse_tag_with_request_body(tag_name, text)
9
- description, klass, schema, required = extract_description_and_schema(text.squish)
10
- RequestBodyTag.new(tag_name, description, klass, schema:, required:)
9
+ description, klass, schema, required, content_type = extract_description_and_schema(text.squish)
10
+ RequestBodyTag.new(tag_name, description, klass, schema:, required:, content_type:)
11
11
  end
12
12
 
13
13
  # Parses a tag that represents a request body example.
@@ -66,11 +66,13 @@ module OasRails
66
66
 
67
67
  # Specific method to extract description and schema for request body tags.
68
68
  # @param text [String] The text to parse.
69
- # @return [Array] An array containing the description, class, schema, and required flag.
69
+ # @return [Array] An array containing the description, class, schema, required flag and content type.
70
70
  def extract_description_and_schema(text)
71
71
  description, type, = extract_description_type_and_content(text)
72
+ description, content_type = extract_text_and_parentheses_content(description)
72
73
  klass, schema, required = type_text_to_schema(type)
73
- [description, klass, schema, required]
74
+
75
+ [description, klass, schema, required, content_type]
74
76
  end
75
77
 
76
78
  # Specific method to extract name, location, and schema for parameters.
@@ -119,7 +121,7 @@ module OasRails
119
121
  # @param input [String] The input text to parse.
120
122
  # @return [Array] An array containing the name and location.
121
123
  def extract_text_and_parentheses_content(input)
122
- return unless input =~ /^(.+?)\(([^)]+)\)/
124
+ return input unless input =~ /^(.+?)\(([^)]+)\)/
123
125
 
124
126
  text = ::Regexp.last_match(1).strip
125
127
  parenthesis_content = ::Regexp.last_match(2).strip
@@ -1,14 +1,15 @@
1
1
  module OasRails
2
2
  module YARD
3
3
  class RequestBodyTag < ::YARD::Tags::Tag
4
- attr_accessor :klass, :schema, :required
4
+ attr_accessor :klass, :schema, :required, :content_type
5
5
 
6
- def initialize(tag_name, text, klass, schema: {}, required: false)
6
+ def initialize(tag_name, text, klass, schema: {}, required: false, content_type: 'application/json')
7
7
  # initialize(tag_name, text, types = nil, name = nil)
8
8
  super(tag_name, text, nil, nil)
9
9
  @klass = klass
10
10
  @schema = schema
11
11
  @required = required
12
+ @content_type = content_type
12
13
  end
13
14
  end
14
15
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oas_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - a-chacon
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-05-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: easy_talk_two
@@ -131,7 +130,6 @@ licenses:
131
130
  - GPL-3.0-only
132
131
  metadata:
133
132
  homepage_uri: https://github.com/a-chacon/oas_rails
134
- post_install_message:
135
133
  rdoc_options: []
136
134
  require_paths:
137
135
  - lib
@@ -146,8 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
144
  - !ruby/object:Gem::Version
147
145
  version: '0'
148
146
  requirements: []
149
- rubygems_version: 3.5.11
150
- signing_key:
147
+ rubygems_version: 3.6.7
151
148
  specification_version: 4
152
149
  summary: OasRails is a Rails engine for generating automatic interactive documentation
153
150
  for your Rails APIs.