-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[http/openapi] Use enum-driven visibility analysis APIs #5416
base: main
Are you sure you want to change the base?
[http/openapi] Use enum-driven visibility analysis APIs #5416
Conversation
…e/parameter visibility decorator metadata.
.chronus/changes/witemple-msft-http-visibility-enum-2024-11-19-13-8-4.md
Outdated
Show resolved
Hide resolved
All changed packages have been documented.
Show changes
|
You can try these changes here
|
…um' into witemple-msft/http-visibility-enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, one question: should we change the @parameterVisibility
and @returnTypeVisibility
decorators to accept enum visibility (or have I missed this being done previously?). Should we be clear that these are any
filters?
Also, does @parameterVisibility()
now effectively create an undefined any
filter, meaning that all properties are allowed?
@@ -180,6 +181,9 @@ export const $parameterVisibility: ParameterVisibilityDecorator = ( | |||
/** | |||
* Returns the visibilities of the parameters of the given operation, if provided with `@parameterVisibility`. | |||
* | |||
* @deprecated Use `getParameterVisibilityFilter` instead. | |||
* | |||
* @see {@link getParameterVisibilityFilter} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two deprecations on the operation visibility decorators will have to be approved by the breaking change review board. I will be surprised if anyone is using these filters, other than possibly the typespec-autorest emitter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no occurrences of getReturnTypeVisibility
or getParameterVisibility
within the packages
folder of typespec-azure. I doubt anything other than typespec itself was using these APIs.
@@ -218,6 +286,9 @@ export const $returnTypeVisibility: ReturnTypeVisibilityDecorator = ( | |||
/** | |||
* Returns the visibilities of the return type of the given operation, if provided with `@returnTypeVisibility`. | |||
* | |||
* @deprecated Use `getReturnTypeVisibilityFilter` instead. | |||
* | |||
* @see {@link getReturnTypeVisibilityFilter} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above
}, | ||
}; | ||
} | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want the default here to be to return a filter, so that this should be deprecated as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this question about HttpVisibilityProvider
or resolveRequestVisibility
? If former, it will always return a filter. If latter, it would be severely breaking. I did consider it, but don't think we can really swallow deprecating the whole HTTP Visibility
concept right now. I think instead of preemptively deprecating the HTTP-only Visibility
, my hope is that if the core APIs are used in the next couple of months (i.e., people switch to using getReturnTypeVisibilityFilter(..., HttpVisibilityProvider)
instead of resolveRequestVisibility
or MetadataInfo
, then HTTP's Visibility
will become a vestigial feature that we can deprecate once some emitters have really proved that this analysis API works for their use case (I'm going to do this for the JS server emitter).
@markcowl I can clarify that returnType/parameter visibility are specifying Good question on |
This PR brings the core enum-driven visibility system to parity with the existing visibility concepts and uses its new analysis methods in the HTTP and OpenAPI libraries.
Delete
andQuery
phases.Delete
applies when a resource is passed as an argument to a DELETE operation.Query
applies when a resource is passed as an argument to a GET or HEAD operation.any
constraint of the filter to be satisfied if it is missing OR if some modifier in the constraint is present. If theany
constraint is present, but empty, it will be unsatisfiable.getParameterVisibility
andgetReturnTypeVisibility
in favor ofgetParameterVisibilityFilter
andgetReturnTypeVisibilityFilter
which return VisibilityFilter objects instead ofstring[]
. Like the modifier analysis methods, the filter versions of these methods are infallible.getParameterVisibilityFilter
andgetReturnTypeVisibilityFilter
accept aVisibilityProvider
object that provides default visibility filters for parameters and return types if the parameter/returnType visibilities are not set explicitly. TypeSpec core exports anEmptyProvider
that always return filters with no constraints, suitable as a default. HTTP exportsHttpVisibilityProvider
, which must be used when working in HTTP, as it provides the HTTP-specific default visibility logic that determines visibility by verb.HttpVisibilityProvider
can be instantiated with either anHttpVerb
directly, in which case that exact verb will be used;HttpOperationOptions
, in which case the verbSelector will be used if present, otherwise the fallback logic will be used; or no argument in which case the fallback logic will always be used. This gives it parity withgetHttpOperation
.Visibility
through visibility filters instead of visibility string arrays. The HTTP Visibility concept is unchanged.Fixed a bug in http-server-csharp that was surfaced by these changes where a visibility constraint(invalidated by merge)Visibility.Create & Visibility.Update
was provided, resulting in Visibility.None and properties being made invisible, affecting effective type calculation for anonymous models.hasVisibility
andgetVisibilityForClass
were improperly initializing the visibility state. This didn't affect the new APIs, but it would cause the state of the legacy APIs to be corrupted if visibility is queried from the new APIs before the legacy APIs.Closes #5119
Closes #5120