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

can I set uniqueItems in json schema based on property of item #3909

Open
jcphlux opened this issue May 7, 2024 · 3 comments
Open

can I set uniqueItems in json schema based on property of item #3909

jcphlux opened this issue May 7, 2024 · 3 comments
Labels

Comments

@jcphlux
Copy link

jcphlux commented May 7, 2024

Question

Is it possible to base uniqueItems on CustomTypes property in my json schema on the property CustomType in the CustomTypes schema in definitions?

{
  "properties": {
    "CustomTypes": {
      "items": {
        "$ref": "#/definitions/CustomTypes"
      },
      "type": "array",
      "title": "Custom Types",
      "description": "The Custom type array.",
      "default": [],
      "widget": {
        "formlyConfig":{
          "templateOptions": {
            "uniqueItems": true
          }
        }
      }
    }
  },
  "type": "object",
  "required": [
    "CustomTypes"
  ],
  "title": "This is a Title",
  "default_values": [
    {
      "CustomTypes": []
    }
  ],
  "definitions": {
    "CustomTypes": {
      "properties": {
        "CustomType": {
          "allOf": [
            {
              "$ref": "#/definitions/CustomType"
            }
          ],
          "title": "Custom Type",
          "description": "The Custom type."
        },
        "TypeNames": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "title": "Custom Type Names",
          "description": "The Custom name starts with.",
          "default": []
        }
      },
      "type": "object",
      "required": [
        "CustomType",
        "TypeNames"
      ],
      "title": "Custom Types"
    },
    "CustomType": {
      "type": "string",
      "enum": [
        "enum_1",
        "enum_2",
        "enum_3",
        "enum_4",
        "enum_5"
      ],
      "title": "CustomType"
    }
  }
}
@kenisteward
Copy link
Collaborator

kenisteward commented May 7, 2024 via email

@jcphlux
Copy link
Author

jcphlux commented May 7, 2024

Instead of putting unique items in the widget put it in the schema itself. Unique items is a json schema validation key.

so like this

     "CustomTypes": {
      "items": {
        "$ref": "#/definitions/CustomTypes"
      },
      "type": "array",
      "title": "Custom Types",
      "description": "The Custom type array.",
      "default": [],
      "uniqueItems": true         
    }

So when dealing with an object vs a enum how do I tell it what property of that object to base uniqueness off of? I don't want more then one object with the same enum.

@kenisteward
Copy link
Collaborator

kenisteward commented May 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants