From acab437a7d36c3b8c75851c9eae4790f87386da3 Mon Sep 17 00:00:00 2001 From: Greg Myers Date: Sat, 2 Nov 2019 12:55:09 +0000 Subject: [PATCH] Add failing test showing Psych errors --- rswag-specs/lib/rswag/specs/swagger_formatter.rb | 2 ++ rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/rswag-specs/lib/rswag/specs/swagger_formatter.rb b/rswag-specs/lib/rswag/specs/swagger_formatter.rb index b8061dc..d16aeb2 100644 --- a/rswag-specs/lib/rswag/specs/swagger_formatter.rb +++ b/rswag-specs/lib/rswag/specs/swagger_formatter.rb @@ -48,6 +48,8 @@ module Rswag def pretty_generate(doc) if @config.swagger_format == :yaml + # NOTE: Yaml will quite happily embed ruby-only classes such as symbols. + # clean_doc = stringify(doc) YAML.dump(doc) else # config errors are thrown in 'def swagger_format', no throw needed here JSON.pretty_generate(doc) diff --git a/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb b/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb index 2a29cde..6561f8a 100644 --- a/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb +++ b/rswag-specs/spec/rswag/specs/swagger_formatter_spec.rb @@ -74,6 +74,8 @@ module Rswag it 'writes the swagger_doc(s) as yaml' do expect(File).to exist("#{swagger_root}/v1/swagger.json") expect { JSON.parse(File.read("#{swagger_root}/v1/swagger.json")) }.to raise_error(JSON::ParserError) + # Psych::DisallowedClass would be raised if we do not pre-process ruby symbols + expect { YAML.safe_load(File.read("#{swagger_root}/v1/swagger.json")) }.not_to raise_error end end