Class: Graphiti::OpenAPI::Action
Constant Summary
collapse
- METHODS_MAP =
Hash.new do |hash, key|
hash[key] = key
end.merge(
index: :get,
show: :get,
create: :post,
update: :put,
destroy: :delete,
)
- SUMMARIES_MAP =
Hash.new do |hash, key|
hash[key] = "#{key.capitalize} resource"
end.merge(
index: "List resources",
show: "Fetch resource",
create: "Create resource",
update: "Update resource",
destroy: "Destroy resource",
)
- OPERATIONS_MAP =
Hash.new do |hash, key|
hash[key] = key
end.merge(
index: :list,
show: :get,
destroy: :delete,
)
Instance Method Summary
collapse
Methods included from Parameters
#array_enum, #parameter, #path_parameter, #query_parameter
Instance Method Details
#collection? ⇒ Boolean
52
53
54
|
# File 'app/models/graphiti/open_api/action.rb', line 52
def collection?
%i[index create].include?(action)
end
|
#delete? ⇒ Boolean
95
96
97
|
# File 'app/models/graphiti/open_api/action.rb', line 95
def delete?
action == :destroy
end
|
#method ⇒ Object
68
69
70
|
# File 'app/models/graphiti/open_api/action.rb', line 68
def method
METHODS_MAP[action]
end
|
#modify? ⇒ Boolean
64
65
66
|
# File 'app/models/graphiti/open_api/action.rb', line 64
def modify?
%i[create update].include?(action)
end
|
#operation ⇒ Object
80
81
82
|
# File 'app/models/graphiti/open_api/action.rb', line 80
def operation
{method => operation_description}
end
|
#operation_description ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'app/models/graphiti/open_api/action.rb', line 84
def operation_description
{
operationId: operation_id,
summary: summary,
tags: tags,
responses: responses,
}.tap do |desc|
desc[:requestBody] = {'$ref': "#/components/requestBodies/#{resource.type}"} if modify?
end
end
|
#operation_id ⇒ Object
76
77
78
|
# File 'app/models/graphiti/open_api/action.rb', line 76
def operation_id
"#{OPERATIONS_MAP[action]}_#{action == :index ? model_name.plural : model_name.singular}".camelize(:lower)
end
|
#read? ⇒ Boolean
60
61
62
|
# File 'app/models/graphiti/open_api/action.rb', line 60
def read?
%i[index show].include?(action)
end
|
#resource ⇒ Object
46
47
48
|
# File 'app/models/graphiti/open_api/action.rb', line 46
def resource
schema.resources[attributes[:resource]]
end
|
#resource? ⇒ Boolean
56
57
58
|
# File 'app/models/graphiti/open_api/action.rb', line 56
def resource?
!collection?
end
|
#summary ⇒ Object
72
73
74
|
# File 'app/models/graphiti/open_api/action.rb', line 72
def summary
SUMMARIES_MAP[action].gsub(/\bresources\b/, type.humanize).gsub(/\bresource\b/, type.singularize.humanize)
end
|