Decorators
Decorators add metadata, validation, and constraints to declarations. Kite has 17 built-in decorators.
Syntax
@decoratorName@decoratorName(argument)@decoratorName(namedArg: value)Multiple decorators can be stacked:
@description("Server port")@minValue(1)@maxValue(65535)input number port = 8080Validation Decorators
@minValue(n)
Minimum value constraint for numbers.
@minValue(1)input number port = 8080@minValue(0)input number count = 10@maxValue(n)
Maximum value constraint for numbers.
@maxValue(65535)input number port = 8080@maxValue(100)input number percentage = 50@minLength(n)
Minimum length for strings and arrays.
@minLength(3)input string name@minLength(1)input string[] tags@maxLength(n)
Maximum length for strings and arrays.
@maxLength(255)input string name@maxLength(10)input string[] tags@nonEmpty
Ensures strings or arrays are not empty.
@nonEmptyinput string name@nonEmptyinput string[] requiredTags@validate(regex: "pattern")
Custom validation with regex pattern or preset.
// Regex validation@validate(regex: "^[a-z]+$")input string name@validate(regex: "^[a-z0-9-]+$")input string slug// Preset validation@validate(preset: "email")input string email@allowed([values])
Whitelist of allowed values.
@allowed(["dev", "staging", "prod"])input string environment = "dev"@allowed([80, 443, 8080])input number port = 80@unique
Ensures array elements are unique.
@uniqueinput string[] tags = ["web", "api"]@uniqueinput number[] ports = [80, 443, 8080]Schema Decorators
@cloud
Marks properties as cloud-generated (set by provider after creation).
schema AwsInstance { string name // User-set @cloud string arn // Cloud-generated @cloud(importable) string id // Cloud-generated, importable}Syntax forms:
@cloud- Cloud-generated, not importable@cloud(importable)- Shorthand for importable=true@cloud(importable=true)- Explicit true@cloud(importable=false)- Same as plain @cloud
Resource Decorators
@existing("reference")
Reference existing cloud resources.
@existing("arn:aws:s3:::my-bucket")resource S3.Bucket existingBucket {}@existing("i-0123456789abcdef0")resource EC2.Instance existingServer {}Supported formats:
- ARN:
arn:aws:s3:::bucket-name - URL:
https://example.comors3://bucket/key - EC2 Instance ID:
i-0123456789abcdef0 - KMS Alias:
alias/my-key - Log Group:
/aws/lambda/my-function - Tags:
Environment=prod,Team=platform
@sensitive
Mark sensitive data (passwords, secrets, API keys).
@sensitiveinput string apiKey@sensitiveoutput string connectionString@sensitiveresource RDS.Instance database { ... }@dependsOn(resources)
Explicit dependency declaration.
resource VPC.Subnet subnet { ... }@dependsOn(subnet)resource EC2.Instance server { ... }@dependsOn([vpc, subnet, securityGroup])resource RDS.Instance database { ... }@tags(tags)
Add cloud provider tags.
// Object format@tags({ Environment: "prod", Team: "platform" })resource S3.Bucket photos { ... }// Array format@tags(["Environment =prod", "Team=platform"])resource EC2.Instance server { ... }// String format@tags("Environment =prod")resource RDS.Instance db { ... }@provider(providers)
Target specific cloud providers.
@provider("aws")resource S3.Bucket photos { ... }@provider(["aws", "azure"])resource Storage.Bucket multiCloud { ... }@count(n)
Create multiple instances. Injects count variable (0-indexed).
@count(3)resource EC2.Instance server { name = "server-${count}" // server-0, server-1, server-2}@count(replicas)component WebServer api { input number index = count}Metadata Decorators
@description("text")
Documentation for any declaration.
@description("The port number for the web server")input number port = 8080@description("Main application database")resource RDS.Instance database { ... }@description("User configuration schema")schema Config { ... }@description("Calculate the area of a rectangle")fun area(number w, number h) number { ... }Quick Reference
| Decorator | Arguments | Targets |
|---|---|---|
@minValue(n) | number | input, output |
@maxValue(n) | number | input, output |
@minLength(n) | number | input, output |
@maxLength(n) | number | input, output |
@nonEmpty | none | input |
@validate(regex:, preset:) | named strings | input, output |
@allowed([...]) | array | input, schema property |
@unique | none | input |
@cloud | optional: importable | schema property |
@existing("ref") | string | resource |
@sensitive | none | input, output |
@dependsOn(res) | reference(s) | resource, component |
@tags({...}) | object/array/string | resource, component |
@provider("...") | string/array | resource, component |
@description("...") | string | all declarations |
@count(n) | number | resource, component |
Syntax Rules
// Valid - single positional argument@provider("aws")@provider(["aws", "azure"]) // Array is ONE argument// Valid - named arguments@validate(regex: "^[a-z]+$")// Invalid - multiple positional arguments@provider("aws", "azure") // ERROR: use array insteadObject Key Validation
Decorator object keys must be alphanumeric:
// Valid@tags({ envStage: "prod" }) // underscore OK@tags({ cloudProvider: "aws" }) // hyphen OK@tags({ Environment: "production" })// Invalid@tags({ "env stage": "prod" }) // space not allowed@tags({ "123start": "value" }) // can't start with numberPattern: ^[a-zA-Z][a-zA-Z0-9_-]*$
Next: Learn about the Standard Library - built-in functions.