Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-line literals in swagger editor?

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?

like image 613
fool4jesus Avatar asked Jan 26 '15 23:01

fool4jesus


People also ask

Does Yaml support multiline string?

Multi-line blocks and long strings. YAML also supports writing strings on multiple lines in your YAML, with two different styles: literal and folded. Those are represented by a | (for literal style) or > (for folded style) header line (see examples below), and we will go into their differences soon.

How do you comment a line in Swagger?

Click on the + button on the left of each line of the Swagger spec to add your comment from the Comment Bar. The Comment Bar houses all the comments, both resolved and unresolved, on the API spec, sorted by line. You can access the Comment Bar anytime from the Swagger UI.


2 Answers

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.

like image 199
Mike Malloy Avatar answered Oct 07 '22 09:10

Mike Malloy


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.
like image 11
john Avatar answered Oct 07 '22 09:10

john