mirror of
https://github.com/ditkrg/jsonapi-swagger.git
synced 2026-01-24 14:56:50 +00:00
Compare commits
No commits in common. "master" and "v0.8.1" have entirely different histories.
@ -162,7 +162,7 @@ module Jsonapi
|
|||||||
def tt(key, options={})
|
def tt(key, options={})
|
||||||
options[:scope] = :jsonapi_swagger
|
options[:scope] = :jsonapi_swagger
|
||||||
options[:default] = key.to_s.humanize
|
options[:default] = key.to_s.humanize
|
||||||
I18n.t(key, **options)
|
I18n.t(key, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def safe_encode(content)
|
def safe_encode(content)
|
||||||
|
|||||||
@ -3,13 +3,31 @@ module Jsonapi
|
|||||||
module Swagger
|
module Swagger
|
||||||
class Resource
|
class Resource
|
||||||
def self.with(model_class_name)
|
def self.with(model_class_name)
|
||||||
@resource_class = model_class_name.safe_constantize
|
if Object.const_defined?("#{model_class_name}Resource")
|
||||||
unless @resource_class < JSONAPI::Serializable::Resource
|
@resource_class = "#{model_class_name}Resource".safe_constantize
|
||||||
raise Jsonapi::Swagger::Error, "#{@resource_class.class} is not Subclass of JSONAPI::Serializable::Resource!"
|
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
|
end
|
||||||
require 'jsonapi/swagger/resources/serializable_resource'
|
|
||||||
return Jsonapi::Swagger::SerializableResource.new(@resource_class)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
module Jsonapi
|
module Jsonapi
|
||||||
module Swagger
|
module Swagger
|
||||||
VERSION = '0.8.3'
|
VERSION = '0.8.1'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user