Search code examples
yamlopenapidredd

How write the BOM-Character in an OpenAPI3-YAML Specification


In the OpenApi3-spec of my API I have an endpoint returning CSV-data. No my Dredd-Test fails although example and returned are exactly the same. I assume the problem that my API returns CSV with a BOM character.

Now I have no idea How I can encode the character correctly in OpenAPI3-YAML. Can anyone help me out?

I tried \ufeff as I would do in JSON but it didn't work.

      responses:
        "200":
          description: ffffoo
          content:
            text/csv;charset=UTF-8:
              schema:
                type: string
              example: |-
                a;b;c
                1;2;3
                4;5;5



Solution

  • A literal block scalar does not process escape sequences, you'll need a double-quoted scalar for that:

          responses:
            "200":
              description: ffffoo
              content:
                text/csv;charset=UTF-8:
                  schema:
                    type: string
                  example: "\ufeff\
                    a;b;c\n\
                    1;2;3\n\
                    4;5;5"
    

    An escaped line break excludes the line break from the content. Unescaped line breaks in double-quoted scalars would be folded into an undesired space. \n\ basically replaces the space that would be generated from the line break with a proper line break.

    You can of course do away with the line breaks in the source but I'd say this is more readable.