Skip to content

[Bug]: FilterVisibility to honor extends #11036

Description

@dvv

Hi!

I upgraded to 1.13.0 and tried to apply the new FilterVisibility type:

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<T extends Model> is FilterVisibility<T, #{ all: #[Lifecycle.Create] }, "{name}Create"> {}

model UserCreate is ObjectCreate<User> {}

// -----------------------------------------------------------------------------

The resulting spec is somewhat surprising to me:

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:

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 #11034

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions