Class: R2OAS::Schema::V3::FromFiles::Components::RequestBodyObject
- Inherits:
-
BaseObject
- Object
- BaseObject
- R2OAS::Schema::V3::FromFiles::Components::RequestBodyObject
- Includes:
- Callable, DeepMethods
- Defined in:
- lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb
Instance Method Summary collapse
- #call_ref_path! ⇒ Object
-
#initialize(doc, ref, opts) ⇒ RequestBodyObject
constructor
A new instance of RequestBodyObject.
- #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) ⇒ RequestBodyObject
Returns a new instance of RequestBodyObject.
18 19 20 21 22 23 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb', line 18 def initialize(doc, ref, opts) super(opts) @doc = doc @parent_ref = Components::RequestBodyRef.new(ref) resolve_dependencies! end |
Instance Method Details
#call_ref_path! ⇒ Object
47 48 49 50 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb', line 47 def call_ref_path! callback = proc { |obj| obj.ref_path } deep_call(@doc, '$ref', callback) end |
#ref_path ⇒ Object
72 73 74 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb', line 72 def ref_path "#/components/requestBodies/#{schema_name}" end |
#resolve_dependencies! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb', line 34 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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb', line 52 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_request_body_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_request_body_name_list.push(@resolved_schema_name) end end @resolved_schema_name end |
#to_doc ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb', line 25 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_request_body, @doc, ref_dup) @doc end |