|
| 1 | +--- |
| 2 | +description: Guidelines for creating cfn-lint schema extensions |
| 3 | +globs: src/cfnlint/data/schemas/extensions/**/*.json |
| 4 | +--- |
| 5 | +# Creating Schema Extensions for cfn-lint |
| 6 | + |
| 7 | +<rule> |
| 8 | +name: schema_extension_creation |
| 9 | +description: Guidelines for creating and maintaining schema extensions for cfn-lint |
| 10 | +filters: |
| 11 | + - type: file_extension |
| 12 | + pattern: "\.json$" |
| 13 | + - type: path |
| 14 | + pattern: "src/cfnlint/data/schemas/extensions/" |
| 15 | + |
| 16 | +actions: |
| 17 | + - type: suggest |
| 18 | + message: | |
| 19 | + When creating schema extensions for cfn-lint: |
| 20 | + |
| 21 | + 1. **Follow JSON Schema structure**: |
| 22 | + - Use standard JSON Schema with `if/then` conditional validation |
| 23 | + - Properly validate property types in the `if` clause |
| 24 | + - Use `false` as a schema value to disallow properties |
| 25 | + - Use descriptive file names that indicate what aspect is being validated |
| 26 | + |
| 27 | + 2. **Base extensions on AWS documentation**: |
| 28 | + - Read the official AWS CloudFormation documentation thoroughly |
| 29 | + - Focus on property constraints not covered by the base schema |
| 30 | + - Validate relationships between properties (e.g., when X is Y, Z must be A) |
| 31 | + - Document the source of the validation rule with comments or commit messages |
| 32 | + |
| 33 | + 3. **Organize extensions properly**: |
| 34 | + - Place extensions in the correct resource type directory |
| 35 | + - Create new directories for resource types if needed |
| 36 | + - Follow the existing naming conventions |
| 37 | + |
| 38 | + 4. **Test your extensions**: |
| 39 | + - Create test cases that should pass and fail |
| 40 | + - Ensure the error messages are clear and helpful |
| 41 | + |
| 42 | +examples: |
| 43 | + - input: | |
| 44 | + { |
| 45 | + "if": { |
| 46 | + "properties": { |
| 47 | + "TargetType": { |
| 48 | + "enum": ["lambda"] |
| 49 | + } |
| 50 | + } |
| 51 | + }, |
| 52 | + "then": { |
| 53 | + "properties": { |
| 54 | + "Protocol": { |
| 55 | + "enum": ["HTTP", "HTTPS"] |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + output: | |
| 61 | + { |
| 62 | + "if": { |
| 63 | + "properties": { |
| 64 | + "TargetType": { |
| 65 | + "enum": ["lambda"] |
| 66 | + }, |
| 67 | + "Protocol": { |
| 68 | + "type": "string" |
| 69 | + } |
| 70 | + }, |
| 71 | + "required": ["TargetType"] |
| 72 | + }, |
| 73 | + "then": { |
| 74 | + "properties": { |
| 75 | + "Protocol": false, |
| 76 | + "Port": false, |
| 77 | + "HealthCheckPath": false |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | +metadata: |
| 83 | + priority: high |
| 84 | + version: 1.0 |
| 85 | +</rule> |
0 commit comments