0

I'm attempting to reproduce this YAML variable using PyYAML's dump:

x-google-backend:
  address: https://www.google.com
  path_translation: [ APPEND_PATH_TO_ADDRESS ]

Specifically the path_translation: [ APPEND_PATH_TO_ADDRESS ] is what I can't produce.

It's meant to take a python object and turn it into valid yaml. The trouble is I can only ever get

x-google-backend:
  address: https://www.google.com
  path_translation: '[ APPEND_PATH_TO_ADDRESS ]'

or

x-google-backend:
  address: https://www.google.com
  path_translation:
  - APPEND_PATH_TO_ADDRESS

From PyYAML's own documentation it looks like what I'm trying to do is called a "flow collection". But when I tried their recommended syntax I just got the above result with the hyphen representing a list item.

Specifically I'm doing it inside a dictionary:

dict({"path_translation": [ "APPEND_PATH_TO_ADDRESS" ]}, address="https://www.google.com")

Any ideas about how to produce this correctly would be greatly appreciated!

MarkyDD
  • 272
  • 5
  • 16
  • What is the code needed to reproduce? By default, pyyaml will use the flow representation for collections that don't contain any nested collections according to [this](https://pyyaml.org/wiki/PyYAMLDocumentation). – Jasmijn Apr 27 '21 at 19:56
  • pyyaml `dump` is being called by apispec `to_yaml()`, which sets the Dumper as `dumper.represent_mapping("tag:yaml.org,2002:map", instance.items())` – MarkyDD Apr 27 '21 at 20:06
  • I wasn't clear, apologies: please edit your question so it contains a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Jasmijn Apr 27 '21 at 21:39

0 Answers0