|
| 1 | +--- |
| 2 | +applyTo: "**/*.Autorest/README.md" |
| 3 | +--- |
| 4 | + |
| 5 | +# AutoRest README.md Files |
| 6 | + |
| 7 | +When working with README.md files in AutoRest projects (*.Autorest directories), follow these specific guidelines for API specification references and directive documentation: |
| 8 | + |
| 9 | +## API Specification References |
| 10 | + |
| 11 | +### Always Use Commit Hash |
| 12 | +- **Never reference API specifications using branch names** (e.g., `main`, `master`) |
| 13 | +- **Always use specific commit hashes** to ensure reproducible builds |
| 14 | +- This prevents breaking changes when the specification repository evolves |
| 15 | + |
| 16 | +### Examples |
| 17 | + |
| 18 | +#### Good - Commit Hash Reference |
| 19 | +```yaml |
| 20 | +# lock the commit |
| 21 | +commit: 4442e8121686218ce2951ab4dc734e489aa5bc08 |
| 22 | +require: |
| 23 | + - $(this-folder)/../../readme.azure.noprofile.md |
| 24 | +input-file: |
| 25 | + - $(repo)/specification/quota/resource-manager/Microsoft.Quota/stable/2023-02-01/quota.json |
| 26 | +``` |
| 27 | +
|
| 28 | +#### Avoid - Branch Reference |
| 29 | +```yaml |
| 30 | +# Don't do this - branch references can change |
| 31 | +branch: main |
| 32 | +input-file: |
| 33 | + - https://github.com/Azure/azure-rest-api-specs/blob/main/specification/quota/resource-manager/Microsoft.Quota/stable/2023-02-01/quota.json |
| 34 | +``` |
| 35 | +
|
| 36 | +### Updating Specifications |
| 37 | +- When updating to a newer API specification, update the commit hash |
| 38 | +- Document the reason for the specification update in commit messages |
| 39 | +- Test thoroughly after specification updates |
| 40 | +
|
| 41 | +## Directive Documentation |
| 42 | +
|
| 43 | +### Write Comments for All Directives |
| 44 | +- **Every directive should have a comment explaining its purpose** |
| 45 | +- Comments should explain the "why" not just the "what" |
| 46 | +- Help future maintainers understand the intention behind customizations |
| 47 | +
|
| 48 | +### Directive Comment Patterns |
| 49 | +
|
| 50 | +#### Model Modifications |
| 51 | +```yaml |
| 52 | +directive: |
| 53 | + # Remove cmdlets that are not supported in the current API version |
| 54 | + - where: |
| 55 | + verb: Set |
| 56 | + remove: true |
| 57 | + |
| 58 | + # Simplify parameter names for better PowerShell experience |
| 59 | + - where: |
| 60 | + subject: ConfigProfile |
| 61 | + parameter-name: ConfigurationProfileAssignmentName |
| 62 | + set: |
| 63 | + parameter-name: Name |
| 64 | +``` |
| 65 | +
|
| 66 | +#### Property Customizations |
| 67 | +```yaml |
| 68 | +directive: |
| 69 | + # Configure table formatting to show most relevant properties first |
| 70 | + - where: |
| 71 | + model-name: SupportTicketDetails |
| 72 | + set: |
| 73 | + format-table: |
| 74 | + properties: |
| 75 | + - Name |
| 76 | + - Title |
| 77 | + - SupportTicketId |
| 78 | + - Severity |
| 79 | + - ServiceDisplayName |
| 80 | + - CreatedDate |
| 81 | +``` |
| 82 | +
|
| 83 | +#### API Filtering |
| 84 | +```yaml |
| 85 | +directive: |
| 86 | + # Remove preview API operations that are not ready for public use |
| 87 | + - where: |
| 88 | + subject: ^ConfigProfileVersion$ |
| 89 | + remove: true |
| 90 | + |
| 91 | + # Hide internal-only cmdlets from public interface |
| 92 | + - where: |
| 93 | + verb: Invoke |
| 94 | + subject: UploadFile |
| 95 | + hide: true |
| 96 | +``` |
| 97 | +
|
| 98 | +### Comment Guidelines |
| 99 | +
|
| 100 | +#### Be Specific About Purpose |
| 101 | +```yaml |
| 102 | +# Good - Explains the business reason |
| 103 | +# Remove Set cmdlets because they are not supported in this API version |
| 104 | +- where: |
| 105 | + verb: Set |
| 106 | + remove: true |
| 107 | + |
| 108 | +# Avoid - Too generic |
| 109 | +# Remove cmdlets |
| 110 | +- where: |
| 111 | + verb: Set |
| 112 | + remove: true |
| 113 | +``` |
| 114 | +
|
| 115 | +#### Explain Complex Transformations |
| 116 | +```yaml |
| 117 | +# Good - Explains the technical reasoning |
| 118 | +# Transform parameter validation to handle special case where top=0 disables pagination |
| 119 | +- from: GetAzSupportTicket_List.cs |
| 120 | + where: $ |
| 121 | + transform: $ = $.replace("!String.IsNullOrEmpty(_nextLink)" ,"!String.IsNullOrEmpty(_nextLink) && this._top <= 0"); |
| 122 | + |
| 123 | +# Better - More detailed explanation |
| 124 | +# Fix pagination logic: when Top parameter is 0, disable automatic pagination |
| 125 | +# This prevents infinite loops when users explicitly request no pagination |
| 126 | +- from: GetAzSupportTicket_List.cs |
| 127 | + where: $ |
| 128 | + transform: $ = $.replace("!String.IsNullOrEmpty(_nextLink)" ,"!String.IsNullOrEmpty(_nextLink) && this._top <= 0"); |
| 129 | +``` |
| 130 | +
|
| 131 | +## README Structure Best Practices |
| 132 | +
|
| 133 | +### Standard Sections |
| 134 | +Include these sections in AutoRest README.md files: |
| 135 | +
|
| 136 | +1. **Module Overview** - Brief description of the Azure service |
| 137 | +2. **Module Requirements** - Az.Accounts version requirements |
| 138 | +3. **Authentication** - How authentication is handled |
| 139 | +4. **Development** - Link to how-to.md for development instructions |
| 140 | +5. **AutoRest Configuration** - YAML configuration with well-commented directives |
| 141 | +
|
| 142 | +### Example Template |
| 143 | +```markdown |
| 144 | +# Az.ServiceName |
| 145 | +This directory contains the PowerShell module for the [Azure Service Name]. |
| 146 | + |
| 147 | +## Module Requirements |
| 148 | +- [Az.Accounts module](https://www.powershellgallery.com/packages/Az.Accounts/), version 2.7.5 or greater |
| 149 | + |
| 150 | +## Authentication |
| 151 | +AutoRest does not generate authentication code for the module. Authentication is handled via Az.Accounts. |
| 152 | + |
| 153 | +## Development |
| 154 | +For information on how to develop for `Az.ServiceName`, see [how-to.md](how-to.md). |
| 155 | + |
| 156 | +### AutoRest Configuration |
| 157 | + |
| 158 | +``` yaml |
| 159 | +# Lock to specific commit for reproducible builds |
| 160 | +commit: [commit-hash-here] |
| 161 | +require: |
| 162 | + - $(this-folder)/../../readme.azure.noprofile.md |
| 163 | +input-file: |
| 164 | + - $(repo)/specification/service/resource-manager/Microsoft.Service/stable/2023-01-01/service.json |
| 165 | +
|
| 166 | +directive: |
| 167 | + # [Well-commented directives explaining customizations] |
| 168 | +``` |
| 169 | + |
| 170 | +## Maintenance Notes |
| 171 | + |
| 172 | +### Regular Reviews |
| 173 | +- Review commit hashes periodically for security updates |
| 174 | +- Update API specification versions when new stable versions are available |
| 175 | +- Keep directive comments up-to-date when making changes |
| 176 | + |
| 177 | +### Documentation Links |
| 178 | +- Ensure links to external documentation remain valid |
| 179 | +- Update version numbers in requirements when Az.Accounts updates |
| 180 | +- Verify that how-to.md files exist and are current |
0 commit comments