Class: Gitlab::GrapeOpenapi::Converters::PathConverter
- Inherits:
-
Object
- Object
- Gitlab::GrapeOpenapi::Converters::PathConverter
- Defined in:
- lib/gitlab/grape_openapi/converters/path_converter.rb
Defined Under Namespace
Classes: PathVariant
Constant Summary collapse
- RESPONSE_DECLARATIONS =
Grape stores response-entity declarations under :entity (when declared via
entity:on the route) and :success (when declared via thesuccessDSL inside adescblock, in any of its forms). EntityConverter.register handles all three shapes (Class, Hash with :model, Array of those). %i[entity success].freeze
- OPTIONAL_SEGMENT =
A Grape optional path segment: a parenthesised group, e.g.
(/:id). A backslash-escaped paren is a literal character, not a group - OData routes use them, e.g.nuget/v2/Packages\(Id='*package_name'\). /(?<!\\)\(([^()]*)(?<!\\)\)/- ESCAPED_PAREN =
The counterpart of OPTIONAL_SEGMENT: the parenthesis is a literal URL character and only the backslash is Grape pattern syntax, so the escape is dropped once optional segments have been resolved.
/\\([()])/
Class Method Summary collapse
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(routes, schema_registry, request_body_registry) ⇒ PathConverter
constructor
A new instance of PathConverter.
Constructor Details
#initialize(routes, schema_registry, request_body_registry) ⇒ PathConverter
Returns a new instance of PathConverter.
30 31 32 33 34 35 36 |
# File 'lib/gitlab/grape_openapi/converters/path_converter.rb', line 30 def initialize(routes, schema_registry, request_body_registry) @routes = routes @schema_registry = schema_registry @request_body_registry = request_body_registry @config = Gitlab::GrapeOpenapi.configuration @inherited_path_params = {} end |
Class Method Details
.convert(routes, schema_registry, request_body_registry) ⇒ Object
26 27 28 |
# File 'lib/gitlab/grape_openapi/converters/path_converter.rb', line 26 def self.convert(routes, schema_registry, request_body_registry) new(routes, schema_registry, request_body_registry).convert end |
Instance Method Details
#convert ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gitlab/grape_openapi/converters/path_converter.rb', line 38 def convert register_inherited_path_params paths = {} grouped_routes.each do |path_key, routes_for_path| path_variants(path_key, routes_for_path.first).each do |variant| paths[variant.key] ||= {} paths[variant.key].merge!(build_path_item(routes_for_path, variant)) end end paths.reject { |_path, operations| operations.empty? } end |