Module: JsonapiSwaggerHelpers::Writeable
- Included in:
- CreateAction, DestroyAction, UpdateAction
- Defined in:
- lib/jsonapi_swagger_helpers/writeable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #action_name ⇒ Object
- #all_tags ⇒ Object
- #context ⇒ Object
- #default_description ⇒ Object
- #define_schema ⇒ Object
- #generate ⇒ Object
- #initialize(node, controller, description: nil, tags: []) ⇒ Object
- #operation_id ⇒ Object
- #payload_tags ⇒ Object
- #strong_resource ⇒ Object
- #util ⇒ Object
Class Method Details
.included(klass) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 3 def self.included(klass) klass.class_eval do attr_reader :node, :controller, :resource, :description, :tags end end |
Instance Method Details
#action_name ⇒ Object
25 26 27 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 25 def action_name raise 'override me' end |
#all_tags ⇒ Object
37 38 39 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 37 def + end |
#context ⇒ Object
51 52 53 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 51 def context JsonapiSwaggerHelpers.docs_controller end |
#default_description ⇒ Object
29 30 31 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 29 def default_description "#{action_name.to_s.capitalize} Action" end |
#define_schema ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 59 def define_schema _self = self context.send(:swagger_schema, :"#{strong_resource.name}_#{action_name}") do _self.strong_resource.attributes.each_pair do |attribute, config| property attribute do key :type, config[:type] # TODO - swagger type? end end end _self.strong_resource.relations.each_pair do |relation_name, relation_config| context.send(:swagger_schema, :"#{strong_resource.name}_#{relation_name}_#{action_name}") do relation_config[:resource].attributes.each_pair do |attribute, config| property attribute do key :type, config[:type] # TODO - swagger type? end end end end end |
#generate ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 80 def generate _self = self define_schema @node.operation :post do key :description, _self.description key :operationId, _self.operation_id key :tags, _self. end end |
#initialize(node, controller, description: nil, tags: []) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 13 def initialize(node, controller, description: nil, tags: []) @node = node @controller = controller @resource = controller._jsonapi_compliable @description = description || default_description @tags = end |
#operation_id ⇒ Object
33 34 35 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 33 def operation_id "#{controller.name.gsub('::', '-')}-#{action_name}" end |
#payload_tags ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 41 def = [:"payload-#{strong_resource.name}_#{action_name}"] strong_resource.relations.each_pair do |relation_name, relation_config| << :"payload-#{strong_resource.name}_#{relation_name}_#{action_name}" end end |
#strong_resource ⇒ Object
55 56 57 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 55 def strong_resource controller._strong_resources[action_name] end |
#util ⇒ Object
21 22 23 |
# File 'lib/jsonapi_swagger_helpers/writeable.rb', line 21 def util JsonapiSwaggerHelpers::Util end |