Class: R2OAS::Schema::V3::FromFiles::Components::SchemaObject
- Inherits:
-
BaseObject
- Object
- BaseObject
- R2OAS::Schema::V3::FromFiles::Components::SchemaObject
- Includes:
- Callable, DeepMethods
- Defined in:
- lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb
Instance Method Summary collapse
- #call_ref_path! ⇒ Object
-
#initialize(doc, ref, opts) ⇒ SchemaObject
constructor
A new instance of SchemaObject.
- #ref_path ⇒ Object
- #resolve_dependencies! ⇒ Object
- #schema_name ⇒ Object
- #to_doc ⇒ Object
Methods included from DeepMethods
Methods included from Callable
Methods inherited from BaseObject
Constructor Details
#initialize(doc, ref, opts) ⇒ SchemaObject
Returns a new instance of SchemaObject.
17 18 19 20 21 22 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb', line 17 def initialize(doc, ref, opts) super(opts) @doc = doc @parent_ref = Components::SchemaRef.new(ref) resolve_dependencies! end |
Instance Method Details
#call_ref_path! ⇒ Object
46 47 48 49 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb', line 46 def call_ref_path! callback = proc { |obj| obj.ref_path } deep_call(@doc, '$ref', callback) end |
#ref_path ⇒ Object
71 72 73 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb', line 71 def ref_path "#/components/schemas/#{schema_name}" end |
#resolve_dependencies! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb', line 33 def resolve_dependencies! deep_replace!(@doc, '$ref') do |ref_path| schema_obj, schema_type, pure_schema_name = ref_path.split('/').slice(1..-1) schema_doc = root_doc&.fetch(schema_obj, nil)&.fetch(schema_type, nil)&.fetch(pure_schema_name, nil) || {} ref = create_child_ref(pure_schema_name) obj = Components::SchemaObject.new(schema_doc, ref, opts) obj_store.add('components/schemas', pure_schema_name, obj) obj end end |
#schema_name ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb', line 51 def schema_name return @resolved_schema_name if @resolved_schema_name.present? before_schema_name = ref_dup[:schema_name] _ref_dup = ref_dup execute_transform_plugins(:components_schema_name, _ref_dup) @resolved_schema_name = _ref_dup[:schema_name] if before_schema_name != @resolved_schema_name if reserved_schema_name_list.include?(@resolved_schema_name) raise DepulicateSchemaNameError, "Transformed schema name: '#{@resolved_schema_name}' cannot be used. It already exists." else obj_store.appended_components_schema_name_list.push(@resolved_schema_name) end end @resolved_schema_name end |
#to_doc ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb', line 24 def to_doc call_ref_path! # MEMO: # If it is overwritten, it may lead to unexpected problems, so give a copy execute_transform_plugins(:components_schema, @doc, ref_dup) @doc end |