microsoft / microsoft/typespec
[Bug]: FilterVisibility to honor extends
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
Hi!
I upgraded to 1.13.0 and tried to apply the new `FilterVisibility` type:
```tsp
import "@typespec/http";
using TypeSpec.Reflection;
@service(#{ })
namespace Rpc;
// -----------------------------------------------------------------------------
model Base {
@visibility(Lifecycle.Read) id: string,
}
model Auditable extends Base {
@visibility(Lifecycle.Read) created_at: utcDateTime,
@visibility(Lifecycle.Read) created_by: string,
@visibility(Lifecycle.Read) updated_at: utcDateTime,
@visibility(Lifecycle.Read) updated_by: string,
}
// -----------------------------------------------------------------------------
model User extends Auditable {
name: string,
}
// -----------------------------------------------------------------------------
@doc("DTO to create {name}", T) model ObjectCreate is FilterVisibility {}
model UserCreate is ObjectCreate {}
// -----------------------------------------------------------------------------
```
The resulting spec is somewhat surprising to me:
```yaml
openapi: 3.0.0
info:
title: (title)
version: 0.0.0
tags: []
paths: {}
components:
schemas:
Auditable:
type: object
required:
- created_at
- created_by
- updated_at
- updated_by
properties:
created_at:
type: string
format: date-time
readOnly: true
created_by:
type: string
readOnly: true
updated_at:
type: string
format: date-time
readOnly: true
updated_by:
type: string
readOnly: true
allOf:
- $ref: '#/components/schemas/Base'
Base:
type: object
required:
- id
properties:
id:
type: string
readOnly: true
User:
type: object
required:
- name
properties:
name:
type: string
allOf:
- $ref: '#/components/schemas/Auditable'
UserCreate:
type: object
required:
- name
properties:
name:
type: string
allOf:
- $ref: '#/components/schemas/Auditable'
description: DTO to create User
```
That is, `Create` lifecycle is applied to explicit portion of `User` model, and inherited properties go on without visibility filter.
Is this the expected behavior?
Then, I made `User` model to read:
```tsp
model User extends Auditable {
@visibility(Lifecycle.Create) login: string,
name: string,
}
```
and encounter the compilation error:
`error
@typespec/openapi/duplicate-type-name
Duplicate type name: 'User'. Check @friendlyName decorators and overlap with types in TypeSpec or service namespace.`.
Wonder what is the cause of the (rather unexpeced) error?
TIA
_Originally posted by @dvv in https://github.com/microsoft/typespec/discussions/11034_
Contributor guide
Assessment
This issue has not been assessed yet.