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

Custom types not working as expected #695

Open
pascalre opened this issue Jan 11, 2023 · 0 comments
Open

Custom types not working as expected #695

pascalre opened this issue Jan 11, 2023 · 0 comments

Comments

@pascalre
Copy link

I want to create a custom js-yaml schema, which supports Homeassistant tags. For that I developed homeassistant-js-yaml-schema.
Unfortunately something is not working as expected, leading to this behavior. The schema reads the tags, but it adds too much meta information.

I noticed the same behavior in the provided example custom_types.js. I used exact the same file custom_types.js, loaded exact the same file custom_types.yml and dumped it. The result differs and also adds too much meta information. For me it looks like the represent function is ignored.

See my test here:

const jsyaml = require('js-yaml');
const { SPACE_SCHEMA } = require('../src/custom_types');

test('should load yaml with SPACE_SCHEMA', () => {
  const file = `
subject: Custom types in JS-YAML
spaces:
- !space
  height: 1000
  width: 1000
  points:
  - !point [ 10, 43, 23 ]
  - !point [ 165, 0, 50 ]
  - !point [ 100, 100, 100 ]

- !space
  height: 64
  width: 128
  points:
  - !point [ 12, 43, 0 ]
  - !point [ 1, 4, 90 ]

- !space # An empty space"
`;

  const doc = jsyaml.load(file, { schema: SPACE_SCHEMA });
  const result = jsyaml.dump(doc);
  expect(result).toBe(doc);
});

The result is

subject: Custom types in JS-YAML
    spaces:
      - klass: Space
        height: 1000
        width: 1000
        points:
          - klass: Point
            x: 10
            'y': 43
            z: 23
          - klass: Point
            x: 165
            'y': 0
            z: 50
          - klass: Point
            x: 100
            'y': 100
            z: 100
      - klass: Space
        height: 64
        width: 128
        points:
          - klass: Point
            x: 12
            'y': 43
            z: 0
          - klass: Point
            x: 1
            'y': 4
            z: 90
      - klass: Space
        height: 0
        width: 0
        points: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant