[Bug]: Lifecycle.Read properties marked as required in generated swagger
- Dominant language
- TypeScript
- Stars
- 27
- Forks
- 90
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 156
Description
### Describe the bug
We are an Azure resource provider and some of our resources, as defined in our TypeSpec files, have a few read-only properties. We have marked these properties with Lifecycle.Read.
Example:
https://github.com/Azure/azure-rest-api-specs-pr/blob/5729860481db39f079e9fe0d443886345ea8f5b9/specification/relationships/Relationships.Management/main.tsp#L101
That said, in the generated swagger document, this property is both marked as 'readOnly: true' and is listed in the types 'required' section.
Example:
https://github.com/Azure/azure-rest-api-specs-pr/blob/5729860481db39f079e9fe0d443886345ea8f5b9/specification/relationships/resource-manager/Microsoft.Relationships/preview/2023-09-01-preview/relationships.json#L686
Having a property marked as required means tooling like Terraform and Bicep expects this property to be provided during resource creation (i.e. HTTP PUT requests) but we do not require or want values for these properties provided.
It seems Bicep has fixed this on downstream on their side https://github.com/Azure/bicep-types-az/pull/2568.
Terraform has not, but I do believe the source of the problem is in the swagger generator.
### Reproduction
Typespec
https://github.com/Azure/azure-rest-api-specs-pr/blob/5729860481db39f079e9fe0d443886345ea8f5b9/specification/relationships/Relationships.Management/main.tsp#L101
Generated Swagger
https://github.com/Azure/azure-rest-api-specs-pr/blob/5729860481db39f079e9fe0d443886345ea8f5b9/specification/relationships/resource-manager/Microsoft.Relationships/preview/2023-09-01-preview/relationships.json#L686
### Checklist
- [x] Follow our [Code of Conduct](https://github.com/azure/typespec-azure/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that this issue is about the Azure libraries for typespec. For bug in the typespec language or core libraries file it in the [TypeSpec repo](https://github.com/Microsoft/TypeSpec/issues/new/choose)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
Contributor guide
Assessment
This issue has not been assessed yet.