Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not able to parse anchor variable reference #301

Closed
KrishnaveniSan opened this issue Oct 18, 2016 · 5 comments
Closed

not able to parse anchor variable reference #301

KrishnaveniSan opened this issue Oct 18, 2016 · 5 comments

Comments

@KrishnaveniSan
Copy link

Hi,

I m trying to parse a swagger.yaml with js-yaml. I have defined anchor variables and referenced them as below.

x-a127-config:
  abc: &ABC 
  xyz: &xyz 


x-a127-services:
  abc: *abc
  **cache-session: *xyz**

The parser throws exception at line *cache-session: xyz

error: unidentified alias "xyz" at line 28, column 22:
cache-session: *xyz
^

Below is my code

var yaml = require('js-yaml');
var doc;
    try {
      doc = yaml.load(stream.readFileSync(inputFilePath, 'utf8')); //inputFilePath -- is path to my swagger.yaml file
       } catch (e) {
      console.log(e);
    } 

Is there any option that can be used while parsing, so that js-yaml will parse the references to anchor variables successfully?

@dervus
Copy link
Collaborator

dervus commented Oct 18, 2016

JS-YAML registers anchors only for non-empty nodes. I'll check if it conforms the spec or not.

@stealthybox
Copy link

This may be related to #319.

@puzrin puzrin mentioned this issue Feb 28, 2017
9 tasks
@perlpunk
Copy link

You can add an anchor to any node, the spec doesn't say anything special about empty nodes.
For this input:

a: &a
b: *a

I currently get this JSON output:

{
  "a": null,
  "b": []
}

where b should actually have the value null.

@perlpunk
Copy link

perlpunk commented Aug 4, 2018

@rlidwka
Copy link
Member

rlidwka commented Dec 29, 2020

Fixed in e8cf6f6 (currently in dev branch).

@rlidwka rlidwka closed this as completed Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants