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?
This commit is contained in:
Greg Myers
2019-11-02 13:13:02 +00:00
parent 2c0f3c9396
commit eeb1026691

View File

@@ -48,15 +48,16 @@ module Rswag
def pretty_generate(doc) def pretty_generate(doc)
if @config.swagger_format == :yaml 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 else # config errors are thrown in 'def swagger_format', no throw needed here
JSON.pretty_generate(doc) JSON.pretty_generate(doc)
end end
end end
def deep_stringify_hash_keys(doc) def yaml_prepare(doc)
json_doc = JSON.pretty_generate(doc)
doc clean_doc = JSON.parse(json_doc)
end end
def metadata_to_swagger(metadata) def metadata_to_swagger(metadata)