oas_core 0.3.0 → 0.5.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: '019372235c3a772e19f7e7c60b15b3409130efbd8a16d9a75a5c7c9a1a9ecd09'
|
4
|
+
data.tar.gz: 694f56c8a25feeb710a0a431ae44e3975a8b8b23a72d2433570f944de1b002f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb19a595ad1d2031eb0872b5c2d795b63e113ae7920fd74fafec502193a71e5c1b900c4edaecdbacd8951721dd8b419eec82c80dfcf8ee5102d5e947d7889cf6
|
7
|
+
data.tar.gz: 59f273f6e638a37d54bd010e79faff713d3df1713f494dc4dec752fae1bbfdd1276bbad5eb87115e787a80e01af129f7f7f56d451d20df152bd4fc6f7f2e73c3
|
data/README.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|

|
2
2
|

|
3
|
-

|
4
4
|

|
5
|
-

|
6
5
|

|
7
6
|
|
8
|
-
# 📃Open API Specification
|
7
|
+
# 📃Open API Specification Core
|
9
8
|
|
10
|
-
|
9
|
+
OasCore is a Ruby gem designed to generate Open API Specification (OAS) 3.1 documentation directly from YARD comments in your endpoints. It serves as the core engine for OAS generation, while framework-specific adapters like `OasRails` (for Ruby on Rails) handle the extraction, integration and additional features.
|
10
|
+
|
11
|
+
## Framework adapters
|
12
|
+
|
13
|
+
- **[OasRails](https://github.com/a-chacon/oas_rails)**
|
11
14
|
|
12
15
|
## Documentation
|
13
16
|
|
@@ -30,12 +30,13 @@ module OasCore
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def extract_summary(oas_route:)
|
33
|
-
oas_route.tags(:summary).first
|
34
|
-
|
33
|
+
summary_tag = oas_route.tags(:summary).first
|
34
|
+
summary_tag&.text || generate_crud_name(oas_route.method_name,
|
35
|
+
oas_route.controller.downcase) || "#{oas_route.verb} #{oas_route.path}"
|
35
36
|
end
|
36
37
|
|
37
38
|
def extract_operation_id(oas_route:)
|
38
|
-
"#{oas_route.
|
39
|
+
"#{oas_route.verb}_#{oas_route.path.gsub('/', '_')}"
|
39
40
|
end
|
40
41
|
|
41
42
|
def extract_tags(oas_route:)
|
@@ -50,7 +51,7 @@ module OasCore
|
|
50
51
|
def default_tags(oas_route:)
|
51
52
|
tags = []
|
52
53
|
if OasCore.config.default_tags_from == :namespace
|
53
|
-
tag = oas_route.path.split('/').reject(&:empty?).first
|
54
|
+
tag = oas_route.path.split('/').reject(&:empty?).first&.titleize
|
54
55
|
tags << tag unless tag.nil?
|
55
56
|
else
|
56
57
|
tags << oas_route.controller.gsub('/', ' ').titleize
|
@@ -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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
@parameters << ParameterBuilder.new(@specification).from_path(oas_route.path,
|
18
|
-
p).build
|
19
|
-
end
|
13
|
+
|
14
|
+
oas_route.path_params&.map do |p|
|
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