Compare commits

..

No commits in common. "master" and "v0.8.0" have entirely different histories.

4 changed files with 30 additions and 13 deletions

View File

@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
spec.licenses = ['MIT']
spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'rake', '>= 12.3.3'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rubocop', '~> 0.67'
spec.add_development_dependency 'rswag', '~>2.0'
end

View File

@ -132,15 +132,14 @@ module Jsonapi
end
model_klass.columns.each do |col|
col_name = transform_method ? col.name.send(transform_method) : col.name
is_array = col.respond_to?(:array) ? col.array : false
clos[col_name.to_sym] = { type: swagger_type(col), items_type: col.type, is_array: is_array, nullable: col.null, comment: col.comment }
clos[col_name.to_sym] = { type: swagger_type(col), items_type: col.type, is_array: col.array, nullable: col.null, comment: col.comment }
clos[col_name.to_sym][:comment] = safe_encode(col.comment) if need_encoding
end
end
end
def swagger_type(column)
return 'array' if column.respond_to?(:array) && column.array
return 'array' if column.array
case column.type
when :bigint, :integer then 'integer'
@ -162,7 +161,7 @@ module Jsonapi
def tt(key, options={})
options[:scope] = :jsonapi_swagger
options[:default] = key.to_s.humanize
I18n.t(key, **options)
I18n.t(key, options)
end
def safe_encode(content)

View File

@ -3,12 +3,30 @@ module Jsonapi
module Swagger
class Resource
def self.with(model_class_name)
@resource_class = model_class_name.safe_constantize
unless @resource_class < JSONAPI::Serializable::Resource
raise Jsonapi::Swagger::Error, "#{@resource_class.class} is not Subclass of JSONAPI::Serializable::Resource!"
if Object.const_defined?("#{model_class_name}Resource")
@resource_class = "#{model_class_name}Resource".safe_constantize
unless @resource_class < JSONAPI::Resource
raise Jsonapi::Swagger::Error, "#{@resource_class.class} is not Subclass of JSONAPI::Resource!"
end
require 'jsonapi/swagger/resources/jsonapi_resource'
return Jsonapi::Swagger::JsonapiResource.new(@resource_class)
elsif Object.const_defined?("Serializable#{model_class_name}")
@resource_class = "Serializable#{model_class_name}".safe_constantize
unless @resource_class < JSONAPI::Serializable::Resource
raise Jsonapi::Swagger::Error, "#{@resource_class.class} is not Subclass of JSONAPI::Serializable::Resource!"
end
require 'jsonapi/swagger/resources/serializable_resource'
return Jsonapi::Swagger::SerializableResource.new(@resource_class)
elsif Object.const_defined?("#{model_class_name}Serializer")
@resource_class = "#{model_class_name}Serializer".safe_constantize
unless @resource_class < FastJsonapi::ObjectSerializer
raise Jsonapi::Swagger::Error, "#{@resource_class.class} is not Subclass of FastJsonapi::ObjectSerializer!"
end
require 'jsonapi/swagger/resources/fast_jsonapi_resource'
return Jsonapi::Swagger::FastJsonapiResource.new(@resource_class)
else
raise Jsonapi::Swagger::Error, "#{model_class_name} not support!"
end
require 'jsonapi/swagger/resources/serializable_resource'
return Jsonapi::Swagger::SerializableResource.new(@resource_class)
end
end
end

View File

@ -2,6 +2,6 @@
module Jsonapi
module Swagger
VERSION = '0.8.3'
VERSION = '0.8.0'
end
end