Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ internal class RequestPathPattern : IEquatable<RequestPathPattern>, IReadOnlyLis
public static readonly RequestPathPattern ManagementGroup = new("/providers/Microsoft.Management/managementGroups/{managementGroupId}");
public static readonly RequestPathPattern ResourceGroup = new("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}");
public static readonly RequestPathPattern Subscription = new("/subscriptions/{subscriptionId}");
public static readonly RequestPathPattern Extension = new("/{resourceUri}");

public static readonly RequestPathPattern Tenant = new(string.Empty);

public static RequestPathPattern GetFromScope(ResourceScope scope)
public static RequestPathPattern GetFromScope(ResourceScope scope, RequestPathPattern? path = null)
{
return scope switch
{
ResourceScope.ResourceGroup => ResourceGroup,
ResourceScope.Subscription => Subscription,
ResourceScope.ManagementGroup => ManagementGroup,
ResourceScope.Extension => Extension,
ResourceScope.Extension =>
path is null
? throw new InvalidOperationException("Extension scope requires a path parameter.")
: new RequestPathPattern(path._segments.Take(1)),
ResourceScope.Tenant => Tenant,
_ => throw new InvalidOperationException($"Unhandled scope {scope}"),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal static ResourceMetadata DeserializeResourceMetadata(IReadOnlyDictionary
}

//TODO: handle Extension resource in emitter
if (resourceIdPattern is not null && resourceIdPattern.StartsWith("/{resourceUri}/"))
if (resourceIdPattern is not null && (resourceIdPattern.StartsWith("/{resourceUri}/") || resourceIdPattern.StartsWith("/{scope}/")))
{
resourceScope = ResourceScope.Extension;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ private static RequestPathPattern GetContextualRequestPattern(ResourceMetadata r
return new RequestPathPattern(resourceMetadata.ParentResourceId);
}

if (resourceMetadata.ResourceScope == ResourceScope.Extension)
{
if (string.IsNullOrEmpty(resourceMetadata.ResourceIdPattern))
{
throw new InvalidOperationException("Extension resource's IdPattern can't be empty or null.");
}
return RequestPathPattern.GetFromScope(resourceMetadata.ResourceScope, new RequestPathPattern(resourceMetadata.ResourceIdPattern));
}

return RequestPathPattern.GetFromScope(resourceMetadata.ResourceScope);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ private static void BuildContextualParameterHierarchy(RequestPathPattern current
// using the reference name of the last segment as the parameter name, aka resourceGroupName
parameterStack.Push(new ContextualParameter(current[^2].Value, current[^1].VariableName, id => id.ResourceGroupName()));
}
else if (current == RequestPathPattern.Extension)
else if (current.Count == 1 && !current[0].IsConstant) // Extension resource case: single variable segment. Here we assume the extension resource's requestPathPattern start with one and only one variable segment
{
parameterStack.Push(new ContextualParameter("resourceUri", "resourceUri", id => BuildParentInvocation(parentLayerCount, id)));
// Extension resource case: single variable segment
parameterStack.Push(new ContextualParameter(current[0].VariableName, current[0].VariableName, id => BuildParentInvocation(parentLayerCount, id)));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "./baz.tsp";
import "./zoo.tsp";
import "./routes.tsp";
import "./endpoint.tsp";
import "./selfhelp.tsp";

using TypeSpec.Versioning;
using Azure.ClientGenerator.Core;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@typespec/openapi";
import "@typespec/rest";

using Azure.ResourceManager;
using TypeSpec.Http;
using TypeSpec.OpenAPI;

namespace MgmtTypeSpec;

model SelfHelpResource
is Azure.ResourceManager.ExtensionResource<SelfHelpResourceProperties> {
...ResourceNameParameter<
Resource = SelfHelpResource,
KeyName = "selfHelpName",
SegmentName = "selfHelps",
NamePattern = ""
>;
}

model SelfHelpResourceProperties {
selfHelpId: string;
}

#suppress "@azure-tools/typespec-azure-resource-manager/no-resource-delete-operation" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
@armResourceOperations
interface SolutionResources {
get is Extension.Read<Extension.ScopeParameter, SelfHelpResource>;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading