Class: Graphiti::OpenAPI::Endpoint

Inherits:
EndpointData show all
Defined in:
app/models/graphiti/open_api/endpoint.rb

Instance Method Summary collapse

Methods inherited from EndpointData

#actions

Instance Method Details

#collection_actionsObject



58
59
60
# File 'app/models/graphiti/open_api/endpoint.rb', line 58

def collection_actions
  actions.select(&:collection?)
end

#parametersObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/graphiti/open_api/endpoint.rb', line 35

def parameters
  [].tap do |parameters|
    parameters << {'$ref': "#/components/parameters/#{type}_include"} if resource.relationships?
    parameters << {'$ref': "#/components/parameters/#{type}_sort"}
    parameters << {'$ref': "#/components/parameters/#{type}_fields"}
    resource.relationships.values.map do |relationship|
      relationship.resources.each do |resource|
        parameters << {'$ref': "#/components/parameters/#{resource.type}_fields"}
      end
    end
  end.uniq
end

#pathsObject



24
25
26
27
28
29
30
31
32
33
# File 'app/models/graphiti/open_api/endpoint.rb', line 24

def paths
  {
    path => {
      parameters: parameters,
    }.merge(collection_actions.map(&:operation).inject(&:merge)),
    resource_path => {
      parameters: [{'$ref': "#/components/parameters/#{resource.type}_id"}] + parameters,
    }.merge(resource_actions.map(&:operation).inject(&:merge)),
  }
end

#resourceObject



48
49
50
# File 'app/models/graphiti/open_api/endpoint.rb', line 48

def resource
  resource_actions.first.resource
end

#resource_actionsObject



54
55
56
# File 'app/models/graphiti/open_api/endpoint.rb', line 54

def resource_actions
  actions.reject(&:collection?)
end

#resource_pathObject



20
21
22
# File 'app/models/graphiti/open_api/endpoint.rb', line 20

def resource_path
  File.join(path.to_s, "{id}")
end