Skip to content

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

Open
@christophfriedrich

Description

@christophfriedrich

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is the initial status for an issue that requires triage.📝 DocumentationIndicates improvements or additions to documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions