Search code examples
yaml

What does ">-" do?


I have found some internal async-api schema that looks like the following example:

  schemas:
    Example:
      type: object
      allOf:
        - $ref: '#/components/schemas/Foo'
        - type: object
          properties:
            bar:
              type: string
              description: >-
                Some description

What does the >- mean in this case? I could not find any documentation about this. The official specification only mentions the | character, which indicates a multiline string.


Solution

  • | and > are both used for multiline strings.

    Block Style Indicator: The block style indicates how newlines inside the block should behave. If you would like them to be kept as newlines, use the literal style, indicated by a pipe (|). If instead you want them to be replaced by spaces, use the folded style, indicated by a right angle bracket (>). (To get a newline using the folded style, leave a blank line by putting two newlines in. Lines with extra indentation are also not folded.)

    Block Chomping Indicator: The chomping indicator controls what should happen with newlines at the end of the string. The default, clip, puts a single newline at the end of the string. To remove all newlines, strip them by putting a minus sign (-) after the style indicator. Both clip and strip ignore how many newlines are actually at the end of the block; to keep them all put a plus sign (+) after the style indicator.

    Source with interactivity, so you can easily see the differences between these syntaxes: https://yaml-multiline.info/

    See also How do I break a string in YAML over multiple lines? for an in-depth explanation.