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

Is enum supported? #96

Open
cihad opened this issue Nov 12, 2024 · 5 comments
Open

Is enum supported? #96

cihad opened this issue Nov 12, 2024 · 5 comments

Comments

@cihad
Copy link

cihad commented Nov 12, 2024

Why is the enum not working?

{
  "type": "object",
  "properties": {
    "city": {
      "title": "City",
      "enum": ["Foo", "Bar"],
      "x-jsf-presentation": {
        "inputType": "select"
      },
      "type": "string"
    }
  }
}

but it is ok:

{
  "type": "object",
  "properties": {
    "city": {
      "title": "City",
      "oneOf": [
        { "const": "Foo", "title": "Foo" },
        { "const": "Bar", "title": "Bar" }
      ],
      "x-jsf-presentation": {
        "inputType": "select"
      },
      "type": "string"
    }
  }
}
@ollyd
Copy link
Collaborator

ollyd commented Nov 13, 2024

Hi @cihad! In your example enum won't work as it would need a corresponding options property within the x-jsf-presentation property. However, whilst this will work it's now deprecated and will be removed in future - our recommended implementation is using oneOf as per your second example.

If you need to use enum in the way you've suggested, whereby the label would also represent the value, contributions to the library are always very welcome!

@cihad
Copy link
Author

cihad commented Nov 14, 2024

Enum will always come up. It would be good to support it. Maybe enumLabels can be added to x-jsf-presentation.

@ollyd
Copy link
Collaborator

ollyd commented Nov 15, 2024

Enum will always come up. It would be good to support it. Maybe enumLabels can be added to x-jsf-presentation.

Hi @cihad agree it would be good to support it. We would suggest enumTitles rather than enumLabels as title is more in line with the json schema spec. If you would like to take a stab at opening a PR, it would be appreciated.

@sandrina-p
Copy link
Collaborator

sandrina-p commented Nov 15, 2024

Hi @cihad! Oone more thing we remembered:

Imagine this enum: ["1", 1, true, "true"] Using enumTitles an object, we cannot match the title for each key because they are always strings. So the enumTitles needs to be an array as enum.
In your example, it would be enumTitles: ["Identification", "P45 Document"]

Does this make sense to you?

@cihad
Copy link
Author

cihad commented Nov 15, 2024

Yes, it would be better to use enumTitles as an array instead of an object.

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

3 participants