-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for type pointers that refer to something other than a to…
…p-level type definition to import closure calculation
- Loading branch information
Showing
2 changed files
with
124 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 5 additions & 9 deletions
14
src/Bicep.Core/Emit/CompileTimeImports/ArmTemplateHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Deployments.Core.Definitions.Schema; | ||
using Azure.Deployments.Templates.Engines; | ||
|
||
namespace Bicep.Core.Emit.CompileTimeImports; | ||
|
||
internal static class ArmTemplateHelpers | ||
{ | ||
private const string ArmTypeRefPrefix = "#/definitions/"; | ||
|
||
internal static ITemplateSchemaNode DereferenceArmType(SchemaValidationContext context, string typePointer) | ||
{ | ||
// TODO make LocalSchemaRefResolver in Azure.Deployments.Templates public | ||
if (!typePointer.StartsWith(ArmTypeRefPrefix) || | ||
typePointer[ArmTypeRefPrefix.Length..].Contains('/') || | ||
context.Definitions is null || | ||
!context.Definitions.TryGetValue(typePointer[ArmTypeRefPrefix.Length..], out var typeDefinition)) | ||
if (LocalSchemaRefResolver.ResolveLocalReference(context, typePointer, out var node, out var failureMessage)) | ||
{ | ||
throw new InvalidOperationException($"Invalid ARM template type reference ({typePointer}) encountered"); | ||
return node; | ||
} | ||
|
||
return typeDefinition; | ||
throw new InvalidOperationException($"Invalid ARM template type reference ({typePointer}) encountered: {failureMessage}"); | ||
} | ||
} |