class <%= model.camelcase %>
include Swagger::Blocks <%- model_name = "#{model}".split("::").last || model -%> <%- attributes = "#{namespace}::#{model_name.camelcase}Resource".constantize._attributes -%> <%- relationships = "#{namespace}::#{model_name.camelcase}Resource".constantize._relationships -%> swagger_schema :<%= model_name.singularize.underscore %>_index_response do property :data do key :type, :array items do property :id do key :type, :integer end property :type do key :type, :string end <%- if attributes -%> property :attributes do <%- attributes.keys.each do |attribute| -%> property :<%= attribute %> do key :type, :string end <%- end -%> end <%- end -%> <%- if relationships -%> property :relationships do <%- relationships.keys.each do |relationship| -%> property :<%= relationship %> do property :links do property :self do key :type, :string end property :related do key :type, :string end end end <%- end -%> end <%- end -%> end end end swagger_schema :<%= model_name.singularize.underscore %>_show_response do property :data do property :id do key :type, :integer end property :type do key :type, :string end property :links do property :self do key :type, :string end end <%- if attributes -%> property :attributes do <%- attributes.keys.each do |attribute| -%> property :<%= attribute %> do key :type, :string end <%- end -%> end <%- end -%> <%- if relationships -%> property :relationships do <%- relationships.keys.each do |relationship| -%> property :<%= relationship %> do property :links do property :self do key :type, :string end property :related do key :type, :string end end end <%- end -%> end <%- end -%> end end swagger_schema :<%= model_name.singularize.underscore %>_create_response do property :data do property :id do key :type, :integer end property :type do key :type, :string end property :links do property :self do key :type, :string end end <%- if attributes -%> property :attributes do <%- attributes.keys.each do |attribute| -%> property :<%= attribute %> do key :type, :string end <%- end -%> end <%- end -%> <%- if relationships -%> property :relationships do <%- relationships.keys.each do |relationship| -%> property :<%= relationship %> do property :links do property :self do key :type, :string end property :related do key :type, :string end end end <%- end -%> end <%- end -%> end end swagger_schema :<%= model_name.singularize.underscore %>_update_response do property :data do property :id do key :type, :integer end property :type do key :type, :string end property :links do property :self do key :type, :string end end <%- if attributes -%> property :attributes do <%- attributes.keys.each do |attribute| -%> property :<%= attribute %> do key :type, :string end <%- end -%> end <%- end -%> <%- if relationships -%> property :relationships do <%- relationships.keys.each do |relationship| -%> property :<%= relationship %> do property :links do property :self do key :type, :string end property :related do key :type, :string end end end <%- end -%> end <%- end -%> end end swagger_schema :create_<%= model_name.singularize.underscore %> do property :data do property :type do key :type, :string end <%- if attributes -%> property :attributes do <%- attributes.keys.each do |attribute| -%> property :<%= attribute %> do key :type, :string end <%- end -%> end <%- end -%> <%- if relationships -%> property :relationships do <%- relationships.each do |relationship| -%> property :<%= relationship[0] %> do property :data do <%- if relationship[1].class.to_s == "JSONAPI::Relationship::ToOne" -%> property :type do key :type, :string end property :id do key :type, :string end <%- elsif relationship[1].class.to_s == "JSONAPI::Relationship::ToMany" -%> property :type do key :type, :string end property :id do key :type, :string end <%- end -%> end end <%- end -%> end <%- end -%> end end swagger_schema :update_<%= model_name.singularize.underscore %> do property :data do property :type do key :type, :string end <%- if attributes -%> property :attributes do <%- attributes.keys.each do |attribute| -%> property :<%= attribute %> do key :type, :string end <%- end -%> end <%- end -%> end end
<%- relationships = “#{namespace}::#{model_name.camelcase}Resource”.constantize._relationships -%> <%- if relationships -%> <% relationships.keys.each do |relationship| %>
swagger_schema :show_<%= relationship %>_from_<%= model_name.singularize.underscore %>_response do <%- relation_relationships = "#{namespace}::#{relationship.to_s.camelcase.singularize}Resource".constantize._relationships -%> <%- relation_attributes = "#{namespace}::#{relationship.to_s.camelcase.singularize}Resource".constantize._attributes -%> property :data do key :type, :array items do property :id do key :type, :integer end property :type do key :type, :string end <%- if relation_attributes -%> property :attributes do <%- relation_attributes.keys.each do |attribute| -%> property :<%= attribute %> do key :type, :string end <%- end -%> end <%- end -%> <%- if relation_relationships -%> property :relationships do <%- relation_relationships.keys.each do |relation_relationship| -%> property :<%= relation_relationship %> do property :links do property :self do key :type, :string end property :related do key :type, :string end end end <%- end -%> end <%- end -%> end end end swagger_schema :show_<%= relationship %>_from_<%= model_name.singularize.underscore %>_relation_response do property :links do property :self do key :type, :string end property :related do key :type, :string end end property :data do key :type, :array items do property :id do key :type, :integer end property :type do key :type, :string end end end end swagger_schema :put_<%= relationship %>_from_<%= model_name.singularize.underscore %>_relation_response do property :data do key :type, :array items do property :id do key :type, :integer end property :type do key :type, :string end end end end swagger_schema :update_<%= relationship %>_from_<%= model_name.singularize.underscore %>_relation_response do property :data do key :type, :array items do property :id do key :type, :integer end property :type do key :type, :string end end end end swagger_schema :delete_<%= relationship %>_from_<%= model_name.singularize.underscore %>_relation_response do property :data do key :type, :array items do property :id do key :type, :integer end property :type do key :type, :string end end end end
<%- end -%> <%- end -%> end