Class: Graphiti::OpenAPI::Relationship

Inherits:
RelationshipData show all
Defined in:
app/models/graphiti/open_api/relationship.rb

Instance Method Summary collapse

Instance Method Details

#jsonapi_relationshipObject



42
43
44
45
46
47
48
49
# File 'app/models/graphiti/open_api/relationship.rb', line 42

def jsonapi_relationship
  case type
  when /belongs_to/, "has_one"
    "jsonapi_relationshipToOne"
  else
    "jsonapi_relationshipToMany"
  end
end

#resourceObject



18
19
20
21
# File 'app/models/graphiti/open_api/relationship.rb', line 18

def resource
  return unless __attributes__[:resource]
  schema.resources[__attributes__[:resource]]
end

#resourcesObject



23
24
25
26
# File 'app/models/graphiti/open_api/relationship.rb', line 23

def resources
  return [resource] if __attributes__[:resources].empty?
  __attributes__[:resources].map { |resource| schema.resources[resource] }
end

#to_schemaObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/graphiti/open_api/relationship.rb', line 28

def to_schema
  {
    name => {
      type: :object,
      properties: {
        links: {"$ref": "#/components/schemas/jsonapi_relationshipLinks"},
        data: {'$ref': "#/components/schemas/#{jsonapi_relationship}"},
        meta: {"$ref": "#/components/schemas/jsonapi_meta"},
      },
    },

  }
end