Skip to content

key-visibility-required

Id
@azure-tools/typespec-azure-core/key-visibility-required

Key properties need to have a Lifecycle visibility setting.

Key properties need to have an explicit Lifecycle visibility setting. Use the @visibility decorator to specify the appropriate visibility for key properties. Without explicit visibility, the key property uses default visibility which may not match the intended behavior.

  • Area: API, SDK

Missing key visibility can misrepresent the mutability of identity fields in the API and generated SDKs.

Key property without explicit visibility:

model Foo {
@key
name: string;
}

Key property with explicit Lifecycle.Read visibility:

model Foo {
@key
@visibility(Lifecycle.Read)
name: string;
}

Suppress only if an identity field is genuinely mutable; otherwise add a visibility decorator with the appropriate lifecycle visibility.