diff --git a/lib/openapi_contracts/parser.rb b/lib/openapi_contracts/parser.rb index 1bed63c..41c22b4 100644 --- a/lib/openapi_contracts/parser.rb +++ b/lib/openapi_contracts/parser.rb @@ -2,7 +2,7 @@ module OpenapiContracts class Parser autoload :Transformers, 'openapi_contracts/parser/transformers' - TRANSFORMERS = [Transformers::Pointer].freeze + TRANSFORMERS = [Transformers::Nullable, Transformers::Pointer].freeze def self.call(dir, filename) new(dir.join(filename)).parse diff --git a/lib/openapi_contracts/parser/transformers/nullable.rb b/lib/openapi_contracts/parser/transformers/nullable.rb new file mode 100644 index 0000000..fac0a0f --- /dev/null +++ b/lib/openapi_contracts/parser/transformers/nullable.rb @@ -0,0 +1,10 @@ +module OpenapiContracts::Parser::Transformers + class Nullable < Base + def call(object) + return unless object['type'].present? && object['nullable'] == true + + object.delete('nullable') + object['type'] = [object['type'], 'null'] + end + end +end