Skip to content

Commit

Permalink
Uptake Enum-driven visibility (#1829)
Browse files Browse the repository at this point in the history
This PR is for validation of the uptake of
microsoft/typespec#4825

It masks some no-deprecated lint errors that result from the deprecation
of `getVisibility`

---------

Co-authored-by: Will Temple <will@wtemple.net>
  • Loading branch information
witemple-msft and willmtemple authored Nov 8, 2024
1 parent d0d9485 commit f9689c4
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
changeKind: internal
packages:
- "@azure-tools/typespec-autorest"
- "@azure-tools/typespec-azure-core"
- "@azure-tools/typespec-azure-resource-manager"
- "@azure-tools/typespec-client-generator-core"
---

Mask deprecation lint warnings for uptake of enum-driven visibility.
2 changes: 1 addition & 1 deletion core
Submodule core updated 196 files
2 changes: 2 additions & 0 deletions packages/typespec-autorest/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,7 @@ export async function getOpenAPIForService(
if (isReadonlyProperty(program, prop)) {
property.readOnly = true;
} else {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const vis = getVisibility(program, prop);
if (vis) {
const mutability = [];
Expand Down Expand Up @@ -2038,6 +2039,7 @@ export async function getOpenAPIForService(

function canSharePropertyUsingReadonlyOrXMSMutability(prop: ModelProperty) {
const sharedVisibilities = ["read", "create", "update", "write"];
// eslint-disable-next-line @typescript-eslint/no-deprecated
const visibilities = getVisibility(program, prop);
if (visibilities) {
for (const visibility of visibilities) {
Expand Down
1 change: 1 addition & 0 deletions packages/typespec-autorest/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export function resolveOperationId(context: AutorestEmitterContext, operation: O
* designate a read-only property.
*/
export function isReadonlyProperty(program: Program, property: ModelProperty) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const visibility = getVisibility(program, property);
// note: multiple visibilities that include read are not handled using
// readonly: true, but using separate schemas.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const requireKeyVisibility = createRule({
model.name !== "object"
) {
for (const [name, prop] of model.properties) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (isKey(context.program, prop) && !getVisibility(context.program, prop)) {
context.reportDiagnostic({
target: prop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const armResourceProvisioningStateRule = createRule({
}

// validate it must has a read only visibility
// eslint-disable-next-line @typescript-eslint/no-deprecated
const visibilities = getVisibility(context.program, provisioning);
if (
!(visibilities !== undefined && visibilities.length === 1 && visibilities[0] === "read")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const resourceNameRule = createRule({
}

function checkResourceName(nameProp: ModelProperty) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const visibilities = getVisibility(context.program, nameProp);
return (
!http.isPathParam(context.program, nameProp) ||
Expand Down
1 change: 1 addition & 0 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ export function isReadOnly(property: SdkBodyModelPropertyType) {
}

function getSdkVisibility(context: TCGCContext, type: ModelProperty): Visibility[] | undefined {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const visibility = getVisibility(context.program, type);
if (visibility) {
const result: Visibility[] = [];
Expand Down

0 comments on commit f9689c4

Please sign in to comment.