oas_core 1.1.0 → 1.2.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: 12fdf235fa83442a3868ac09e2aa1185268aad637a799df7a184ac38c396dfdc
4
- data.tar.gz: 4546918641b90a1808edff30c8595f8b102ddc5c616bb13b8768a6756366f98a
3
+ metadata.gz: a77360fd7e6944eb6e1ea64830375d480b04c289e478b63b444c3dc6f12134f9
4
+ data.tar.gz: 371786121bec6160afd368ed2677999055189aad0cbfa35c26a8c16a572c2505
5
5
  SHA512:
6
- metadata.gz: 9995f945c5e3688c1f8d18729bbddbcc3febe1a7322739daf92e90aaf161f69d039b64327832de832ed477ecd8ec55b2433c3117b1359cf954de2daa3e8f2877
7
- data.tar.gz: 30419c1faa9f66271bbcc2261c6ca5fa64f4f1b3203503a8fcfa32a9a31ac39b7326e0455c0090f7e8ee35fe5be3bc2a0dcc9884bfa87250c6808c858c411ad3
6
+ metadata.gz: ddd844dd639cda56c2635b52bd46db947a07428c8ef482f82184ca5693768665f7bb29ebd0d1ca275104a3ff506d5c9f5530d13255f2a5bccbdecd80aa3b7181
7
+ data.tar.gz: e66985fb30da4835e342a0580947de67a008f01c55d8799e59135d3ad137d42a341198fd96b988a095ab20353a429441f1ef3753c0a87517fb637ac70f227a5c
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OasCore
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -49,6 +49,8 @@ module OasCore
49
49
  raw_type, required = text_and_required(second)
50
50
  schema = raw_type_to_content(raw_type)
51
51
  name = "#{name}[]" if location == 'query' && schema[:type] == 'array'
52
+ description, schema_keywords = extract_schema_keywords(description)
53
+ schema.merge!(schema_keywords)
52
54
 
53
55
  ParameterTag.new(tag_name, name, description.strip, schema, location, required:)
54
56
  rescue StandardError => e
@@ -201,6 +203,37 @@ module OasCore
201
203
  [text.strip, nil]
202
204
  end
203
205
  end
206
+
207
+ # Only allows keywords defined in the OpenAPI 3.0 specification for parameter schemas.
208
+ # @param text [String] The text to parse.
209
+ # @return [Array] An array containing the cleaned description and a hash of extracted keywords.
210
+ def extract_schema_keywords(text)
211
+ allowed_keywords = %i[
212
+ default minimum maximum enum format pattern multipleOf
213
+ exclusiveMinimum exclusiveMax minLength maxLength nullable
214
+ ].freeze
215
+
216
+ keywords = {}
217
+ cleaned_text = text.dup
218
+
219
+ text.scan(/(\w+):\s*\(([^)]+)\)/) do |keyword, value|
220
+ keyword_sym = keyword.to_sym
221
+ if allowed_keywords.include?(keyword_sym)
222
+ parsed_value = case keyword_sym
223
+ when :nullable, :exclusiveMinimum, :exclusiveMaximum
224
+ value.strip.downcase == 'true'
225
+ when :enum
226
+ value.strip.split(/\s*,\s*/)
227
+ else
228
+ value.strip
229
+ end
230
+ keywords[keyword_sym] = parsed_value
231
+ cleaned_text.sub!(/#{keyword}:\s*\([^)]+\)/, '')
232
+ end
233
+ end
234
+
235
+ [cleaned_text.strip, keywords]
236
+ end
204
237
  end
205
238
  end
206
239
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oas_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - a-chacon