[Bug]: Generated swagger may contain incompatible properties
- Dominant language
- TypeScript
- Stars
- 27
- Forks
- 90
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 156
Description
### Describe the bug
I believe the problem is this TypeSpec:
```
model Model1 is ProxyResource<{}> {
}
model Model2 extends Model1 {
properties: Model2Properties;
}
```
The `properties` property between these two models is not compatible, which generates this swagger which is also invalid (at least according to our BreakingChanges tool):
```
"Model2": {
"properties": {
"properties": {
"$ref": "#/definitions/Model2Properties",
}
},
"allOf": [
{
"$ref": "#/definitions/Model1"
}
],
},
"Model1": {
"properties": {
"properties": {
"type": "object",
},
},
}
```
Should TypeSpec detect this case, and generate an error or warning at the TypeSpec level?
### Reproduction
This spec is causing our BreakingChanges tool to crash with error "incompatible properties":
https://github.com/Azure/azure-rest-api-specs-pr/pull/19678/checks?check_run_id=31035653031
Minimal repro in playground: [TypeSpec Azure](https://azure.github.io/typespec-azure/playground?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7CtIZcmVzdNUZdmVyc2lvbmluZ8wfYXp1cmUtdG9vbHMvyCstxhVjb3Jl3yvIK3Jlc291cmNlLW1hbmFnZXIiOwoKdXNpbmcgVHlwZVNwZWMuSHR0cDvQFVJlc3TRFVbpAKnIG0HEZS5Db3JlzhJSx3dNxnY7CgovKiogQ29udG9zbyDIHiBQcm92aWRlciDmAJ5tZW50IEFQSS4gKi8KQGFybcggTmFtZXNwYWNlCkBzZXJ2aWNlKHsKICB0aXRsZTogIsdYyC5IdWJDbGllbnQiLAp9KQpA5wFgZWQo5wDBcykKbshSIE1pY3Jvc29mdC7SR%2B8AuEFQSSDHTXPkAKNlbnVtIMhUIOQAksQuMjAyMS0xMC0wMS1wcmV2aWV3yDXENCAgQHVzZURlcGVuZGVuY3ko9QEx6AFrcy52MV8wX1DGSF8xKcRAYXJtQ29tbW9u5AGZc8cq10jLKctUNcRIYPIAqWAsCn0KCm1vZGVsIEZv5AEKcGVydGll5gDdQHZpc2liaWxpdHkoInJlYWQixEdjdXJyZW50x10%2FOiBzdHLlAiIKICBkZXNjcmlwdGlvbs0Y1kpw5AF55wJhU3RhdGU%2FOuYCIswUO%2B0AoiBpcyBUcmFja2Vk6AD6PO0AuT7lALouLukBGeQCS1BhcmFtZXRlcsQsPsRSI3N1cHByZXNz%2FwNO7wNOL2FybcoV7ADALXPkAK0iICIiCkBwYeQBIegAgShGb28pCkDINigi6AJSIikKQGRp5AExbWluYXRvcigia2lu5AEb6QDv5wFl5AD2UHJveHnIVDx7ff8A6Qogy0AsCiAgxh90dGVybiA9ICJeWzAtOV0rXFwuzwkkIgogID7lAbb%2FASX%2FASXHFWludmFsaWQtZW52ZWxvcOUBNuQBrHnlASwgIOQA8zrrAKzkArvlAfRAZG9jKCJIZWxtIFNvbHXkAlTkAQXnAejsASZCYXIgZXh0ZW5kc8tJ5QEgx21pZXPFZEJhcspDO9d%2BLkZvb%2BUAgnVuxEfOHcVWRm9vOiAiRm9vIuQBWuYC6O4DSs1pxTRmxDT%2FAxP%2FAxPtAxPkBHpUaGXNMiDlAoUgb2YgYSDoAYHmBVxscm%2FEO3Vz5wDV0VTlAKToAMrnBNnEX8hHIGNyZcQncmVxdWVzdCBoYXMgYmVlbiBhY2NlcHRlZMRnICBBxw46ICLICyLWUGnEQOQAtOkAwchE7ACcOiAizA%2FaTHVwZGF0xE%2FFQ1XHDjogIsgLyjvpBo7pAMTmANxk5QErICBTdWNjZWVk5QDFyQzTP8U25AFNZmFpbMk%2BRsUN5AIfxQncOHdhcyBjYW5jZco%2BQ8cP5Ablxwv%2FAUAgZGVsZekBgETEDeYA%2BcgL5AcVCgppbnRlcmbkBwBPcGVy5QCAc%2BkDNfYGS8spe30KCg%3D%3D&e=%40azure-tools%2Ftypespec-autorest&options=%7B%22linterRuleSet%22%3A%7B%22extends%22%3A%5B%22%40azure-tools%2Ftypespec-azure-rulesets%2Fresource-manager%22%5D%7D%7D)
### 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
Research direction
Start with the minimal TypeSpec reproduction in the linked TypeSpec Azure playground and compare its generated Swagger with the BreakingChanges tool failure from PR 19678. Trace the model inheritance and property generation path; done means incompatible inherited properties are detected with an appropriate TypeSpec-level error or warning, and the reproduction no longer produces invalid Swagger.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100