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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/lib/oas_rails/builders/oas_route_builder.rb +2 -3
  4. data/lib/oas_rails/configuration.rb +14 -127
  5. data/lib/oas_rails/engine.rb +0 -5
  6. data/lib/oas_rails/version.rb +1 -1
  7. data/lib/oas_rails.rb +18 -64
  8. metadata +4 -54
  9. data/lib/oas_rails/builders/content_builder.rb +0 -62
  10. data/lib/oas_rails/builders/operation_builder.rb +0 -32
  11. data/lib/oas_rails/builders/parameter_builder.rb +0 -28
  12. data/lib/oas_rails/builders/parameters_builder.rb +0 -39
  13. data/lib/oas_rails/builders/path_item_builder.rb +0 -24
  14. data/lib/oas_rails/builders/request_body_builder.rb +0 -61
  15. data/lib/oas_rails/builders/response_builder.rb +0 -40
  16. data/lib/oas_rails/builders/responses_builder.rb +0 -81
  17. data/lib/oas_rails/extractors/oas_route_extractor.rb +0 -66
  18. data/lib/oas_rails/json_schema_generator.rb +0 -132
  19. data/lib/oas_rails/oas_route.rb +0 -21
  20. data/lib/oas_rails/spec/components.rb +0 -96
  21. data/lib/oas_rails/spec/contact.rb +0 -18
  22. data/lib/oas_rails/spec/hashable.rb +0 -39
  23. data/lib/oas_rails/spec/info.rb +0 -66
  24. data/lib/oas_rails/spec/license.rb +0 -18
  25. data/lib/oas_rails/spec/media_type.rb +0 -24
  26. data/lib/oas_rails/spec/operation.rb +0 -25
  27. data/lib/oas_rails/spec/parameter.rb +0 -37
  28. data/lib/oas_rails/spec/path_item.rb +0 -33
  29. data/lib/oas_rails/spec/paths.rb +0 -26
  30. data/lib/oas_rails/spec/reference.rb +0 -16
  31. data/lib/oas_rails/spec/request_body.rb +0 -21
  32. data/lib/oas_rails/spec/response.rb +0 -20
  33. data/lib/oas_rails/spec/responses.rb +0 -25
  34. data/lib/oas_rails/spec/server.rb +0 -17
  35. data/lib/oas_rails/spec/specable.rb +0 -54
  36. data/lib/oas_rails/spec/specification.rb +0 -50
  37. data/lib/oas_rails/spec/tag.rb +0 -18
  38. data/lib/oas_rails/yard/example_tag.rb +0 -12
  39. data/lib/oas_rails/yard/oas_rails_factory.rb +0 -169
  40. data/lib/oas_rails/yard/parameter_tag.rb +0 -14
  41. data/lib/oas_rails/yard/request_body_example_tag.rb +0 -11
  42. data/lib/oas_rails/yard/request_body_tag.rb +0 -16
  43. data/lib/oas_rails/yard/response_example_tag.rb +0 -12
  44. 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: 44055a7f28caf66419b7450458c652bfa88b28459669f856b35a83dc4a25f228
4
- data.tar.gz: 188cafd5d14c17fe5055850af9fd712d086f135a20aa70e9640a29721a7656cf
3
+ metadata.gz: d60145b23d4b27b3fc5f1f58e024cb4ea0df37c6d10932d64b9bc5ce08641e83
4
+ data.tar.gz: '099cce8d88c18549bded9eaa2e3f4b9176a1a934f2a511bb3d6af567c18822ed'
5
5
  SHA512:
6
- metadata.gz: 927cdf58a97c24ad7e6956bc09086b1baa221ec796cea3ccb08fc988a6ed92a4707097b956a00ac888cefaea4e238f48c49c6b197b96b08b4f48f0c6fd194c40
7
- data.tar.gz: b64572ca08987c1461fe2ae799a3771021dc534e18a35b0f394181ad2fdfe7d8a46dd6124caf56aff2745476c2eacc795df72ca3b6ddbc73fce4146dc581a023
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 [OasRailsBook](http://a-chacon.com/oas_rails)
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
- method: method,
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 :info,
4
- :layout,
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
- @info = Spec::Info.new
22
- @layout = false
23
- @servers = default_servers
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
- @include_mode = :all
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
- define_singleton_method("response_body_of_#{response}") do
55
- instance_variable_get(variable_name) || @response_body_of_default
56
- end
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 default_servers
67
- [Spec::Server.new(url: "http://localhost:3000", description: "Rails Default Development Server")]
68
- end
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
- def tags=(value)
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
@@ -1,11 +1,6 @@
1
1
  module OasRails
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace OasRails
4
- config.to_prepare do
5
- ActiveSupport::Inflector.inflections(:en) do |inflect|
6
- inflect.acronym 'YARD'
7
- end
8
- end
9
4
 
10
5
  config.app_middleware.use(
11
6
  Rack::Static,
@@ -1,3 +1,3 @@
1
1
  module OasRails
2
- VERSION = "0.16.0"
2
+ VERSION = "0.17.0"
3
3
  end
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
- oas = Spec::Specification.new
69
- oas.build
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 configure_yard!
85
- ::YARD::Tags::Library.default_factory = YARD::OasRailsFactory
86
- yard_tags = {
87
- 'Request body' => [:request_body, :with_request_body],
88
- 'Request body Example' => [:request_body_example, :with_request_body_example],
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.16.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: method_source
27
+ name: oas_core
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '1.0'
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: '1.0'
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