Class: Apia::OpenApi::Objects::Path

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/apia/open_api/objects/path.rb

Instance Method Summary collapse

Methods included from Helpers

#add_to_components_schemas, #convert_type_to_open_api_data_type, #formatted_description, #generate_array_schema, #generate_id_from_definition, #generate_scalar_schema, #generate_schema_ref

Constructor Details

#initialize(spec:, path_ids:, route:, name:, api_authenticator:) ⇒ Path

Returns a new instance of Path.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/apia/open_api/objects/path.rb', line 32

def initialize(spec:, path_ids:, route:, name:, api_authenticator:)
  @spec = spec
  @path_ids = path_ids
  @route = route
  @api_authenticator = api_authenticator
  @route_spec = {
    operationId: convert_route_to_id,
    summary: @route.endpoint.definition.name,
    description: @route.endpoint.definition.description,
    tags: route.group ? get_group_tags(route.group) : [name],
    security: []
  }
end

Instance Method Details

#add_to_specObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/apia/open_api/objects/path.rb', line 46

def add_to_spec
  add_scopes_description
  add_scopes_security
  path = @route.path

  if @route.request_method == :get
    add_parameters
  else
    add_request_body
  end

  path = "/#{path}"
  # Remove the `:` from the url parameters in the path
  # This is because some tools based on the OpenAPI spec don't like the `:` in the path
  path = path.gsub(/:([^\/]+)/, '\1')

  @spec[:paths][path] ||= {}
  @spec[:paths][path][@route.request_method.to_s] = @route_spec

  add_responses
end