From 9e4b97d422cbd05ab05160872366add6536d8c44 Mon Sep 17 00:00:00 2001 From: Konstantin Munteanu Date: Fri, 15 Sep 2023 10:07:18 +0200 Subject: [PATCH] Revert "Nullable transformer is obsolete (#68)" This reverts commit d6c120d5ebba1a6880fbc85f4f4da5ea541eeef7. --- lib/openapi_contracts/parser.rb | 2 +- lib/openapi_contracts/parser/transformers/nullable.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 lib/openapi_contracts/parser/transformers/nullable.rb 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