38

I am trying to get a multi-line literal in Swagger editor (awesome tool, by the way!).

  post:
    summary: Translate one or more identifiers
    description: |
Translate one or more identifiers for one entity into the
identifiers of another entity. Translate one or more
identifiers for one entity into the identifiers of another entity.

    consumes:
    - application/json

I've tried it with | and >, with different endings (increasing indent vs. empty line), and every way I can think of, but it always gives the same error:

YAML Syntax Error
Can not read a block mapping entry; a multiline key may not be an implicit  
key at line 24, column 15: consumes: ^

I see bugs for JS-YAML that indicate the problem is a Windows-style newline at the end, which I know HTML textareas can create. This is the first time I'm really using YAML much, so is it just me doing something wrong, or a bug in Swagger editor?

2
  • I have found it difficult to debug syntax errors like this in the online Swagger editor. These issues are more easily identified in text editors like SublimeText, where colour coding is used to highlight syntax problems.
    – OneXer
    Commented May 14, 2021 at 15:21
  • I could see that @OneXer. I imagine such things are far more developed than they were when I asked this question. Today I'd probably use VSC.
    – fool4jesus
    Commented May 19, 2021 at 12:17

5 Answers 5

58

I believe the problem is the way you started the text on your description block. It must be indented one level to the right of description: Here's an example of something that works for me:

/{user-id}:
get:
  summary: Facebook User
  description: |
    Displays all information about a Facebook user, depending on access privileges.  Displays all information about a Facebook user, depending on access privileges.
  parameters:
    - name: user-id
      in: path
      description: The Facebook user ID
      required: true
      type: string

In my actual code, the description is three lines long.

1
  • In my case, the same error message was caused by missing a space after the colon of the previous line (summary) but your answer made me look more closely. Commented Jul 7, 2020 at 0:34
21

It's the indentation. It should be like:

  post:
    summary: Translate one or more identifiers
    description: |
      Translate one or more identifiers for one entity into the
      identifiers of another entity. Translate one or more
      identifiers for one entity into the identifiers of another entity.
5

Wanted to add the JSON approach. I'm using pure JSON in the Swagger Editor to avoid problems with double syntax (learning, debugging, parsing for web documentation, etc.).

"get": {
    "description": "Hi\n\nThere",

For some reason double newline character \n seemed to be required, at least for the new line to render on the Swagger Editor. However when I exported the official Uber API YAML demo as JSON (File -> Download as JSON), the resulting JSON only had single newline characters where multi-line literals were demonstrated. Weird.

0

In my case it was only a /, that i should have put in the beginning of the permalink, in my category.md:

permalink: /{{ blog.catPermalinkPrefix }}/{{ category.slug }}/ 
0

In my case, copy/paste of some text that had tabs in the front of the text made it "look" good, but caused this error

Not the answer you're looking for? Browse other questions tagged or ask your own question.