oas_core 0.3.0 → 0.4.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 342155f509e56cc99810dd3883b97d5d274546e2592108c937c746d47daec610
|
4
|
+
data.tar.gz: c4dd49a6427f7e9189b626359af59c245828073a94bda3a04c5870493620ac5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '069f0e27323893c9195f244ed21739f8b4fe04e9a9e424aa9f3fe6b4b4f2cd45ee2bfb16882eb4196f2dcbdef8dca472a2979608c89f9a2ecadc5d987cc57d73'
|
7
|
+
data.tar.gz: 929d2ce828e2b9ae88473d6401d8b2f8d7c1199b3908ede351588c83b620c10f097012c19eb11a2dc076b65130e09def523c30a567d06423ccbd764bcc0a454b
|
@@ -10,13 +10,9 @@ module OasCore
|
|
10
10
|
|
11
11
|
def from_oas_route(oas_route)
|
12
12
|
parameters_from_tags(tags: oas_route.tags(:parameter))
|
13
|
+
|
13
14
|
oas_route.path_params.try(:map) do |p|
|
14
|
-
unless @parameters.any?
|
15
|
-
param.name.to_s == p.to_s
|
16
|
-
end
|
17
|
-
@parameters << ParameterBuilder.new(@specification).from_path(oas_route.path,
|
18
|
-
p).build
|
19
|
-
end
|
15
|
+
@parameters << ParameterBuilder.new(@specification).from_path(oas_route.path, p).build unless @parameters.any? { |param| param.name.to_s == p.to_s }
|
20
16
|
end
|
21
17
|
|
22
18
|
self
|
@@ -6,6 +6,16 @@ module OasCore
|
|
6
6
|
# The JsonSchemaGenerator module provides methods to transform string representations
|
7
7
|
# of data types into JSON schema formats.
|
8
8
|
module JsonSchemaGenerator
|
9
|
+
@custom_type_parsers = {}
|
10
|
+
|
11
|
+
# Registers a custom type parser.
|
12
|
+
#
|
13
|
+
# @param type_matcher [Proc] A proc that matches the type string.
|
14
|
+
# @param parser [Proc] A proc that processes the type string.
|
15
|
+
def self.register_type_parser(type_matcher, parser)
|
16
|
+
@custom_type_parsers[type_matcher] = parser
|
17
|
+
end
|
18
|
+
|
9
19
|
# Processes a string representing a data type and converts it into a JSON schema.
|
10
20
|
#
|
11
21
|
# @param str [String] The string representation of a data type.
|
@@ -22,6 +32,7 @@ module OasCore
|
|
22
32
|
#
|
23
33
|
# @param str [String] The string representation of a data type.
|
24
34
|
# @return [Hash] A hash containing the type, whether it's required, and any additional properties.
|
35
|
+
# Registry for custom type parsers
|
25
36
|
def self.parse_type(str)
|
26
37
|
required = str.start_with?('!')
|
27
38
|
type = str.sub(/^!/, '').strip
|
@@ -32,7 +43,12 @@ module OasCore
|
|
32
43
|
when /^Array<(.+)>$/i
|
33
44
|
{ type: :array, required:, items: parse_type(::Regexp.last_match(1)) }
|
34
45
|
else
|
35
|
-
|
46
|
+
custom_parser = @custom_type_parsers.find { |matcher, _| matcher.call(type) }
|
47
|
+
if custom_parser
|
48
|
+
custom_parser.last.call(type, required)
|
49
|
+
else
|
50
|
+
{ type: type.downcase.to_sym, required: }
|
51
|
+
end
|
36
52
|
end
|
37
53
|
end
|
38
54
|
|
data/lib/oas_core/oas_route.rb
CHANGED
data/lib/oas_core/version.rb
CHANGED