microsoft / microsoft/typespec
[Bug]: @madeRequired breaks OptionalProperties
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
### Describe the bug
Corner case follow-up to https://github.com/microsoft/typespec/pull/441.
When using the [OptionalProperties](https://typespec.io/docs/standard-library/built-in-data-types/#OptionalProperties) template on a model that includes a [@madeRequired](https://typespec.io/docs/libraries/versioning/reference/decorators/#@TypeSpec.Versioning.madeRequired) decorator, the decorator is preserved in the generated model which causes a compiler error.
Compiling the reproducer below results in:
```
TypeSpec compiler v1.13.0
× Compiling
Diagnostics were reported during compilation:
main.tsp:12:3 - error @typespec/versioning/made-required-optional: Property 'foo?' marked with @madeRequired but is optional. Should be 'foo'
> 12 | foo: string
| ^^^
Found 1 error.
```
I think `OptionalProperties` should omit `@madeRequired` decorators in the generated model.
### Reproduction
```
import "@typespec/versioning";
@TypeSpec.Versioning.versioned(Reproducer.Versions)
namespace Reproducer;
enum Versions {
demo: "demo"
}
model Required {
@TypeSpec.Versioning.madeRequired(Versions.demo)
foo: string
}
model Optional is OptionalProperties;
```
### Checklist
- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/Microsoft/typespec/discussions).
- [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.