Azure / typespec-azure

About TypeSpec Azure Libraries
https://azure.github.io/typespec-azure/
MIT License
15 stars 41 forks source link

[Bug]: ARM Private.enforceConstaint should allow armVirtualResource instead of strictly type check on Foundations.Resource #1344

Open allenjzhang opened 3 months ago

allenjzhang commented 3 months ago

Describe the bug

Cases exists where @armVirtualResource having actions. Standard ArmResourceXXX op template does strict resource base type check. In this case we should allow virtual resource as well so it can take advantage of standard template.

Proposal:

Loosen the contraint check ONLY on ArmResourceActionXXX. For other life cycle operations, virtual resource doesn't make sense.

Reproduction

@singleton
@parentResource(SubscriptionLocationResource)
@armVirtualResource
model SAPVirtualInstanceMetadata {
  /**
   * The default variable.
   */
  @path
  @visibility("read")
  @segment("sapVirtualInstanceMetadata")
  @key
  default: "string";
}
...
  /**
   * Gets the sizing recommendations.
   */
  getSizingRecommendations is ArmResourceActionSync<
    SAPVirtualInstanceMetadata,
    SAPSizingRecommendationRequest,
    SAPSizingRecommendationResult
  >;

Checklist

allenjzhang commented 3 months ago

Once this is fixed, fixing spec: /workspaces/azure-rest-api-specs-pr/specification/workloads/Workloads.SAPVirtualInstance.Management/custom.tsp

markcowl commented 2 months ago

@allenjzhang @armVirtualResource is not designed to be an endpoint, but a parent to a resource (i.e. in places where there is an additional path segment). Actions should occur only on resources or providers, according to the RPC.

We should not provide core template support for patterns that are outside the RPC. If we need to aupply a pattern for this, why not imply use primitive operations using @route?