website icon indicating copy to clipboard operation
website copied to clipboard

[📝 Docs]: Improve Enum documentation

Open benjagm opened this issue 1 year ago • 22 comments

What Docs changes are you proposing?

We received this feedback from the website and we think this is a great suggestion to improve our docs:

Page: /understanding-json-schema/reference/enum Comment: It'd be nice to see enum defined in context - where does it live in an overall schema?

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

benjagm avatar Mar 13 '24 09:03 benjagm

Can I work on this one @benjagm

Adity20 avatar Mar 13 '24 09:03 Adity20

Let's discuss what the improvement is in this issue before working on it.

gregsdennis avatar Mar 13 '24 09:03 gregsdennis

I guess telling the user where does enum live in overall schema using an example of enumerated values and then giving an example of using two different data types will be helpful. In current json schema components we are showing the enum property only and not how it can be implemented withing overall schema

Adity20 avatar Mar 13 '24 10:03 Adity20

where does enum live in overall schema

This is my point: where would you say that enum "lives" in a schema? There's not a correct answer to this because it depends on the data you're trying to validate.

enum on it's own in a schema, as it's shown in the current page, is perfectly valid and actually encouraged.

gregsdennis avatar Mar 13 '24 10:03 gregsdennis

Agreed @gregsdennis it can vary depending on different schemas

Adity20 avatar Mar 13 '24 10:03 Adity20

It's fine as it is or we can just add an example for an array of enumerated values { "type": "array", "items": { "type": "string", "enum": ["one", "two", "three"] } } like this

Adity20 avatar Mar 13 '24 10:03 Adity20

We shouldn't combine enum with other validation keywords (like type). enum lists valid values. Other validations are redundant.

We tell people this all the time, and they still do it. But we shouldn't promote this practice.

gregsdennis avatar Mar 13 '24 10:03 gregsdennis

Completely agree with you @gregsdennis. So I guess we should leave it like that only to avoid any further confusion

Adity20 avatar Mar 13 '24 10:03 Adity20

We just received more feedback regarding improving the docs of Enum:

  • Comment: Is "enum" a keyword or a user-defined name? For example, would "color": ["red", "green", "blue"] work?

benjagm avatar Mar 18 '24 17:03 benjagm

So what changes we should introduce in the documentation @benjagm ? color is a property of the object and enum specifies the value of color so the value must be one of the three strings. I don't think "color": ["red", "green", "blue"] will work because we can't substitute color for enum keyword. Let me know if I'm wrong @benjagm and @gregsdennis.

Adity20 avatar Mar 18 '24 17:03 Adity20

I don't think that makes sense from a JSON Schema perspective.

However, I think it might make sense if they're trying to build a form, and they want a field called color to be one of those three values. However, I'd expect a form generator to understand "color": { "enum": [ "red", "green", "blue" ]}.

gregsdennis avatar Mar 18 '24 18:03 gregsdennis

Yeah agreed @gregsdennis So we should add this to the enum documentation?

Adity20 avatar Mar 18 '24 19:03 Adity20

Add what? We can't document any form gen stuff because every form generator does things differently. There's no standard.

gregsdennis avatar Mar 18 '24 19:03 gregsdennis

Comment: Is "enum" a keyword or a user-defined name? For example, would "color": ["red", "green", "blue"] work?

This comment

Adity20 avatar Mar 18 '24 19:03 Adity20

I don't understand how adding that improves the docs.

gregsdennis avatar Mar 18 '24 19:03 gregsdennis

I think the docs are actually quite clear that it's a keyword. The examples on the page use it as a keyword. JSON Schema is comprised of keywords. I'm not sure how else it can be interpreted. I don't know what the commenter means by "user-defined name" because there's no such thing in JSON Schema. There are custom keywords, but those are also keywords.

The page STARTS with "The enum keyword..."

gregsdennis avatar Mar 18 '24 19:03 gregsdennis

After going through this thread, I came up with a couple suggestions:

1. To further enrich the enum documentation:

We can add required constraint to the docs.

{
  "type": "object",
  "properties": {
    "color": {
      "enum": ["red", "blue", "green"]
    },
    "shape": {
      "enum": ["circle", "square", "triangle"]
    }
  },
  "required": ["color", "shape"]
}

Also, I agree with @gregsdennis , using type with enum is redundant, because we are already specifying valid values in enum, that's kind of the purpose of enum.

2. In response to the comment received Is "enum" a keyword or a user-defined name? For example, would "color": ["red", "green", "blue"] work?

It seems like a common query beginners might have. The code above perfectly shows how to use enum with a custom field. But if we want to answer this query explicitly, we can add "custom_key": { "enum": ["value1", "value2", "value3"] } to the documentation.

@benjagm Let me know if this task can be Assigned to me. Thanks.

rishabhsdev avatar Mar 30 '24 07:03 rishabhsdev

is this free?

keys-i avatar Apr 13 '24 09:04 keys-i

@radhesh1 what needs doing is unclear. I don't think that anything needs to be done and this issue can be closed. If you see a way to make things more clear, please make a proposal here before creating a PR.

gregsdennis avatar Apr 13 '24 09:04 gregsdennis

Hello! :wave:

This issue has been automatically marked as stale due to inactivity :sleeping:

It will be closed in 180 days if no further activity occurs. To keep it active, please add a comment with more details.

There can be many reasons why a specific issue has no activity. The most probable cause is a lack of time, not a lack of interest.

Let us figure out together how to push this issue forward. Connect with us through our slack channel : https://json-schema.org/slack

Thank you for your patience :heart:

github-actions[bot] avatar Jun 02 '24 00:06 github-actions[bot]

This issue has been automatically marked as stale due to inactivity 😴

We'd love this issue to stay open.

benjagm avatar Aug 21 '24 08:08 benjagm

Hii @benjagm , I came across website and try to understand the application so my concern is we should work on providing more details for specific topic and give more language specific example like for JS and TS . And we can also add search bar for faster access the topic. Looking forward to the opportunity to collaborate with you

jagpreetrahi avatar Sep 21 '24 17:09 jagpreetrahi

@benjagm may I work on this issue, please review this, looks better image

techmannih avatar Oct 24 '24 11:10 techmannih

@benjagm @valeriahhdez May I work on this issue, there is no activity from last 2 months

techmannih avatar Jan 10 '25 12:01 techmannih

@techmannih Yes, you can

valeriahhdez avatar Jan 13 '25 22:01 valeriahhdez