oas_core 1.2.0 β 1.3.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 +4 -4
- data/README.md +1 -1
- data/lib/oas_core/builders/operation_builder.rb +10 -1
- data/lib/oas_core/configuration.rb +2 -2
- data/lib/oas_core/json_schema_generator.rb +2 -2
- data/lib/oas_core/spec/info.rb +2 -2
- data/lib/oas_core/spec/parameter.rb +1 -1
- data/lib/oas_core/spec/path_item.rb +5 -1
- data/lib/oas_core/spec/server.rb +4 -3
- data/lib/oas_core/spec/specification.rb +1 -1
- data/lib/oas_core/version.rb +1 -1
- data/lib/oas_core/yard/oas_core_factory.rb +62 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 25745b92adac67103b83e87c32b5e4ad79fa05addd4c18c36638a726e5c265d7
|
|
4
|
+
data.tar.gz: 584a858c3cba7df7ebf9a9f219f4580db1237dae3a2f07a3ac0d02f90e6f5b8b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1d62dbfe664d07dea17bd9f47b20cacc743e4e44fd6011c5e9e0b56c9dfd22ab8ac795590345014304e69708e734c9f45f55a8faa62a77a17ed94449fde713f9
|
|
7
|
+
data.tar.gz: 4135466e3a1c2a006ddf29d298676557cb65b7f750870e735eaf8af2da0c55bbb44b8f84769a2cf9bc39983f9a530f39c2fe25e5b618a2434bc02dded874da3c
|
data/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# πOpen API Specification Core
|
|
8
8
|
|
|
9
|
-
OasCore is a Ruby gem designed to generate Open API Specification (OAS) 3.
|
|
9
|
+
OasCore is a Ruby gem designed to generate Open API Specification (OAS) 3.2 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
10
|
|
|
11
11
|
## Framework adapters
|
|
12
12
|
|
|
@@ -35,7 +35,16 @@ module OasCore
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def extract_operation_id(oas_route:)
|
|
38
|
-
|
|
38
|
+
# Sanitize path to create URL-safe operationId:
|
|
39
|
+
# - Replace / with _
|
|
40
|
+
# - Remove braces from path parameters ({id} β id)
|
|
41
|
+
# - Clean up multiple consecutive underscores
|
|
42
|
+
sanitized_path = oas_route.path
|
|
43
|
+
.gsub('/', '_')
|
|
44
|
+
.gsub(/[{}]/, '')
|
|
45
|
+
.gsub(/_+/, '_')
|
|
46
|
+
.gsub(/^_|_$/, '')
|
|
47
|
+
"#{oas_route.verb}_#{sanitized_path}"
|
|
39
48
|
end
|
|
40
49
|
|
|
41
50
|
def extract_tags(oas_route:)
|
|
@@ -17,7 +17,7 @@ module OasCore
|
|
|
17
17
|
@info = args.fetch(:info, Spec::Info.new)
|
|
18
18
|
@servers = args.fetch(:servers, default_servers)
|
|
19
19
|
@tags = []
|
|
20
|
-
@swagger_version = '3.
|
|
20
|
+
@swagger_version = '3.2.0'
|
|
21
21
|
@default_tags_from = :namespace
|
|
22
22
|
@api_path = '/'
|
|
23
23
|
@authenticate_all_routes_by_default = true
|
|
@@ -26,7 +26,7 @@ module OasCore
|
|
|
26
26
|
@set_default_responses = true
|
|
27
27
|
@possible_default_responses = %i[not_found unauthorized forbidden internal_server_error
|
|
28
28
|
unprocessable_entity]
|
|
29
|
-
@http_verbs = %i[get post put patch delete]
|
|
29
|
+
@http_verbs = %i[get post put patch delete options head trace]
|
|
30
30
|
@response_body_of_default = 'Hash{ status: !Integer, error: String }'
|
|
31
31
|
|
|
32
32
|
@possible_default_responses.each do |response|
|
|
@@ -139,10 +139,10 @@ module OasCore
|
|
|
139
139
|
case type.to_s.downcase
|
|
140
140
|
when 'string' then { type: 'string' }
|
|
141
141
|
when 'integer' then { type: 'integer' }
|
|
142
|
-
when 'float' then { type: '
|
|
142
|
+
when 'float' then { type: 'number' }
|
|
143
143
|
when 'boolean' then { type: 'boolean' }
|
|
144
144
|
when 'array' then { type: 'array' }
|
|
145
|
-
when 'hash' then { type: '
|
|
145
|
+
when 'hash' then { type: 'object' }
|
|
146
146
|
when 'nil' then { type: 'null' }
|
|
147
147
|
when 'date' then { type: 'string', format: 'date' }
|
|
148
148
|
when 'datetime' then { type: 'string', format: 'date-time' }
|
data/lib/oas_core/spec/info.rb
CHANGED
|
@@ -31,7 +31,7 @@ module OasCore
|
|
|
31
31
|
def default_description
|
|
32
32
|
"# Welcome to OasCore
|
|
33
33
|
|
|
34
|
-
OasCore automatically generates interactive documentation for your Rails APIs using the OpenAPI Specification 3.
|
|
34
|
+
OasCore automatically generates interactive documentation for your Rails APIs using the OpenAPI Specification 3.2 (OAS 3.2) and displays it with a nice UI.
|
|
35
35
|
|
|
36
36
|
## Getting Started
|
|
37
37
|
|
|
@@ -52,7 +52,7 @@ To customize and enrich your API documentation:
|
|
|
52
52
|
|
|
53
53
|
## Features
|
|
54
54
|
|
|
55
|
-
- Automatic OAS 3.
|
|
55
|
+
- Automatic OAS 3.2 document generation
|
|
56
56
|
- [RapiDoc](https://github.com/rapi-doc/RapiDoc) integration for interactive exploration
|
|
57
57
|
- Minimal setup required for basic documentation
|
|
58
58
|
- Extensible through configuration and Yard tags
|
|
@@ -6,7 +6,7 @@ module OasCore
|
|
|
6
6
|
include Specable
|
|
7
7
|
include Hashable
|
|
8
8
|
|
|
9
|
-
STYLE_DEFAULTS = { query: 'form', path: 'simple', header: 'simple', cookie: 'form' }.freeze
|
|
9
|
+
STYLE_DEFAULTS = { query: 'form', path: 'simple', header: 'simple', cookie: 'form', querystring: 'form' }.freeze
|
|
10
10
|
|
|
11
11
|
attr_accessor :name, :style, :description, :required, :schema
|
|
12
12
|
attr_reader :in
|
|
@@ -4,7 +4,7 @@ module OasCore
|
|
|
4
4
|
module Spec
|
|
5
5
|
class PathItem
|
|
6
6
|
include Specable
|
|
7
|
-
attr_reader :get, :post, :put, :patch, :delete
|
|
7
|
+
attr_reader :get, :post, :put, :patch, :delete, :options, :head, :trace, :query
|
|
8
8
|
|
|
9
9
|
def initialize(specification)
|
|
10
10
|
@specification = specification
|
|
@@ -13,6 +13,10 @@ module OasCore
|
|
|
13
13
|
@put = nil
|
|
14
14
|
@patch = nil
|
|
15
15
|
@delete = nil
|
|
16
|
+
@options = nil
|
|
17
|
+
@head = nil
|
|
18
|
+
@trace = nil
|
|
19
|
+
@query = nil
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
def add_operation(http_method, operation)
|
data/lib/oas_core/spec/server.rb
CHANGED
|
@@ -4,15 +4,16 @@ module OasCore
|
|
|
4
4
|
module Spec
|
|
5
5
|
class Server
|
|
6
6
|
include Specable
|
|
7
|
-
attr_accessor :url, :description
|
|
7
|
+
attr_accessor :url, :description, :name
|
|
8
8
|
|
|
9
|
-
def initialize(url:, description:)
|
|
9
|
+
def initialize(url:, description:, name: nil)
|
|
10
10
|
@url = url
|
|
11
11
|
@description = description
|
|
12
|
+
@name = name
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def oas_fields
|
|
15
|
-
%i[url description]
|
|
16
|
+
%i[url description name]
|
|
16
17
|
end
|
|
17
18
|
end
|
|
18
19
|
end
|
data/lib/oas_core/version.rb
CHANGED
|
@@ -52,11 +52,73 @@ module OasCore
|
|
|
52
52
|
description, schema_keywords = extract_schema_keywords(description)
|
|
53
53
|
schema.merge!(schema_keywords)
|
|
54
54
|
|
|
55
|
+
schema[:default] = parse_default_tag(schema) if schema.key?(:default)
|
|
56
|
+
schema[:enum] = parse_enum_tag(schema) if schema.key?(:enum)
|
|
57
|
+
|
|
55
58
|
ParameterTag.new(tag_name, name, description.strip, schema, location, required:)
|
|
56
59
|
rescue StandardError => e
|
|
57
60
|
raise TagParsingError, "Failed to parse parameter tag: #{e.message}"
|
|
58
61
|
end
|
|
59
62
|
|
|
63
|
+
# Parses the default tag.
|
|
64
|
+
# @param schema [Hash] The schema containing the default value.
|
|
65
|
+
# @return [Value] The parsed default value.
|
|
66
|
+
def parse_default_tag(schema)
|
|
67
|
+
case schema[:type]
|
|
68
|
+
when 'integer'
|
|
69
|
+
parse_integer(schema[:default])
|
|
70
|
+
when 'boolean'
|
|
71
|
+
parse_boolean(schema[:default])
|
|
72
|
+
else
|
|
73
|
+
schema[:default]
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Parses the enum tag.
|
|
78
|
+
# @param schema [Hash] The schema containing the enum values.
|
|
79
|
+
# @return [Array] The parsed enum values.
|
|
80
|
+
def parse_enum_tag(schema)
|
|
81
|
+
enum_values = schema[:enum]
|
|
82
|
+
return enum_values unless enum_values.is_a?(Array)
|
|
83
|
+
|
|
84
|
+
case schema[:type]
|
|
85
|
+
when 'integer'
|
|
86
|
+
enum_values.map do |value|
|
|
87
|
+
parse_integer(value)
|
|
88
|
+
end
|
|
89
|
+
when 'boolean'
|
|
90
|
+
enum_values.map do |value|
|
|
91
|
+
parse_boolean(value)
|
|
92
|
+
end
|
|
93
|
+
else
|
|
94
|
+
enum_values
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Parses an integer value.
|
|
99
|
+
# @param value [String] The value to parse.
|
|
100
|
+
# @return [Integer, Object] The parsed integer or the original value if it can't be coerced.
|
|
101
|
+
def parse_integer(value)
|
|
102
|
+
Integer(value)
|
|
103
|
+
rescue ArgumentError, TypeError
|
|
104
|
+
# Keep original value if it can't be coerced
|
|
105
|
+
value
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Parses a boolean value.
|
|
109
|
+
# @param value [String] The value to parse.
|
|
110
|
+
# @return [Boolean, Object] The parsed boolean or the original value if it can't be coerced.
|
|
111
|
+
def parse_boolean(value)
|
|
112
|
+
value_str = value.to_s.downcase
|
|
113
|
+
if value_str == 'true'
|
|
114
|
+
true
|
|
115
|
+
elsif value_str == 'false'
|
|
116
|
+
false
|
|
117
|
+
else
|
|
118
|
+
value
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
60
122
|
# Parses a tag that represents a response.
|
|
61
123
|
# @param tag_name [String] The name of the tag.
|
|
62
124
|
# @param text [String] The tag text to parse.
|
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.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- a-chacon
|
|
@@ -72,7 +72,7 @@ dependencies:
|
|
|
72
72
|
- !ruby/object:Gem::Version
|
|
73
73
|
version: '0.9'
|
|
74
74
|
description: OasCore simplifies API documentation by automatically generating OpenAPI
|
|
75
|
-
Specification (OAS 3.
|
|
75
|
+
Specification (OAS 3.2) documents from your Ruby application routes. It eliminates
|
|
76
76
|
the need for manual documentation, ensuring accuracy and consistency.
|
|
77
77
|
email:
|
|
78
78
|
- andres.ch@protonmail.com
|