Class: Meta::JsonSchema::ObjectSchema
- Inherits:
-
BaseSchema
- Object
- BaseSchema
- Meta::JsonSchema::ObjectSchema
- Defined in:
- lib/meta/json_schema/schemas/object_schema.rb
Constant Summary collapse
- USER_OPTIONS_CHECKER =
Utils::KeywordArgs::Builder.build do permit_extras true key :scope, normalizer: ->(value) { raise ArgumentError, 'scope 选项不可传递 nil' if value.nil? value = [value] unless value.is_a?(Array) value } end
Constants inherited from BaseSchema
Instance Attribute Summary collapse
-
#locked_options ⇒ Object
readonly
Returns the value of attribute locked_options.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Attributes inherited from BaseSchema
Instance Method Summary collapse
-
#dup(options) ⇒ Object
复制一个新的 ObjectSchema,只有 options 不同.
- #filter(object_value, user_options = {}) ⇒ Object
-
#initialize(properties: nil, options: {}, locked_options: {}, schema_name_resolver: proc { nil }) ⇒ ObjectSchema
constructor
A new instance of ObjectSchema.
- #locked_exclude ⇒ Object
- #locked_scope ⇒ Object
-
#merge_other_properties(properties) ⇒ Object
合并其他的属性,并返回一个新的 ObjectSchema.
- #resolve_name(stage) ⇒ Object
- #to_schema_doc(user_options = {}) ⇒ Object
Methods inherited from BaseSchema
#filter?, #find_schema, #if?, #scoped, #staged, #to_schema, #value?
Constructor Details
#initialize(properties: nil, options: {}, locked_options: {}, schema_name_resolver: proc { nil }) ⇒ ObjectSchema
Returns a new instance of ObjectSchema.
20 21 22 23 24 25 26 27 |
# File 'lib/meta/json_schema/schemas/object_schema.rb', line 20 def initialize(properties: nil, options: {}, locked_options: {}, schema_name_resolver: proc { nil }) super() @properties = properties || Properties.new({}) # property 包含 stage,stage 包含 scope、schema @properties = Properties.new(@properties) if @properties.is_a?(Hash) = USER_OPTIONS_CHECKER.check( || {}) @schema_name_resolver = schema_name_resolver || proc { nil } end |
Instance Attribute Details
#locked_options ⇒ Object (readonly)
Returns the value of attribute locked_options.
8 9 10 |
# File 'lib/meta/json_schema/schemas/object_schema.rb', line 8 def end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
8 9 10 |
# File 'lib/meta/json_schema/schemas/object_schema.rb', line 8 def properties @properties end |
Instance Method Details
#dup(options) ⇒ Object
复制一个新的 ObjectSchema,只有 options 不同
30 31 32 33 34 35 36 37 |
# File 'lib/meta/json_schema/schemas/object_schema.rb', line 30 def dup() self.class.new( properties: properties, options: , locked_options: , schema_name_resolver: @schema_name_resolver ) end |
#filter(object_value, user_options = {}) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/meta/json_schema/schemas/object_schema.rb', line 39 def filter(object_value, = {}) # 合并 user_options = USER_OPTIONS_CHECKER.check() = (, ) if super end |
#locked_exclude ⇒ Object
73 74 75 |
# File 'lib/meta/json_schema/schemas/object_schema.rb', line 73 def locked_exclude && [:exclude] end |
#locked_scope ⇒ Object
69 70 71 |
# File 'lib/meta/json_schema/schemas/object_schema.rb', line 69 def locked_scope && [:scope] end |
#merge_other_properties(properties) ⇒ Object
合并其他的属性,并返回一个新的 ObjectSchema
47 48 49 |
# File 'lib/meta/json_schema/schemas/object_schema.rb', line 47 def merge_other_properties(properties) ObjectSchema.new(properties: self.properties.merge(properties)) end |
#resolve_name(stage) ⇒ Object
51 52 53 54 |
# File 'lib/meta/json_schema/schemas/object_schema.rb', line 51 def resolve_name(stage) locked_scopes = ( || {})[:scope] || [] @schema_name_resolver.call(stage, locked_scopes) end |
#to_schema_doc(user_options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/meta/json_schema/schemas/object_schema.rb', line 56 def to_schema_doc( = {}) = USER_OPTIONS_CHECKER.check() = (, ) if schema = { type: 'object' } schema[:description] = [:description] if [:description] properties, required_keys = @properties.to_swagger_doc(**) schema[:properties] = properties unless properties.empty? schema[:required] = required_keys unless required_keys.empty? schema end |