mirror of
https://github.com/ditkrg/jsonapi-swagger.git
synced 2026-01-23 22:36:50 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 352fd3da35 | |||
| bee05fea2b | |||
| b301d53f02 | |||
| c7eaef79ab | |||
|
|
8efe5ff488 | ||
|
|
1b01e6a31a | ||
|
|
a0f7422793 | ||
|
|
9eae4f0b0b |
@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
||||
spec.licenses = ['MIT']
|
||||
|
||||
spec.add_development_dependency 'bundler', '~> 2.0'
|
||||
spec.add_development_dependency 'rake', '~> 10.0'
|
||||
spec.add_development_dependency 'rake', '>= 12.3.3'
|
||||
spec.add_development_dependency 'rubocop', '~> 0.67'
|
||||
spec.add_development_dependency 'rswag', '~>2.0'
|
||||
end
|
||||
|
||||
@ -132,14 +132,15 @@ module Jsonapi
|
||||
end
|
||||
model_klass.columns.each do |col|
|
||||
col_name = transform_method ? col.name.send(transform_method) : col.name
|
||||
clos[col_name.to_sym] = { type: swagger_type(col), items_type: col.type, is_array: col.array, nullable: col.null, comment: col.comment }
|
||||
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][:comment] = safe_encode(col.comment) if need_encoding
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def swagger_type(column)
|
||||
return 'array' if column.array
|
||||
return 'array' if column.respond_to?(:array) && column.array
|
||||
|
||||
case column.type
|
||||
when :bigint, :integer then 'integer'
|
||||
@ -161,7 +162,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)
|
||||
|
||||
@ -3,30 +3,12 @@ module Jsonapi
|
||||
module Swagger
|
||||
class Resource
|
||||
def self.with(model_class_name)
|
||||
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!"
|
||||
@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!"
|
||||
end
|
||||
require 'jsonapi/swagger/resources/serializable_resource'
|
||||
return Jsonapi::Swagger::SerializableResource.new(@resource_class)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -2,6 +2,6 @@
|
||||
|
||||
module Jsonapi
|
||||
module Swagger
|
||||
VERSION = '0.8.0'
|
||||
VERSION = '0.8.3'
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user