From 6dcd64ee00690034e419b3341e50a0f222401e72 Mon Sep 17 00:00:00 2001 From: zhandao Date: Sat, 8 Feb 2020 17:15:51 +0800 Subject: [PATCH] FEAT: #61 configurable additionalProperties default value --- lib/oas_objs/schema_obj.rb | 5 ++++- lib/open_api/config.rb | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/oas_objs/schema_obj.rb b/lib/oas_objs/schema_obj.rb index 85c7d46..4d43be9 100644 --- a/lib/oas_objs/schema_obj.rb +++ b/lib/oas_objs/schema_obj.rb @@ -55,7 +55,10 @@ def recg_schema_type(t = self.type) end def additional_properties - return if processed[:type] != 'object' || _addProp.nil? + return if processed[:type] != 'object' + default = Config.additional_properties_default_value_of_type_object + return { additionalProperties: default } if _addProp.nil? && !default.nil? + value = _addProp.in?([true, false]) ? _addProp : SchemaObj.new(_addProp, { }).process { additionalProperties: value } end diff --git a/lib/open_api/config.rb b/lib/open_api/config.rb index 45e0bfa..24ae452 100644 --- a/lib/open_api/config.rb +++ b/lib/open_api/config.rb @@ -24,6 +24,8 @@ module Config cattr_accessor(:file_format) { 'binary' } + cattr_accessor(:additional_properties_default_value_of_type_object) { nil } + def self.docs open_api_docs end