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

Empty Xo-member is encoded wrong #45

Open
johannesheucher-gip opened this issue Jun 5, 2023 · 0 comments
Open

Empty Xo-member is encoded wrong #45

johannesheucher-gip opened this issue Jun 5, 2023 · 0 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@johannesheucher-gip
Copy link
Contributor

johannesheucher-gip commented Jun 5, 2023

Having a complex member inside an XoObject which has no members by itself, creates a wrong JSON (the empty JSON has a key "" instead).

A {
}

B {
  a: A
}

Encoding B leads to

{
  a: {
    "": undefined
  }
}

Proposed Solution

In xo-utils.ts

    static copyProperty(src: Xo, dst: Xo, path: string): void {

        const xoPath = XoUtil.sanitizePath(path);

        const result = XoUtil.resolveCreate(dst, xoPath);

        const pathToCopy = (result.value || result?.unresolvedPath?.head === '') ? xoPath : result.resolvedPath.concat(result.unresolvedPath.head).join('.');

        dst.resolveAssign(pathToCopy, src.resolve(pathToCopy));

    }
@johannesheucher-gip johannesheucher-gip self-assigned this Jun 5, 2023
@johannesheucher-gip johannesheucher-gip added the good first issue Good for newcomers label Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant