Skip to content

Commit 35fa2f8

Browse files
Merge pull request #285621 from mumian/0827-decorator
additional information for decorator
2 parents e203f30 + 0ca4f3d commit 35fa2f8

File tree

3 files changed

+97
-14
lines changed

3 files changed

+97
-14
lines changed

articles/azure-resource-manager/bicep/file.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Bicep is a declarative language, which means the elements can appear in any orde
1919
A Bicep file has the following elements.
2020

2121
```bicep
22+
@<decorator>(<argument>)
2223
metadata <metadata-name> = ANY
2324
2425
targetScope = '<scope>'
@@ -48,6 +49,7 @@ module <module-symbolic-name> '<path-to-file>' = {
4849
}
4950
}
5051
52+
@<decorator>(<argument>)
5153
output <output-name> <output-data-type> = <output-value>
5254
```
5355

@@ -116,20 +118,22 @@ You can add one or more decorators for each of the following elements:
116118
* [func](#functions)
117119
* [type](#types)
118120

121+
The decorators include:
122+
119123
| Decorator | Apply to element | Apply to data type | Argument | Description |
120124
| --------- | ---- | ----------- | ------- |
121125
| allowed | [param](./parameters.md#allowed-values) | all | array | Use this decorator to make sure the user provides correct values. This decorator is only permitted on `param` statements. To declare that a property must be one of a set of predefined values in a [`type`](./user-defined-data-types.md) or [`output`](./outputs.md) statement, use [union type syntax](./data-types.md#union-types). Union type syntax can also be used in `param` statements.|
122-
| batchSize |[resource](./resource-declaration.md#batchsize), [module](./modules.md#batchsize)| N/A | integer | Set up instances to deploy sequentially. |
123-
| description | [param](./parameters.md#description), [var](./variables.md#description), [resource](./resource-declaration.md#description), [module](./modules.md#description), [output](./outputs.md#description), [type](./user-defined-data-types.md#description), [func](./user-defined-functions.md#description) | all | string | Provide descriptions for the elements. Markdown-formatted text can be used for the description text. |
126+
| batchSize |[module](./modules.md#batchsize), [resource](./resource-declaration.md#batchsize) | N/A | integer | Set up instances to deploy sequentially. |
127+
| description | [func](./user-defined-functions.md#description), [param](./parameters.md#description), [module](./modules.md#description), [output](./outputs.md#description), [resource](./resource-declaration.md#description), [type](./user-defined-data-types.md#description), [var](./variables.md#description) | all | string | Provide descriptions for the elements. Markdown-formatted text can be used for the description text. |
124128
| discriminator | [param](./parameters.md#discriminator), [type](./user-defined-data-types.md#discriminator), [output](./outputs.md#discriminator) | object | string | Use this decorator to ensure the correct subclass is identified and managed. For more information, see [Custom-tagged union data type](./data-types.md#custom-tagged-union-data-type).|
125-
| export | [var](./variables.md#export), [type](./user-defined-data-types.md#export), [func](./user-defined-functions.md#export) | all | none| Indicates that the element can be imported by another Bicep file. |
126-
| maxLength | [param](./parameters.md#length-constraints), [output](./outputs.md#length-constraints) | array, string | int | The maximum length for string and array elements. The value is inclusive. |
127-
| maxValue | [param](./parameters.md#integer-constraints), [output](./outputs.md#integer-constraints) | int | int | The maximum value for the integer elements. This value is inclusive. |
128-
| metadata | [param](./parameters.md#metadata), [output](./outputs.md#metadata) | all | object | Custom properties to apply to the elements. Can include a description property that is equivalent to the description decorator. |
129-
| minLength | [param](./parameters.md#length-constraints), [output](./outputs.md#length-constraints) | array, string | int | The minimum length for string and array elements. The value is inclusive. |
130-
| minValue | [param](./parameters.md#integer-constraints), [output](./outputs.md#integer-constraints) | int | int | The minimum value for the integer elements. This value is inclusive. |
129+
| export | [func](./user-defined-functions.md#export), [type](./user-defined-data-types.md#export), [var](./variables.md#export) | all | none| Indicates that the element can be imported by another Bicep file. |
130+
| maxLength | [param](./parameters.md#length-constraints), [output](./outputs.md#length-constraints), [type](./user-defined-data-types.md#length-constraints) | array, string | int | The maximum length for string and array elements. The value is inclusive. |
131+
| maxValue | [param](./parameters.md#integer-constraints), [output](./outputs.md#integer-constraints), [type](./user-defined-data-types.md#integer-constraints) | int | int | The maximum value for the integer elements. This value is inclusive. |
132+
| metadata | [func](./user-defined-functions.md#metadata), [output](./outputs.md#metadata), [param](./parameters.md#metadata), [type](./user-defined-data-types.md#metadata) | all | object | Custom properties to apply to the elements. Can include a description property that is equivalent to the description decorator. |
133+
| minLength | [param](./parameters.md#length-constraints), [output](./outputs.md#length-constraints), [type](./user-defined-data-types.md#length-constraints) | array, string | int | The minimum length for string and array elements. The value is inclusive. |
134+
| minValue | [param](./parameters.md#integer-constraints), [output](./outputs.md#integer-constraints), [type](./user-defined-data-types.md#integer-constraints) | int | int | The minimum value for the integer elements. This value is inclusive. |
131135
| sealed | [param](./parameters.md#sealed), [type](./user-defined-data-types.md#sealed), [output](./outputs.md#sealed) | object | none | Elevate [BCP089](./diagnostics/bcp089.md) from a warning to an error when a property name of a use-define data type is likely a typo. For more information, see [Elevate error level](./user-defined-data-types.md#elevate-error-level). |
132-
| secure | [param](./parameters.md#secure-parameters) | string, object | none | Marks the parameter as secure. The value for a secure parameter isn't saved to the deployment history and isn't logged. For more information, see [Secure strings and objects](data-types.md#secure-strings-and-objects). |
136+
| secure | [param](./parameters.md#secure-parameters), [type](./user-defined-data-types.md#secure-types) | string, object | none | Marks the parameter as secure. The value for a secure parameter isn't saved to the deployment history and isn't logged. For more information, see [Secure strings and objects](data-types.md#secure-strings-and-objects). |
133137

134138
## Parameters
135139

articles/azure-resource-manager/bicep/user-defined-data-types.md

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,18 @@ resource storageAccount 'Microsoft.Storage/storageAccounts@2023-04-01' = {
232232

233233
Decorators are written in the format `@expression` and are placed above the declarations of the user-defined data type. The following table shows the available decorators for user-defined data types.
234234

235-
| Decorator | Argument | Description |
235+
| Decorator | Apply to | Argument | Description |
236236
| --------- | ----------- | ------- |
237-
| [description](#description) | string | Provide descriptions for the user-defined data type. |
238-
| [discriminator](#discriminator) | string | Use this decorator to ensure the correct subclass is identified and managed. |
239-
| [export](#export) | none | Indicates that the user-defined data type is available for import by another Bicep file. |
240-
| [sealed](#sealed) | none | Elevate [BCP089](./diagnostics/bcp089.md) from a warning to an error when a property name of a use-define data type is likely a typo. For more information, see [Elevate error level](#elevate-error-level).|
237+
| [description](#description) | all |string | Provide descriptions for the user-defined data type. |
238+
| [discriminator](#discriminator) | object | string | Use this decorator to ensure the correct subclass is identified and managed. |
239+
| [export](#export) | all | none | Indicates that the user-defined data type is available for import by another Bicep file. |
240+
| [maxLength](#length-constraints) | array, string | int | The maximum length for string and array data types. The value is inclusive. |
241+
| [maxValue](#integer-constraints) | int | int | The maximum value for the integer data types. This value is inclusive. |
242+
| [metadata](#metadata) | all | object | Custom properties to apply to the data types. Can include a description property that is equivalent to the description decorator. |
243+
| [minLength](#length-constraints) | array, string | int | The minimum length for string and array data types. The value is inclusive. |
244+
| [minValue](#integer-constraints) | int | int | The minimum value for the integer data types. This value is inclusive. |
245+
| [sealed](#sealed) | object | none | Elevate [BCP089](./diagnostics/bcp089.md) from a warning to an error when a property name of a use-define data type is likely a typo. For more information, see [Elevate error level](#elevate-error-level).|
246+
| [secure](#secure-types) | string, object | none | Marks the types as secure. The value for a secure type isn't saved to the deployment history and isn't logged. For more information, see [Secure strings and objects](data-types.md#secure-strings-and-objects). |
241247

242248
Decorators are in the [sys namespace](bicep-functions.md#namespaces-for-functions). If you need to differentiate a decorator from another item with the same name, preface the decorator with `sys`. For example, if your Bicep file includes a variable named `description`, you must add the sys namespace when using the **description** decorator.
243249

@@ -267,10 +273,65 @@ Markdown-formatted text can be used for the description text.
267273

268274
Use `@export()` to share the user-defined data type with other Bicep files. For more information, see [Export variables, types, and functions](./bicep-import.md#export-variables-types-and-functions).
269275

276+
### Integer constraints
277+
278+
You can set minimum and maximum values for integer type. You can set one or both constraints.
279+
280+
```bicep
281+
@minValue(1)
282+
@maxValue(12)
283+
type month int
284+
```
285+
286+
### Length constraints
287+
288+
You can specify minimum and maximum lengths for string and array types. You can set one or both constraints. For strings, the length indicates the number of characters. For arrays, the length indicates the number of items in the array.
289+
290+
The following example declares two type. One type is for a storage account name that must have 3-24 characters. The other type is an array that must have from 1-5 items.
291+
292+
```bicep
293+
@minLength(3)
294+
@maxLength(24)
295+
type storageAccountName string
296+
297+
@minLength(1)
298+
@maxLength(5)
299+
type appNames array
300+
```
301+
302+
### Metadata
303+
304+
If you have custom properties that you want to apply to a user-defined data type, add a metadata decorator. Within the metadata, define an object with the custom names and values. The object you define for the metadata can contain properties of any name and type.
305+
306+
You might use this decorator to track information about the data type that doesn't make sense to add to the [description](#description).
307+
308+
```bicep
309+
@description('Configuration values that are applied when the application starts.')
310+
@metadata({
311+
source: 'database'
312+
contact: 'Web team'
313+
})
314+
type settings object
315+
```
316+
317+
When you provide a `@metadata()` decorator with a property that conflicts with another decorator, that decorator always takes precedence over anything in the `@metadata()` decorator. So, the conflicting property within the `@metadata()` value is redundant and will be replaced. For more information, see [No conflicting metadata](./linter-rule-no-conflicting-metadata.md).
318+
270319
### Sealed
271320

272321
See [Elevate error level](#elevate-error-level).
273322

323+
### Secure types
324+
325+
You can mark string or object user-defined data type as secure. The value of a secure type isn't saved to the deployment history and isn't logged.
326+
327+
```bicep
328+
@secure()
329+
type demoPassword string
330+
331+
@secure()
332+
type demoSecretObject object
333+
```
334+
274335
## Elevate error level
275336

276337
By default, declaring an object type in Bicep allows it to accept additional properties of any type. For example, the following Bicep is valid but raises a warning of [BCP089] - `The property "otionalProperty" is not allowed on objects of type "{ property: string, optionalProperty: null | string }". Did you mean "optionalProperty"?`:

articles/azure-resource-manager/bicep/user-defined-functions.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Decorators are written in the format `@expression` and are placed above function
110110
| --------- | ----------- | ------- |
111111
| [description](#description) | string | Provide descriptions for the function. |
112112
| [export](#export) | none | Indicates that the function is available for import by another Bicep file. |
113+
| [metadata](#metadata) | object | Custom properties to apply to the function. Can include a description property that is equivalent to the description decorator. |
113114

114115
Decorators are in the [sys namespace](bicep-functions.md#namespaces-for-functions). If you need to differentiate a decorator from another item with the same name, preface the decorator with `sys`. For example, if your Bicep file includes a variable named `description`, you must add the sys namespace when using the **description** decorator.
115116

@@ -128,6 +129,23 @@ Markdown-formatted text can be used for the description text.
128129

129130
Use `@export()` to share the function with other Bicep files. For more information, see [Export variables, types, and functions](./bicep-import.md#export-variables-types-and-functions).
130131

132+
### Metadata
133+
134+
If you have custom properties that you want to apply to a user-defined function, add a metadata decorator. Within the metadata, define an object with the custom names and values. The object you define for the metadata can contain properties of any name and type.
135+
136+
You might use this decorator to track information about the function that doesn't make sense to add to the [description](#description).
137+
138+
```bicep
139+
@description('Configuration values that are applied when the application starts.')
140+
@metadata({
141+
source: 'database'
142+
contact: 'Web team'
143+
})
144+
type settings object
145+
```
146+
147+
When you provide a `@metadata()` decorator with a property that conflicts with another decorator, that decorator always takes precedence over anything in the `@metadata()` decorator. So, the conflicting property within the `@metadata()` value is redundant and will be replaced. For more information, see [No conflicting metadata](./linter-rule-no-conflicting-metadata.md).
148+
131149
## Next steps
132150

133151
* To learn about the Bicep file structure and syntax, see [Understand the structure and syntax of Bicep files](./file.md).

0 commit comments

Comments
 (0)