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

[📝 Docs]: Example for required properties in Getting Started is misleading #1399

Open
1 task done
christophfriedrich opened this issue Feb 6, 2025 · 4 comments
Open
1 task done
Labels
📝 Documentation Indicates improvements or additions to documentation. Status: Triage This is the initial status for an issue that requires triage.

Comments

@christophfriedrich
Copy link

What Docs changes are you proposing?

I was just quickly looking up how to define a property as required and skimming through the Getting Started for that, where I read in the corresponding section:

To define a required property:
[...]
2. Add the exclusiveMinimum validation keyword and set the value to zero:
[...]
3. Add the required validation keyword to the end of the schema

Not thinking too much about it, I read this as "exclusiveMinimum=0 means that there must be at least one item of this" -- but in fact this keyword refers to the value. The example should be changed here to not be misleading.

Code reference:

### Define required properties
This section describes how to specify that certain properties are required. This example makes the two existing keys required and adds another required key named `price`. The `price` key has a `description` and `type` just like the other keys, but it also specifies a minimum value. Because nothing in the store is free, each product requires a price value that’s above zero. Define this using the `exclusiveMinimum` validation keyword.
To define a required property:
1. Inside the `properties` object, add the `price` key. Include the usual schema annotations `description` and `type`, where `type` is a number:
```jsonc
"properties": {
...
"price": {
"description": "The price of the product",
"type": "number"
}
}
```
2. Add the `exclusiveMinimum` validation keyword and set the value to zero:
```jsonc
"price": {
"description": "The price of the product",
"type": "number",
"exclusiveMinimum": 0
}
```
3. Add the `required` validation keyword to the end of the schema, after the `properties` object. Add `productID`, `productName`, and the new `price` key to the array:
```jsonc
...
"properties": {
...
"price": {
"description": "The price of the product",
"type": "number",
"exclusiveMinimum": 0
},
},
"required": [ "productId", "productName", "price" ]
```

Code of Conduct

  • I agree to follow this project's Code of Conduct
@christophfriedrich christophfriedrich added Status: Triage This is the initial status for an issue that requires triage. 📝 Documentation Indicates improvements or additions to documentation. labels Feb 6, 2025
Copy link

github-actions bot commented Feb 6, 2025

Welcome to the JSON Schema Community. We are so excited you are here! Thanks a lot for reporting your first issue!! 🎉🎉 Please make sure to take a look at our contributors guide if you plan on opening a pull request.
For more details, check out the README.md file.

@Karan-Palan
Copy link
Contributor

From what I understand:

  1. The price property must be present (required keyword).
  2. The price value must be greater than zero (exclusiveMinimum: 0).

Shall I update this @DhairyaMajmudar ?

@jagpreetrahi
Copy link

Hey @Karan-Palan, just checking if you're working on this issue. If not, I’d love to contribute as well. Let me know how we can coordinate.

@Karan-Palan
Copy link
Contributor

@jagpreetrahi I provided my suggestion/solution based on what I understood. Still waiting for assignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📝 Documentation Indicates improvements or additions to documentation. Status: Triage This is the initial status for an issue that requires triage.
Projects
None yet
Development

No branches or pull requests

3 participants