yaml Error while parsing. Expected <block end>, but found <scalar>

23,001

That line needs to be wrapped in quotes in order to escape the inner : character:

- "validate(res.json,  $ref: '#/definitions/ferry')"
                           ^

: is a special character in YAML, a separator for key: value pairs. Without escaping, that line is parsed as the key name validate(res.json, $ref with the value '#/definitions/ferry') and the parser chokes on ) after the ending quotation mark.

Related: How to escape indicator characters (i.e. : or - ) in YAML

Share:
23,001
Dennis Van Bets
Author by

Dennis Van Bets

Updated on March 05, 2020

Comments

  • Dennis Van Bets
    Dennis Van Bets about 4 years

    I'm trying to test a swagger api with got-swag (npm package)

    When I try to validate the json response with a json schema I get a parseError when the seperate yaml files get combined into one yaml and json file. The origin is the -validate() line. The validate() originates from the got-swag package but it fails in it's underlying jsonschema.validate( data, schema ); dependency

     x-tests:
            - description: Should return array of ferries
              steps:
                - get('/api/get/link/ferries')
                - equal(res.statusCode, 200)
                - ok(res.json.length > 0)
                - validate(res.json,  $ref: '#/definitions/ferry')
    

    This is the resulting error:

               throw new exports.ParserError('while parsing a block mapping', this.marks.slice(-1)[0], "expected <block end>, but found " + token.id, token.start_mark);
            ^
    while parsing a block mapping
      on line 29, column 15
    expected <block end>, but found <scalar>
      on line 29, column 76
        at ParserError.YAMLError [as constructor] (C:\Users\dvbets\Documents\Workspace\Repos\node_modules\yaml-js\lib\errors.js:70:46)
        at ParserError.MarkedYAMLError [as constructor] (C:\Users\dvbets\Documents\Workspace\Repos\node_modules\yaml-js\lib\errors.js:90:45)
        at new ParserError (C:\Users\dvbets\Documents\Workspace\Repos\node_modules\yaml-js\lib\parser.js:17:48)
        at Loader.__dirname.Parser.Parser.parse_block_mapping_key (C:\Users\dvbets\Documents\Workspace\Repos\node_modules\yaml-js\lib\parser.js:433:15)
        at Loader.__dirname.Parser.Parser.check_event (C:\Users\dvbets\Documents\Workspace\Repos\node_modules\yaml-js\lib\parser.js:61:48)
        at Loader.__dirname.Composer.Composer.compose_mapping_node (C:\Users\dvbets\Documents\Workspace\Repos\node_modules\yaml-js\lib\composer.js:248:20)
        at Loader.__dirname.Composer.Composer.compose_node (C:\Users\dvbets\Documents\Workspace\Repos\node_modules\yaml-js\lib\composer.js:160:21)
        at Loader.__dirname.Composer.Composer.compose_sequence_node (C:\Users\dvbets\Documents\Workspace\Repos\node_modules\yaml-js\lib\composer.js:216:30)
        at Loader.__dirname.Composer.Composer.compose_node (C:\Users\dvbets\Documents\Workspace\Repos\node_modules\yaml-js\lib\composer.js:158:21)
        at Loader.__dirname.Composer.Composer.compose_mapping_node (C:\Users\dvbets\Documents\Workspace\Repos\node_modules\yaml-js\lib\composer.js:250:27)