3

I'm looking at OpenAPI and the description tag. What are the differences between these tags? They all support multiple lines, but anything else?

description: |
description: >
description: >-
Helen
  • 87,344
  • 17
  • 243
  • 314
Michael
  • 79
  • 7

2 Answers2

3

|, >, >- are some of YAML block style indicators. They are used to break a long string value over multiple lines and format multi-paragraphs Markdown strings. You can find more information here:

In OpenAPI context, the use of > vs | in descriptions affects the resulting Markdown rendering.

> (folded style)

This replaces single new lines with spaces, but adds a new line at the end of the YAML value. To have a literal new line in the value, add a blank line between the lines. To start a new Markdown paragraph, add two blank lines between the paragraphs.

For example:

description: >
  Quick
  brown fox

  jumps over a lazy dog.


  And this is a new paragraph.

This means the description value is:

which after being processed with a Markdown renderer becomes:

<p>Quick brown fox<br/>
jumps over a lazy dog.</p>

<p>And this is a new paragraph.</p>

>- (folded style with the strip block chomping indicator)

Same as > but with no new line at the end of the YAML value.

Markdown renderers don't care about the trailing new line, so the > and >- styles are rendered exactly the same.

| (literal style)

New lines in the YAML value are kept as is. For example:

description: >
  Quick
  brown fox

  jumps over a lazy dog.


  And this is a new paragraph.

This means the description value is:

which will be rendered as

<p>Quick<br>
brown fox</p>

<p>jumps over a lazy dog.</p>

<p>And this is a new paragraph.</p>
Helen
  • 87,344
  • 17
  • 243
  • 314
2

description isn't a YAML "tag", it's just a field/property in the YAML file you're editing, such as an OpenAPI or Swagger document.

The YAML specification describes the different text folding styles here: https://yaml.org/spec/1.2/spec.html#id2793652

That's pretty hard to understand at first glance, so this site makes things a lot easier, and has interactive examples: https://yaml-multiline.info/

MikeRalphson
  • 2,247
  • 2
  • 15
  • 16
  • I saw both of those sites. The yaml-multiline one is very good. However, using Redocly, those conventions don't work the same way. I was wondering if it is a bug in Redocly, or there are flavors that change on each platform. – Michael May 06 '21 at 19:59
  • What specifically doesn't work in ReDoc? It may be the fault of the YAML parser they are using. – MikeRalphson May 07 '21 at 08:38