Class: AnotherApi::OpenAPI::PathBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/another_api/openapi/path_builder.rb

Overview

Builds OpenAPI path items from endpoint configurations.

Operation responses assume the another_api response envelope:

{success: bool, data: <object|array>, options?, metadata?: PaginationMetadata}

If your API ships a different envelope, subclass and override #build_responses (or call SchemaBuilder yourself).

Instance Method Summary collapse

Constructor Details

#initialize(endpoint_configs, known_schemas: nil, configuration: AnotherApi::OpenAPI.configuration) ⇒ PathBuilder

Returns a new instance of PathBuilder.



12
13
14
15
16
# File 'lib/another_api/openapi/path_builder.rb', line 12

def initialize(endpoint_configs, known_schemas: nil, configuration: AnotherApi::OpenAPI.configuration)
  @endpoint_configs = endpoint_configs
  @known_schemas = known_schemas
  @configuration = configuration
end

Instance Method Details

#build_allObject



18
19
20
21
22
23
24
25
26
# File 'lib/another_api/openapi/path_builder.rb', line 18

def build_all
  paths = {}
  @endpoint_configs.each do |endpoint|
    openapi_path = endpoint[:path].gsub(/:(\w+)/, '{\1}')
    paths[openapi_path] ||= {}
    paths[openapi_path][endpoint[:verb]] = build_operation(endpoint)
  end
  paths
end