Skip to content

Commit e1a8f53

Browse files
document enum
1 parent e3340bf commit e1a8f53

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

website/docs/components/package.json-structure.md

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,49 @@ For components that fetch data or perform server-side processing:
199199

200200
#### API Documentation (`oc.parameters`)
201201

202-
| Parameter | Type | Required | Description |
203-
| -------------------------------- | --------- | ------------------ | --------------------------------------------------- |
204-
| `oc.parameters` | `object` | 🔧 **Recommended** | Component API definition for validation and docs |
205-
| `oc.parameters[key].type` | `string` |**Required** | Parameter type: `"string"`, `"boolean"`, `"number"` |
206-
| `oc.parameters[key].mandatory` | `boolean` |**Optional** | If `true`, parameter is required (default: `false`) |
207-
| `oc.parameters[key].description` | `string` | 🔧 **Recommended** | Parameter description for documentation |
208-
| `oc.parameters[key].example` | `string` | 🔧 **Recommended** | Example value for documentation |
209-
| `oc.parameters[key].default` | `any` |**Optional** | Default value when parameter not provided |
202+
| Parameter | Type | Required | Description |
203+
| -------------------------------- | --------- | ------------------ | ------------------------------------------------------------------------ |
204+
| `oc.parameters` | `object` | 🔧 **Recommended** | Component API definition for validation and docs |
205+
| `oc.parameters[key].type` | `string` |**Required** | Parameter type: `"string"`, `"boolean"`, `"number"` |
206+
| `oc.parameters[key].mandatory` | `boolean` |**Optional** | If `true`, parameter is required (default: `false`) |
207+
| `oc.parameters[key].description` | `string` | 🔧 **Recommended** | Parameter description for documentation |
208+
| `oc.parameters[key].example` | `string` | 🔧 **Recommended** | Example value for documentation |
209+
| `oc.parameters[key].default` | `any` |**Optional** | Default value when parameter not provided |
210+
| `oc.parameters[key].enum` | `array` |**Optional** | Restrict parameter to specific values (e.g., `["red", "green", "blue"]`) |
211+
212+
**Enum Parameter Example:**
213+
214+
The `enum` property is particularly useful when you want to restrict parameter values to a predefined set of options. This provides better validation, documentation, and prevents invalid values from being passed to your component.
215+
216+
```json
217+
{
218+
"oc": {
219+
"parameters": {
220+
"theme": {
221+
"type": "string",
222+
"mandatory": false,
223+
"description": "Visual theme for the component",
224+
"example": "dark",
225+
"enum": ["light", "dark", "auto"]
226+
},
227+
"size": {
228+
"type": "string",
229+
"mandatory": true,
230+
"description": "Component size variant",
231+
"enum": ["small", "medium", "large"]
232+
},
233+
"status": {
234+
"type": "string",
235+
"mandatory": false,
236+
"description": "Current status",
237+
"enum": ["pending", "success", "error", "warning"]
238+
}
239+
}
240+
}
241+
}
242+
```
243+
244+
When a parameter with an `enum` is provided with a value not in the allowed list, the registry will return a validation error with the allowed values listed.
210245

211246
#### Advanced Configuration
212247

0 commit comments

Comments
 (0)