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

Array copy item with UUID: first copy has a duplicated UUID #1481

Open
simontaurus opened this issue Feb 4, 2024 · 2 comments
Open

Array copy item with UUID: first copy has a duplicated UUID #1481

simontaurus opened this issue Feb 4, 2024 · 2 comments
Assignees
Labels

Comments

@simontaurus
Copy link

simontaurus commented Feb 4, 2024

General information

  • json-editor version: 2.14.0

Expected behavior

Each array element should have a unique ID

Actual behavior

The first copy has the same UUID as the first element
Seems like #1129 is only partially solved in the current release

Steps to reproduce the behavior

Direct link to example: playground

{
  "type": "object",
  "properties": {
    "uuid": {
      "type": "string",
      "format": "uuid",
      "title": "single uuid",
      "required": true,
      "default": "banana"
    },
    "uuidArray": {
      "type": "array",
      "title": "uuid array",
      "required": true,
      "items": {
        "type": "object",
        "properties": {
          "uuid": {
            "type": "string",
            "format": "uuid"
          }
        }
      }
    }
  }
}

Creating a first element a two copies leads to

{
  "uuid": "2df6ccc8-b03e-4922-bdba-ad83bc458e4e",
  "uuidArray": [
    {
      "uuid": "1c0ed826-8b36-4639-b909-381f7ab5a140"
    },
    {
      "uuid": "6492984d-8013-4b57-863f-fff7ea01a70c"
    },
    {
      "uuid": "6492984d-8013-4b57-863f-fff7ea01a70c"
    }
  ]
}

A workaround is to use a uuid template instead: #1485

@germanbisurgi
Copy link
Collaborator

germanbisurgi commented Feb 12, 2024

Hi @simontaurus,

When adding uuid items with the "+ Item" button everything works like expected. Because the uuid editor create their own value at creation in order to be universally unique.

When copying items the Array editor will check if it#s item is type string and has format uuid. In that case the uuid will be regenerated. In this case it does not override uuid because it#s items are of type object

I guess the issue it's about setting the array value directly in which 2 items are identical. If that is so the value should be stripped off from duplicated items before setting the value of the array. Additionally the constrain "uniqueItems" can be added to the array schema to show validation errors.

I'm closing this because i think that was the issue, which is not a json editor bug, but feel free to reopen it if i missed something :)

@simontaurus
Copy link
Author

simontaurus commented Feb 14, 2024

@germanbisurgi: I don't have permissions to reopen the issue, but it would be great to have some further discussion:

When copying items the Array editor will check if it#s item is type string and has format uuid. In that case the uuid will be regenerated. In this case it does not override uuid because it#s items are of type object

Makes sense, so the copied item is a true and full copy, including the uuid. But actually the uuid seems to be regenerated first and then copied so it's not possible to keep the uuid of the first element and also not achievable to create more than two array items with the same uuid:

First array element get's a uuid:
grafik
Copying the first element asigns a new uuid to the first element and the second element has the same uuid.
grafik
Copying the second element asigns a new uuid to the second element and the third element has the same uuid, which is now different from the uuid of the first element:
grafik

One could also argue that a UUID is per definition global unique and should never be duplicated. However, with a fixed copyRow callback (see #1483) it would be a workaround to enforce the uuid regeneration there.

@germanbisurgi germanbisurgi reopened this Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants