require 'swagger_helper' RSpec.describe '<%= resouces_name %>', type: :request do let(:include) {''} #see https://github.com/domaindrivendev/rswag/issues/188 before(:each) do @<%= model_name %> = create :<%= model_name %> end path '/<%= route_resouces %>' do get '<%= route_resouces %> <%= t(:list) %>' do tags '<%= route_resouces %>' produces 'application/vnd.api+json' parameter name: :'page[number]', in: :query, type: :string, description: '<%= t(:page_num) %>', required: false parameter name: :include, in: :query, type: :string, description: '<%= t(:include_related_data) %>', required: false parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false <% relationships.each_value do |relation| -%> parameter name: :'fields[<%= relation.class_name.tableize %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false <% end -%> response '200', '<%= t(:get_list) %>' do schema type: :object, properties: { data: { type: :array, items: { type: :object, properties: { id: { type: :string, description: 'ID'}, links: { type: :object, properties: { self: { type: :string, description: '<%= t(:detail_link) %>'}, }, description: '<%= t(:detail_link) %>' }, attributes: { type: :object, properties: { <% attributes.each_key.each do |attr| -%> <%= attr %>: { type: :<%= columns_with_comment[attr][:type] %>, <%if columns_with_comment[attr][:is_array] -%> items: { type: :<%= columns_with_comment[attr][:items_type] %>},<% end -%> 'x-nullable': <%= columns_with_comment[attr][:nullable] %>, description: '<%= columns_with_comment[attr][:comment] %>'}, <% end -%> }, description: '<%= t(:attributes) %>' }, relationships: { type: :object, properties: { <% relationships.each do |relation_name, relation| -%> <% relation_name_camelize = relation_name.to_s.camelize -%> <%= relation_name %>: { type: :object, properties: { links: { type: :object, properties: { self: { type: :string, description: '<%= t(:associate_list_link, model: relation_name_camelize) %>' }, related: { type: :string, description: '<%= t(:related_link, model: relation_name_camelize) %>' }, }, description: '<%= t(:related_link, model: relation_name_camelize)%>' }, }, description: '<%= t(:related_model, model: relation_name_camelize)%>' }, <% end -%> }, description: '<%= t(:associate_data) %>' } }, }, description: '<%= t(:data) %>' }, meta: { type: :object, properties: { record_count: { type: :integer, description: '<%= t(:record_count) %>'}, page_count: { type: :integer, description: '<%= t(:page_count) %>'}, }, description: '<%= t(:meta) %>' }, links: { type: :object, properties: { first: { type: :string, description: '<%= t(:first_page_link) %>'}, next: { type: :string, description: '<%= t(:next_page_link) %>'}, last: { type: :string, description: '<%= t(:last_page_link) %>'}, }, description: '<%= t(:page_links) %>' }, }, required: [:data] run_test! end end end path '/<%= route_resouces %>/{id}' do get '<%= route_resouces %> <%= t(:detail) %>' do tags '<%= route_resouces %>' produces 'application/vnd.api+json' parameter name: :id, in: :path, type: :integer, description: 'ID', required: true parameter name: :include, in: :query, type: :string, description: '<%= t(:include_related_data) %>', required: false parameter name: :'fields[<%= route_resouces %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false <% relationships.each_value do |relation| -%> parameter name: :'fields[<%= relation.class_name.tableize %>]', in: :query, type: :string, description: '<%= t(:display_field) %>', required: false <% end -%> response '200', '<%= t(:get_detail) %>' do schema type: :object, properties: { data: { type: :object, properties: { id: { type: :string, description: 'ID'}, type: { type: :string, description: 'Type'}, links: { type: :object, properties: { self: { type: :string, description: '<%= t(:detail_link) %>'}, }, description: '<%= t(:detail_link) %>' }, attributes: { type: :object, properties: { <% attributes.each_key.each do |attr| -%> <%= attr %>: { type: :<%= columns_with_comment[attr][:type] %>, <%if columns_with_comment[attr][:is_array] -%> items: { type: :<%= columns_with_comment[attr][:items_type] %>},<% end -%> 'x-nullable': <%= columns_with_comment[attr][:nullable] %>, description: '<%= columns_with_comment[attr][:comment] %>'}, <% end -%> }, description: '<%= t(:attributes) %>' }, relationships: { type: :object, properties: { <% relationships.each do |relation_name, relation| -%> <% relation_name_camelize = relation_name.to_s.camelize -%> <%= relation_name %>: { type: :object, properties: { links: { type: :object, properties: { self: { type: :string, description: '<%= t(:associate_list_link, model: relation_name_camelize) %>' }, related: { type: :string, description: '<%= t(:related_link, model: relation_name_camelize )%>' }, }, description: '<%= t(:related_link, model: relation_name_camelize) %>' }, }, description: '<%= t(:related_link, model: relation_name_camelize) %>' }, <% end -%> }, description: '<%= t(:associate_data) %>' } }, description: '<%= t(:data) %>' }, }, required: [:data] let(:id) { @<%= model_name %>.id } run_test! end end end <% unless resource_klass.immutable -%> <% end -%> end