From eeb10266918ca52c6aa1e1e86fedbc3a7c1f65d4 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Sat, 2 Nov 2019 13:13:02 +0000 Subject: [PATCH] Fix invalid Swagger in YAML values The original fix failed because though the Keys were now strings, some of the values for path variables were also symbols. Psych does have a safe_load which has a whitelist of classes but it does not have a safe_dump mode. We could have used deep_transform_values and manually converted the classes we did not want, but why risk a buggy implementation when JSON.generate works just fine? --- rswag-specs/lib/rswag/specs/swagger_formatter.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rswag-specs/lib/rswag/specs/swagger_formatter.rb b/rswag-specs/lib/rswag/specs/swagger_formatter.rb index 7a8687a..6e23350 100644 --- a/rswag-specs/lib/rswag/specs/swagger_formatter.rb +++ b/rswag-specs/lib/rswag/specs/swagger_formatter.rb @@ -48,15 +48,16 @@ module Rswag def pretty_generate(doc) if @config.swagger_format == :yaml - YAML.dump(doc.deep_stringify_keys) + clean_doc = yaml_prepare(doc) + YAML.dump(clean_doc) else # config errors are thrown in 'def swagger_format', no throw needed here JSON.pretty_generate(doc) end end - def deep_stringify_hash_keys(doc) - - doc + def yaml_prepare(doc) + json_doc = JSON.pretty_generate(doc) + clean_doc = JSON.parse(json_doc) end def metadata_to_swagger(metadata)