oas_rails 0.16.0 → 0.17.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 +3 -1
- data/lib/oas_rails/builders/oas_route_builder.rb +2 -3
- data/lib/oas_rails/configuration.rb +14 -127
- data/lib/oas_rails/engine.rb +0 -5
- data/lib/oas_rails/version.rb +1 -1
- data/lib/oas_rails.rb +18 -64
- metadata +4 -54
- data/lib/oas_rails/builders/content_builder.rb +0 -62
- data/lib/oas_rails/builders/operation_builder.rb +0 -32
- data/lib/oas_rails/builders/parameter_builder.rb +0 -28
- data/lib/oas_rails/builders/parameters_builder.rb +0 -39
- data/lib/oas_rails/builders/path_item_builder.rb +0 -24
- data/lib/oas_rails/builders/request_body_builder.rb +0 -61
- data/lib/oas_rails/builders/response_builder.rb +0 -40
- data/lib/oas_rails/builders/responses_builder.rb +0 -81
- data/lib/oas_rails/extractors/oas_route_extractor.rb +0 -66
- data/lib/oas_rails/json_schema_generator.rb +0 -132
- data/lib/oas_rails/oas_route.rb +0 -21
- data/lib/oas_rails/spec/components.rb +0 -96
- data/lib/oas_rails/spec/contact.rb +0 -18
- data/lib/oas_rails/spec/hashable.rb +0 -39
- data/lib/oas_rails/spec/info.rb +0 -66
- data/lib/oas_rails/spec/license.rb +0 -18
- data/lib/oas_rails/spec/media_type.rb +0 -24
- data/lib/oas_rails/spec/operation.rb +0 -25
- data/lib/oas_rails/spec/parameter.rb +0 -37
- data/lib/oas_rails/spec/path_item.rb +0 -33
- data/lib/oas_rails/spec/paths.rb +0 -26
- data/lib/oas_rails/spec/reference.rb +0 -16
- data/lib/oas_rails/spec/request_body.rb +0 -21
- data/lib/oas_rails/spec/response.rb +0 -20
- data/lib/oas_rails/spec/responses.rb +0 -25
- data/lib/oas_rails/spec/server.rb +0 -17
- data/lib/oas_rails/spec/specable.rb +0 -54
- data/lib/oas_rails/spec/specification.rb +0 -50
- data/lib/oas_rails/spec/tag.rb +0 -18
- data/lib/oas_rails/yard/example_tag.rb +0 -12
- data/lib/oas_rails/yard/oas_rails_factory.rb +0 -169
- data/lib/oas_rails/yard/parameter_tag.rb +0 -14
- data/lib/oas_rails/yard/request_body_example_tag.rb +0 -11
- data/lib/oas_rails/yard/request_body_tag.rb +0 -16
- data/lib/oas_rails/yard/response_example_tag.rb +0 -12
- data/lib/oas_rails/yard/response_tag.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d60145b23d4b27b3fc5f1f58e024cb4ea0df37c6d10932d64b9bc5ce08641e83
|
4
|
+
data.tar.gz: '099cce8d88c18549bded9eaa2e3f4b9176a1a934f2a511bb3d6af567c18822ed'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bb4524c0f29f381c9e1fa3b351bbb5a860e05a71e83fa7298ec62b68a39f6a2b2a8c21057e1f0a262482d4e565be4e33ff79b490aff2539d074a98dc5506199
|
7
|
+
data.tar.gz: 22f0679476e47e8e72a7fd77c68d944a75b68fd8b004c030676a84ab8a008433d17530d1a985b75ffdebb55ce56795bf7c14679d65ade303c65732ffe705dfec
|
data/README.md
CHANGED
@@ -9,6 +9,8 @@
|
|
9
9
|
|
10
10
|
OasRails is a Rails engine for generating **automatic interactive documentation for your Rails APIs**. It generates an **OAS 3.1** document and displays it using **[RapiDoc](https://rapidocweb.com)**.
|
11
11
|
|
12
|
+
It relies on the [OasCore](https://github.com/a-chacon/oas_core) gem.
|
13
|
+
|
12
14
|
### 🚀 Demo App
|
13
15
|
|
14
16
|
Explore the interactive documentation live:
|
@@ -47,7 +49,7 @@ The goal is to minimize the effort required to create comprehensive documentatio
|
|
47
49
|
|
48
50
|
## Documentation
|
49
51
|
|
50
|
-
For see how to install, configure and use OasRails please refere to the [
|
52
|
+
For see how to install, configure and use OasRails please refere to the [OasCore MDBook](http://a-chacon.com/oas_core)
|
51
53
|
|
52
54
|
## Contributing
|
53
55
|
|
@@ -10,15 +10,14 @@ module OasRails
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def build
|
13
|
-
OasRoute.new(
|
13
|
+
OasCore::OasRoute.new(
|
14
14
|
controller_class: controller_class,
|
15
15
|
controller_action: controller_action,
|
16
16
|
controller: controller,
|
17
17
|
controller_path: controller_path,
|
18
|
-
|
18
|
+
method_name: method,
|
19
19
|
verb: verb,
|
20
20
|
path: path,
|
21
|
-
rails_route: @rails_route,
|
22
21
|
docstring: docstring,
|
23
22
|
source_string: source_string,
|
24
23
|
tags: tags
|
@@ -1,78 +1,28 @@
|
|
1
1
|
module OasRails
|
2
|
-
class Configuration
|
3
|
-
attr_accessor :
|
4
|
-
|
5
|
-
:default_tags_from,
|
6
|
-
:autodiscover_request_body,
|
7
|
-
:autodiscover_responses,
|
8
|
-
:api_path,
|
9
|
-
:ignored_actions,
|
10
|
-
:security_schemas,
|
11
|
-
:authenticate_all_routes_by_default,
|
12
|
-
:set_default_responses,
|
13
|
-
:possible_default_responses,
|
14
|
-
:http_verbs,
|
15
|
-
:use_model_names,
|
16
|
-
:rapidoc_theme
|
17
|
-
|
18
|
-
attr_reader :servers, :tags, :security_schema, :include_mode, :response_body_of_default, :route_extractor
|
2
|
+
class Configuration < OasCore::Configuration
|
3
|
+
attr_accessor :autodiscover_request_body, :autodiscover_responses, :ignored_actions, :rapidoc_theme, :layout
|
4
|
+
attr_reader :route_extractor, :include_mode
|
19
5
|
|
20
6
|
def initialize
|
21
|
-
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@tags = []
|
25
|
-
@swagger_version = '3.1.0'
|
26
|
-
@default_tags_from = :namespace
|
7
|
+
super
|
8
|
+
@route_extractor = Extractors::RouteExtractor
|
9
|
+
@include_mode = :all
|
27
10
|
@autodiscover_request_body = true
|
28
11
|
@autodiscover_responses = true
|
29
|
-
@api_path = "/"
|
30
12
|
@ignored_actions = []
|
31
|
-
@authenticate_all_routes_by_default = true
|
32
|
-
@security_schema = nil
|
33
|
-
@security_schemas = {}
|
34
|
-
@set_default_responses = true
|
35
|
-
@possible_default_responses = [:not_found, :unauthorized, :forbidden, :internal_server_error, :unprocessable_entity]
|
36
|
-
@http_verbs = [:get, :post, :put, :patch, :delete]
|
37
|
-
@response_body_of_default = "Hash{ status: !Integer, error: String }"
|
38
|
-
@use_model_names = false
|
39
13
|
@rapidoc_theme = :rails
|
40
|
-
@
|
41
|
-
@route_extractor = Extractors::RouteExtractor
|
42
|
-
|
43
|
-
@possible_default_responses.each do |response|
|
44
|
-
method_name = "response_body_of_#{response}="
|
45
|
-
variable_name = "@response_body_of_#{response}"
|
46
|
-
|
47
|
-
define_singleton_method(method_name) do |value|
|
48
|
-
raise ArgumentError, "#{method_name} must be a String With a valid object" unless value.is_a?(String)
|
49
|
-
|
50
|
-
OasRails::JsonSchemaGenerator.parse_type(value)
|
51
|
-
instance_variable_set(variable_name, value)
|
52
|
-
end
|
14
|
+
@layout = nil
|
53
15
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def security_schema=(value)
|
61
|
-
return unless (security_schema = DEFAULT_SECURITY_SCHEMES[value])
|
62
|
-
|
63
|
-
@security_schemas = { value => security_schema }
|
16
|
+
# TODO: implement
|
17
|
+
# autodiscover_request_body
|
18
|
+
# autodiscover_responses
|
64
19
|
end
|
65
20
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
def servers=(value)
|
71
|
-
@servers = value.map { |s| Spec::Server.new(url: s[:url], description: s[:description]) }
|
72
|
-
end
|
21
|
+
def include_mode=(value)
|
22
|
+
valid_modes = %i[all with_tags explicit]
|
23
|
+
raise ArgumentError, "include_mode must be one of #{valid_modes}" unless valid_modes.include?(value)
|
73
24
|
|
74
|
-
|
75
|
-
@tags = value.map { |t| Spec::Tag.new(name: t[:name], description: t[:description]) }
|
25
|
+
@include_mode = value
|
76
26
|
end
|
77
27
|
|
78
28
|
def route_extractor=(value)
|
@@ -87,68 +37,5 @@ module OasRails
|
|
87
37
|
|
88
38
|
@route_extractor = value
|
89
39
|
end
|
90
|
-
|
91
|
-
def excluded_columns_incoming
|
92
|
-
%i[id created_at updated_at deleted_at]
|
93
|
-
end
|
94
|
-
|
95
|
-
def excluded_columns_outgoing
|
96
|
-
[]
|
97
|
-
end
|
98
|
-
|
99
|
-
def include_mode=(value)
|
100
|
-
valid_modes = [:all, :with_tags, :explicit]
|
101
|
-
raise ArgumentError, "include_mode must be one of #{valid_modes}" unless valid_modes.include?(value)
|
102
|
-
|
103
|
-
@include_mode = value
|
104
|
-
end
|
105
|
-
|
106
|
-
def response_body_of_default=(value)
|
107
|
-
raise ArgumentError, "response_body_of_default must be a String With a valid object" unless value.is_a?(String)
|
108
|
-
|
109
|
-
OasRails::JsonSchemaGenerator.parse_type(value)
|
110
|
-
@response_body_of_default = value
|
111
|
-
end
|
112
40
|
end
|
113
|
-
|
114
|
-
DEFAULT_SECURITY_SCHEMES = {
|
115
|
-
api_key_cookie: {
|
116
|
-
type: "apiKey",
|
117
|
-
in: "cookie",
|
118
|
-
name: "api_key",
|
119
|
-
description: "An API key that will be supplied in a named cookie."
|
120
|
-
},
|
121
|
-
api_key_header: {
|
122
|
-
type: "apiKey",
|
123
|
-
in: "header",
|
124
|
-
name: "X-API-Key",
|
125
|
-
description: "An API key that will be supplied in a named header."
|
126
|
-
},
|
127
|
-
api_key_query: {
|
128
|
-
type: "apiKey",
|
129
|
-
in: "query",
|
130
|
-
name: "apiKey",
|
131
|
-
description: "An API key that will be supplied in a named query parameter."
|
132
|
-
},
|
133
|
-
basic: {
|
134
|
-
type: "http",
|
135
|
-
scheme: "basic",
|
136
|
-
description: "Basic auth that takes a base64'd combination of `user:password`."
|
137
|
-
},
|
138
|
-
bearer: {
|
139
|
-
type: "http",
|
140
|
-
scheme: "bearer",
|
141
|
-
description: "A bearer token that will be supplied within an `Authorization` header as `bearer <token>`."
|
142
|
-
},
|
143
|
-
bearer_jwt: {
|
144
|
-
type: "http",
|
145
|
-
scheme: "bearer",
|
146
|
-
bearerFormat: "JWT",
|
147
|
-
description: "A bearer token that will be supplied within an `Authorization` header as `bearer <token>`. In this case, the format of the token is specified as JWT."
|
148
|
-
},
|
149
|
-
mutual_tls: {
|
150
|
-
type: "mutualTLS",
|
151
|
-
description: "Requires a specific mutual TLS certificate to use when making an HTTP request."
|
152
|
-
}
|
153
|
-
}.freeze
|
154
41
|
end
|
data/lib/oas_rails/engine.rb
CHANGED
data/lib/oas_rails/version.rb
CHANGED
data/lib/oas_rails.rb
CHANGED
@@ -1,62 +1,22 @@
|
|
1
|
-
require "yard"
|
2
|
-
require "method_source"
|
3
1
|
require "easy_talk"
|
2
|
+
require "oas_core"
|
3
|
+
|
4
|
+
OasCore.configure_yard!
|
4
5
|
|
5
6
|
module OasRails
|
6
7
|
require "oas_rails/version"
|
7
8
|
require "oas_rails/engine"
|
8
9
|
|
9
10
|
autoload :Configuration, "oas_rails/configuration"
|
10
|
-
autoload :OasRoute, "oas_rails/oas_route"
|
11
11
|
autoload :Utils, "oas_rails/utils"
|
12
12
|
autoload :JsonSchemaGenerator, "oas_rails/json_schema_generator"
|
13
13
|
autoload :ActiveRecordExampleFinder, "oas_rails/active_record_example_finder"
|
14
14
|
|
15
15
|
module Builders
|
16
|
-
autoload :OperationBuilder, "oas_rails/builders/operation_builder"
|
17
|
-
autoload :PathItemBuilder, "oas_rails/builders/path_item_builder"
|
18
|
-
autoload :ResponseBuilder, "oas_rails/builders/response_builder"
|
19
|
-
autoload :ResponsesBuilder, "oas_rails/builders/responses_builder"
|
20
|
-
autoload :ContentBuilder, "oas_rails/builders/content_builder"
|
21
|
-
autoload :ParametersBuilder, "oas_rails/builders/parameters_builder"
|
22
|
-
autoload :ParameterBuilder, "oas_rails/builders/parameter_builder"
|
23
|
-
autoload :RequestBodyBuilder, "oas_rails/builders/request_body_builder"
|
24
16
|
autoload :EsquemaBuilder, "oas_rails/builders/esquema_builder"
|
25
17
|
autoload :OasRouteBuilder, "oas_rails/builders/oas_route_builder"
|
26
18
|
end
|
27
19
|
|
28
|
-
# This module contains all the clases that represent a part of the OAS file.
|
29
|
-
module Spec
|
30
|
-
autoload :Hashable, "oas_rails/spec/hashable"
|
31
|
-
autoload :Specable, "oas_rails/spec/specable"
|
32
|
-
autoload :Components, "oas_rails/spec/components"
|
33
|
-
autoload :Parameter, "oas_rails/spec/parameter"
|
34
|
-
autoload :License, "oas_rails/spec/license"
|
35
|
-
autoload :Response, "oas_rails/spec/response"
|
36
|
-
autoload :PathItem, "oas_rails/spec/path_item"
|
37
|
-
autoload :Operation, "oas_rails/spec/operation"
|
38
|
-
autoload :RequestBody, "oas_rails/spec/request_body"
|
39
|
-
autoload :Responses, "oas_rails/spec/responses"
|
40
|
-
autoload :MediaType, "oas_rails/spec/media_type"
|
41
|
-
autoload :Paths, "oas_rails/spec/paths"
|
42
|
-
autoload :Contact, "oas_rails/spec/contact"
|
43
|
-
autoload :Info, "oas_rails/spec/info"
|
44
|
-
autoload :Server, "oas_rails/spec/server"
|
45
|
-
autoload :Tag, "oas_rails/spec/tag"
|
46
|
-
autoload :Specification, "oas_rails/spec/specification"
|
47
|
-
autoload :Reference, "oas_rails/spec/reference"
|
48
|
-
end
|
49
|
-
|
50
|
-
module YARD
|
51
|
-
autoload :RequestBodyTag, 'oas_rails/yard/request_body_tag'
|
52
|
-
autoload :ExampleTag, 'oas_rails/yard/example_tag'
|
53
|
-
autoload :RequestBodyExampleTag, 'oas_rails/yard/request_body_example_tag'
|
54
|
-
autoload :ParameterTag, 'oas_rails/yard/parameter_tag'
|
55
|
-
autoload :ResponseTag, 'oas_rails/yard/response_tag'
|
56
|
-
autoload :ResponseExampleTag, 'oas_rails/yard/response_example_tag'
|
57
|
-
autoload :OasRailsFactory, 'oas_rails/yard/oas_rails_factory'
|
58
|
-
end
|
59
|
-
|
60
20
|
module Extractors
|
61
21
|
autoload :RenderResponseExtractor, 'oas_rails/extractors/render_response_extractor'
|
62
22
|
autoload :RouteExtractor, "oas_rails/extractors/route_extractor"
|
@@ -64,16 +24,22 @@ module OasRails
|
|
64
24
|
end
|
65
25
|
|
66
26
|
class << self
|
27
|
+
OasCore::JsonSchemaGenerator.register_type_parser(
|
28
|
+
->(t) { Utils.active_record_class?(t) },
|
29
|
+
->(type, _required) { Builders::EsquemaBuilder.build_outgoing_schema(klass: type.constantize) }
|
30
|
+
)
|
31
|
+
|
67
32
|
def build
|
68
|
-
|
69
|
-
|
33
|
+
clear_cache
|
34
|
+
OasCore.config = config
|
35
|
+
|
36
|
+
host_routes = Extractors::RouteExtractor.host_routes
|
37
|
+
oas = OasCore::Builders::SpecificationBuilder.new.with_oas_routes(host_routes).build
|
70
38
|
|
71
39
|
oas.to_spec
|
72
40
|
end
|
73
41
|
|
74
|
-
# Configurations for make the OasRails engine Work.
|
75
42
|
def configure
|
76
|
-
OasRails.configure_yard!
|
77
43
|
yield config
|
78
44
|
end
|
79
45
|
|
@@ -81,23 +47,11 @@ module OasRails
|
|
81
47
|
@config ||= Configuration.new
|
82
48
|
end
|
83
49
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
'Parameter' => [:parameter, :with_parameter],
|
90
|
-
'Response' => [:response, :with_response],
|
91
|
-
'Response Example' => [:response_example, :with_response_example],
|
92
|
-
'Endpoint Tags' => [:tags],
|
93
|
-
'Summary' => [:summary],
|
94
|
-
'No Auth' => [:no_auth],
|
95
|
-
'Auth methods' => [:auth, :with_types],
|
96
|
-
'OAS Include' => [:oas_include]
|
97
|
-
}
|
98
|
-
yard_tags.each do |tag_name, (method_name, handler)|
|
99
|
-
::YARD::Tags::Library.define_tag(tag_name, method_name, handler)
|
100
|
-
end
|
50
|
+
def clear_cache
|
51
|
+
return if Rails.env.production?
|
52
|
+
|
53
|
+
MethodSource.clear_cache
|
54
|
+
OasRails::Extractors::RouteExtractor.clear_cache
|
101
55
|
end
|
102
56
|
end
|
103
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oas_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- a-chacon
|
@@ -24,33 +24,19 @@ dependencies:
|
|
24
24
|
- !ruby/object:Gem::Version
|
25
25
|
version: 1.1.2
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
27
|
+
name: oas_core
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
30
|
- - "~>"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 0.4.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
-
- !ruby/object:Gem::Dependency
|
41
|
-
name: yard
|
42
|
-
requirement: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0.9'
|
47
|
-
type: :runtime
|
48
|
-
prerelease: false
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0.9'
|
39
|
+
version: 0.4.0
|
54
40
|
description: OasRails is a Rails engine for generating automatic interactive documentation
|
55
41
|
for your Rails APIs. It generates an OAS 3.1 document and displays it using RapiDoc.
|
56
42
|
email:
|
@@ -80,50 +66,14 @@ files:
|
|
80
66
|
- lib/generators/oas_rails/config/templates/oas_rails_initializer.rb
|
81
67
|
- lib/oas_rails.rb
|
82
68
|
- lib/oas_rails/active_record_example_finder.rb
|
83
|
-
- lib/oas_rails/builders/content_builder.rb
|
84
69
|
- lib/oas_rails/builders/esquema_builder.rb
|
85
70
|
- lib/oas_rails/builders/oas_route_builder.rb
|
86
|
-
- lib/oas_rails/builders/operation_builder.rb
|
87
|
-
- lib/oas_rails/builders/parameter_builder.rb
|
88
|
-
- lib/oas_rails/builders/parameters_builder.rb
|
89
|
-
- lib/oas_rails/builders/path_item_builder.rb
|
90
|
-
- lib/oas_rails/builders/request_body_builder.rb
|
91
|
-
- lib/oas_rails/builders/response_builder.rb
|
92
|
-
- lib/oas_rails/builders/responses_builder.rb
|
93
71
|
- lib/oas_rails/configuration.rb
|
94
72
|
- lib/oas_rails/engine.rb
|
95
|
-
- lib/oas_rails/extractors/oas_route_extractor.rb
|
96
73
|
- lib/oas_rails/extractors/render_response_extractor.rb
|
97
74
|
- lib/oas_rails/extractors/route_extractor.rb
|
98
|
-
- lib/oas_rails/json_schema_generator.rb
|
99
|
-
- lib/oas_rails/oas_route.rb
|
100
|
-
- lib/oas_rails/spec/components.rb
|
101
|
-
- lib/oas_rails/spec/contact.rb
|
102
|
-
- lib/oas_rails/spec/hashable.rb
|
103
|
-
- lib/oas_rails/spec/info.rb
|
104
|
-
- lib/oas_rails/spec/license.rb
|
105
|
-
- lib/oas_rails/spec/media_type.rb
|
106
|
-
- lib/oas_rails/spec/operation.rb
|
107
|
-
- lib/oas_rails/spec/parameter.rb
|
108
|
-
- lib/oas_rails/spec/path_item.rb
|
109
|
-
- lib/oas_rails/spec/paths.rb
|
110
|
-
- lib/oas_rails/spec/reference.rb
|
111
|
-
- lib/oas_rails/spec/request_body.rb
|
112
|
-
- lib/oas_rails/spec/response.rb
|
113
|
-
- lib/oas_rails/spec/responses.rb
|
114
|
-
- lib/oas_rails/spec/server.rb
|
115
|
-
- lib/oas_rails/spec/specable.rb
|
116
|
-
- lib/oas_rails/spec/specification.rb
|
117
|
-
- lib/oas_rails/spec/tag.rb
|
118
75
|
- lib/oas_rails/utils.rb
|
119
76
|
- lib/oas_rails/version.rb
|
120
|
-
- lib/oas_rails/yard/example_tag.rb
|
121
|
-
- lib/oas_rails/yard/oas_rails_factory.rb
|
122
|
-
- lib/oas_rails/yard/parameter_tag.rb
|
123
|
-
- lib/oas_rails/yard/request_body_example_tag.rb
|
124
|
-
- lib/oas_rails/yard/request_body_tag.rb
|
125
|
-
- lib/oas_rails/yard/response_example_tag.rb
|
126
|
-
- lib/oas_rails/yard/response_tag.rb
|
127
77
|
- public/oas-rails-assets/rapidoc-min.js
|
128
78
|
homepage: https://github.com/a-chacon/oas_rails
|
129
79
|
licenses:
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module OasRails
|
2
|
-
module Builders
|
3
|
-
class ContentBuilder
|
4
|
-
def initialize(specification, context)
|
5
|
-
@context = context || :incoming
|
6
|
-
@specification = specification
|
7
|
-
@media_type = Spec::MediaType.new(specification)
|
8
|
-
@content_type = "application/json"
|
9
|
-
end
|
10
|
-
|
11
|
-
def with_schema(schema)
|
12
|
-
@media_type.schema = @specification.components.add_schema(schema)
|
13
|
-
|
14
|
-
self
|
15
|
-
end
|
16
|
-
|
17
|
-
def with_examples(examples)
|
18
|
-
@media_type.examples = @specification.components.add_example(examples)
|
19
|
-
|
20
|
-
self
|
21
|
-
end
|
22
|
-
|
23
|
-
def with_content_type(content_type)
|
24
|
-
@content_type = content_type if content_type.present?
|
25
|
-
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
def with_examples_from_tags(tags)
|
30
|
-
@media_type.examples = @media_type.examples.merge(tags.each_with_object({}).with_index(1) do |(example, result), _index|
|
31
|
-
key = example.text.downcase.gsub(' ', '_')
|
32
|
-
value = {
|
33
|
-
"summary" => example.text,
|
34
|
-
"value" => example.content
|
35
|
-
}
|
36
|
-
result[key] = @specification.components.add_example(value)
|
37
|
-
end)
|
38
|
-
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
def from_model_class(klass)
|
43
|
-
return self unless Utils.active_record_class?(klass)
|
44
|
-
|
45
|
-
model_schema = Builders::EsquemaBuilder.send("build_#{@context}_schema", klass:)
|
46
|
-
model_schema["required"] = []
|
47
|
-
schema = { type: "object", properties: { klass.to_s.downcase => model_schema } }
|
48
|
-
examples = ActiveRecordExampleFinder.new(context: @context).search(klass)
|
49
|
-
@media_type.schema = @specification.components.add_schema(schema)
|
50
|
-
@media_type.examples = @media_type.examples.merge(examples)
|
51
|
-
|
52
|
-
self
|
53
|
-
end
|
54
|
-
|
55
|
-
def build
|
56
|
-
{
|
57
|
-
@content_type => @media_type
|
58
|
-
}
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module OasRails
|
2
|
-
module Builders
|
3
|
-
class OperationBuilder
|
4
|
-
include Extractors::OasRouteExtractor
|
5
|
-
|
6
|
-
def initialize(specification)
|
7
|
-
@specification = specification
|
8
|
-
@operation = Spec::Operation.new(specification)
|
9
|
-
end
|
10
|
-
|
11
|
-
def from_oas_route(oas_route)
|
12
|
-
@operation.summary = extract_summary(oas_route:)
|
13
|
-
@operation.operation_id = extract_operation_id(oas_route:)
|
14
|
-
@operation.description = oas_route.docstring
|
15
|
-
@operation.tags = extract_tags(oas_route:)
|
16
|
-
@operation.security = extract_security(oas_route:)
|
17
|
-
@operation.parameters = ParametersBuilder.new(@specification).from_oas_route(oas_route).build
|
18
|
-
@operation.request_body = RequestBodyBuilder.new(@specification).from_oas_route(oas_route).reference
|
19
|
-
@operation.responses = ResponsesBuilder.new(@specification)
|
20
|
-
.from_oas_route(oas_route)
|
21
|
-
.add_autodiscovered_responses(oas_route)
|
22
|
-
.add_default_responses(oas_route, !@operation.security.empty?).build
|
23
|
-
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
def build
|
28
|
-
@operation
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module OasRails
|
2
|
-
module Builders
|
3
|
-
class ParameterBuilder
|
4
|
-
def initialize(specification)
|
5
|
-
@specification = specification
|
6
|
-
@parameter = Spec::Parameter.new(specification)
|
7
|
-
end
|
8
|
-
|
9
|
-
def from_path(path, param)
|
10
|
-
@parameter.name = param
|
11
|
-
@parameter.in = 'path'
|
12
|
-
@parameter.description = "#{param.split('_')[-1].titleize} of existing #{extract_word_before(path, param).singularize}."
|
13
|
-
|
14
|
-
self
|
15
|
-
end
|
16
|
-
|
17
|
-
def extract_word_before(string, param)
|
18
|
-
regex = %r{/([\w-]+)/\{#{param}\}}
|
19
|
-
match = string.match(regex)
|
20
|
-
match ? match[1] : ""
|
21
|
-
end
|
22
|
-
|
23
|
-
def build
|
24
|
-
@parameter
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module OasRails
|
2
|
-
module Builders
|
3
|
-
class ParametersBuilder
|
4
|
-
def initialize(specification)
|
5
|
-
@specification = specification
|
6
|
-
@parameters = []
|
7
|
-
end
|
8
|
-
|
9
|
-
def from_oas_route(oas_route)
|
10
|
-
parameters_from_tags(tags: oas_route.tags(:parameter))
|
11
|
-
oas_route.path_params.try(:map) do |p|
|
12
|
-
@parameters << ParameterBuilder.new(@specification).from_path(oas_route.path, p).build unless @parameters.any? { |param| param.name.to_s == p.to_s }
|
13
|
-
end
|
14
|
-
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
|
-
def parameters_from_tags(tags:)
|
19
|
-
tags.each do |t|
|
20
|
-
parameter = Spec::Parameter.new(@specification)
|
21
|
-
parameter.name = t.name
|
22
|
-
parameter.in = t.location
|
23
|
-
parameter.required = t.required
|
24
|
-
parameter.schema = t.schema
|
25
|
-
parameter.description = t.text
|
26
|
-
@parameters << parameter
|
27
|
-
end
|
28
|
-
|
29
|
-
self
|
30
|
-
end
|
31
|
-
|
32
|
-
def build
|
33
|
-
@parameters.map do |p|
|
34
|
-
@specification.components.add_parameter(p)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module OasRails
|
2
|
-
module Builders
|
3
|
-
class PathItemBuilder
|
4
|
-
def initialize(specification)
|
5
|
-
@specification = specification
|
6
|
-
@path_item = Spec::PathItem.new(specification)
|
7
|
-
end
|
8
|
-
|
9
|
-
def from_path(path)
|
10
|
-
OasRails.config.route_extractor.host_routes_by_path(path).each do |oas_route|
|
11
|
-
oas_route.verb.downcase.split("|").each do |v|
|
12
|
-
@path_item.add_operation(v, OperationBuilder.new(@specification).from_oas_route(oas_route).build)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
self
|
17
|
-
end
|
18
|
-
|
19
|
-
def build
|
20
|
-
@path_item
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|