Skip to content

Commit ae5746c

Browse files
Add more info about JSONRPC (#19277)
###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/19277)
1 parent 44dcaa6 commit ae5746c

File tree

3 files changed

+333
-0
lines changed

3 files changed

+333
-0
lines changed

src/Bicep.RpcClient/Models/Models.cs

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,123 +10,272 @@ namespace Bicep.RpcClient.Models;
1010
// These models should be kept in sync with the corresponding models in the Bicep CLI, but must also be backwards-compatible,
1111
// as the JSONRPC client is able to communicate with multiple versions of the Bicep CLI.
1212

13+
/// <summary>
14+
/// Represents a zero-based position within a Bicep source file.
15+
/// </summary>
16+
/// <param name="Line">The zero-based line number.</param>
17+
/// <param name="Char">The zero-based character offset within the line.</param>
1318
public record Position(
1419
int Line,
1520
int Char);
1621

22+
/// <summary>
23+
/// Represents a range within a Bicep source file, defined by a start and end position.
24+
/// </summary>
25+
/// <param name="Start">The start position of the range (inclusive).</param>
26+
/// <param name="End">The end position of the range (exclusive).</param>
1727
public record Range(
1828
Position Start,
1929
Position End);
2030

31+
/// <summary>
32+
/// Request to retrieve the version of the Bicep CLI. This is a parameterless request.
33+
/// </summary>
2134
public record VersionRequest();
2235

36+
/// <summary>
37+
/// Response containing the Bicep CLI version.
38+
/// </summary>
39+
/// <param name="Version">The semantic version string of the Bicep CLI (e.g., <c>"0.38.5"</c>).</param>
2340
public record VersionResponse(
2441
string Version);
2542

43+
/// <summary>
44+
/// Request to compile a Bicep file (<c>.bicep</c>) into an ARM template.
45+
/// </summary>
46+
/// <param name="Path">The file path to the Bicep file to compile (e.g., <c>"./main.bicep"</c>).</param>
2647
public record CompileRequest(
2748
string Path);
2849

50+
/// <summary>
51+
/// Response from compiling a Bicep file.
52+
/// </summary>
53+
/// <param name="Success">Whether the compilation completed without errors.</param>
54+
/// <param name="Diagnostics">The collection of diagnostics (errors, warnings, informational messages) produced during compilation.</param>
55+
/// <param name="Contents">The compiled ARM template JSON string, or <see langword="null"/> if compilation failed.</param>
2956
public record CompileResponse(
3057
bool Success,
3158
ImmutableArray<DiagnosticDefinition> Diagnostics,
3259
string? Contents);
3360

61+
/// <summary>
62+
/// Request to compile a Bicep parameters file (<c>.bicepparam</c>) into ARM deployment parameters.
63+
/// </summary>
64+
/// <param name="Path">The file path to the <c>.bicepparam</c> file to compile.</param>
65+
/// <param name="ParameterOverrides">A dictionary of parameter names to JSON values that override the defaults specified in the parameters file.</param>
3466
public record CompileParamsRequest(
3567
string Path,
3668
Dictionary<string, JsonNode> ParameterOverrides);
3769

70+
/// <summary>
71+
/// Response from compiling a Bicep parameters file.
72+
/// </summary>
73+
/// <param name="Success">Whether the compilation completed without errors.</param>
74+
/// <param name="Diagnostics">The collection of diagnostics produced during compilation.</param>
75+
/// <param name="Parameters">The compiled ARM parameters JSON string, or <see langword="null"/> if compilation failed.</param>
76+
/// <param name="Template">The compiled ARM template JSON string referenced by the parameters file, or <see langword="null"/> if not resolvable.</param>
77+
/// <param name="TemplateSpecId">The Azure resource ID of the template spec, if the parameters file references one; otherwise <see langword="null"/>.</param>
3878
public record CompileParamsResponse(
3979
bool Success,
4080
ImmutableArray<DiagnosticDefinition> Diagnostics,
4181
string? Parameters,
4282
string? Template,
4383
string? TemplateSpecId);
4484

85+
/// <summary>
86+
/// Represents a single diagnostic message produced during Bicep compilation or analysis.
87+
/// </summary>
88+
/// <param name="Source">The source of the diagnostic (e.g., <c>"bicep"</c> for compiler diagnostics or a linter rule name).</param>
89+
/// <param name="Range">The source location range where the diagnostic applies.</param>
90+
/// <param name="Level">The severity level of the diagnostic: <c>"Error"</c>, <c>"Warning"</c>, or <c>"Info"</c>.</param>
91+
/// <param name="Code">The diagnostic code (e.g., <c>"BCP001"</c>) that uniquely identifies the diagnostic type.</param>
92+
/// <param name="Message">The human-readable diagnostic message.</param>
4593
public record DiagnosticDefinition(
4694
string Source,
4795
Range Range,
4896
string Level,
4997
string Code,
5098
string Message);
5199

100+
/// <summary>
101+
/// Request to retrieve all file references (modules, extensions, and other dependencies) used by a Bicep file.
102+
/// </summary>
103+
/// <param name="Path">The file path to the Bicep file to analyze.</param>
52104
public record GetFileReferencesRequest(
53105
string Path);
54106

107+
/// <summary>
108+
/// Response containing all file references used by a Bicep file.
109+
/// </summary>
110+
/// <param name="FilePaths">The collection of absolute file paths referenced by the Bicep file, including modules, loaded files, and the file itself.</param>
55111
public record GetFileReferencesResponse(
56112
ImmutableArray<string> FilePaths);
57113

114+
/// <summary>
115+
/// Request to retrieve metadata about a Bicep file, including its parameters, outputs, and exports.
116+
/// </summary>
117+
/// <param name="Path">The file path to the Bicep file to analyze.</param>
58118
public record GetMetadataRequest(
59119
string Path);
60120

121+
/// <summary>
122+
/// Request to generate a snapshot of a Bicep parameters file with deployment metadata.
123+
/// The snapshot captures the resolved state of the parameters file along with contextual deployment information.
124+
/// Requires Bicep CLI version 0.36.1 or later.
125+
/// </summary>
126+
/// <param name="Path">The file path to the <c>.bicepparam</c> file.</param>
127+
/// <param name="Metadata">Deployment metadata providing Azure context such as subscription, resource group, and location.</param>
128+
/// <param name="ExternalInputs">Optional collection of external input values to inject into the snapshot. Pass <see langword="null"/> if no external inputs are needed.</param>
61129
public record GetSnapshotRequest(
62130
string Path,
63131
GetSnapshotRequest.MetadataDefinition Metadata,
64132
ImmutableArray<GetSnapshotRequest.ExternalInputValue>? ExternalInputs)
65133
{
134+
/// <summary>
135+
/// Azure deployment metadata providing context for snapshot generation.
136+
/// All fields are optional and may be <see langword="null"/> if not applicable.
137+
/// </summary>
138+
/// <param name="TenantId">The Azure Active Directory tenant ID (e.g., <c>"00000000-0000-0000-0000-000000000001"</c>).</param>
139+
/// <param name="SubscriptionId">The Azure subscription ID (e.g., <c>"00000000-0000-0000-0000-000000000002"</c>).</param>
140+
/// <param name="ResourceGroup">The target resource group name (e.g., <c>"my-rg"</c>).</param>
141+
/// <param name="Location">The Azure region for the deployment (e.g., <c>"eastus"</c>).</param>
142+
/// <param name="DeploymentName">The name of the deployment (e.g., <c>"my-deployment"</c>).</param>
66143
public record MetadataDefinition(
67144
string? TenantId,
68145
string? SubscriptionId,
69146
string? ResourceGroup,
70147
string? Location,
71148
string? DeploymentName);
72149

150+
/// <summary>
151+
/// Represents an external input value to be injected into a snapshot.
152+
/// </summary>
153+
/// <param name="Kind">The kind of external input (e.g., the input provider type).</param>
154+
/// <param name="Config">Optional JSON configuration for the external input, or <see langword="null"/> if no configuration is needed.</param>
155+
/// <param name="Value">The JSON value for the external input.</param>
73156
public record ExternalInputValue(
74157
string Kind,
75158
JsonNode? Config,
76159
JsonNode Value);
77160
}
78161

162+
/// <summary>
163+
/// Response containing the generated snapshot of a Bicep parameters file.
164+
/// </summary>
165+
/// <param name="Snapshot">The snapshot content as a JSON string representing the resolved deployment state.</param>
79166
public record GetSnapshotResponse(
80167
string Snapshot);
81168

169+
/// <summary>
170+
/// Response containing metadata about a Bicep file's structure and exported symbols.
171+
/// </summary>
172+
/// <param name="Metadata">The collection of file-level metadata entries (e.g., metadata declared with <c>metadata</c> keyword).</param>
173+
/// <param name="Parameters">The collection of parameter definitions declared in the Bicep file.</param>
174+
/// <param name="Outputs">The collection of output definitions declared in the Bicep file.</param>
175+
/// <param name="Exports">The collection of exported symbols (types, variables, functions) declared with the <c>@export()</c> decorator.</param>
82176
public record GetMetadataResponse(
83177
ImmutableArray<GetMetadataResponse.MetadataDefinition> Metadata,
84178
ImmutableArray<GetMetadataResponse.SymbolDefinition> Parameters,
85179
ImmutableArray<GetMetadataResponse.SymbolDefinition> Outputs,
86180
ImmutableArray<GetMetadataResponse.ExportDefinition> Exports)
87181
{
182+
/// <summary>
183+
/// Represents a parameter or output symbol in a Bicep file.
184+
/// </summary>
185+
/// <param name="Range">The source location range of the symbol declaration.</param>
186+
/// <param name="Name">The name of the parameter or output.</param>
187+
/// <param name="Type">The type definition of the symbol, or <see langword="null"/> if the type could not be resolved.</param>
188+
/// <param name="Description">The description from the <c>@description()</c> decorator, or <see langword="null"/> if not specified.</param>
88189
public record SymbolDefinition(
89190
Range Range,
90191
string Name,
91192
TypeDefinition? Type,
92193
string? Description);
93194

195+
/// <summary>
196+
/// Represents an exported symbol declared with the <c>@export()</c> decorator.
197+
/// </summary>
198+
/// <param name="Range">The source location range of the export declaration.</param>
199+
/// <param name="Name">The name of the exported symbol.</param>
200+
/// <param name="Kind">The kind of export (e.g., <c>"Type"</c>, <c>"Variable"</c>, <c>"Function"</c>).</param>
201+
/// <param name="Description">The description from the <c>@description()</c> decorator, or <see langword="null"/> if not specified.</param>
94202
public record ExportDefinition(
95203
Range Range,
96204
string Name,
97205
string Kind,
98206
string? Description);
99207

208+
/// <summary>
209+
/// Represents a type reference for a parameter or output.
210+
/// </summary>
211+
/// <param name="Range">The source location range of the type reference, or <see langword="null"/> for built-in types.</param>
212+
/// <param name="Name">The name of the type (e.g., <c>"string"</c>, <c>"int"</c>, <c>"object"</c>, or a user-defined type name).</param>
100213
public record TypeDefinition(
101214
Range? Range,
102215
string Name);
103216

217+
/// <summary>
218+
/// Represents a file-level metadata entry declared with the <c>metadata</c> keyword in a Bicep file.
219+
/// </summary>
220+
/// <param name="Name">The metadata key name (e.g., <c>"description"</c>, <c>"owner"</c>).</param>
221+
/// <param name="Value">The metadata value as a string.</param>
104222
public record MetadataDefinition(
105223
string Name,
106224
string Value);
107225
}
108226

227+
/// <summary>
228+
/// Request to retrieve the deployment graph for a Bicep file, representing resource dependencies.
229+
/// </summary>
230+
/// <param name="Path">The file path to the Bicep file to analyze.</param>
109231
public record GetDeploymentGraphRequest(
110232
string Path);
111233

234+
/// <summary>
235+
/// Response containing the deployment graph for a Bicep file.
236+
/// </summary>
237+
/// <param name="Nodes">The collection of resource nodes in the deployment graph.</param>
238+
/// <param name="Edges">The collection of dependency edges between resource nodes.</param>
112239
public record GetDeploymentGraphResponse(
113240
ImmutableArray<GetDeploymentGraphResponse.Node> Nodes,
114241
ImmutableArray<GetDeploymentGraphResponse.Edge> Edges)
115242
{
243+
/// <summary>
244+
/// Represents a resource node in the deployment graph.
245+
/// </summary>
246+
/// <param name="Range">The source location range of the resource declaration.</param>
247+
/// <param name="Name">The symbolic name of the resource in the Bicep file.</param>
248+
/// <param name="Type">The fully qualified Azure resource type (e.g., <c>"Microsoft.Storage/storageAccounts"</c>).</param>
249+
/// <param name="IsExisting">Whether this is a reference to an existing resource (declared with the <c>existing</c> keyword) rather than a new deployment.</param>
250+
/// <param name="RelativePath">The relative file path if this resource is defined in a module; otherwise <see langword="null"/>.</param>
116251
public record Node(
117252
Range Range,
118253
string Name,
119254
string Type,
120255
bool IsExisting,
121256
string? RelativePath);
122257

258+
/// <summary>
259+
/// Represents a directed dependency edge between two resource nodes in the deployment graph.
260+
/// </summary>
261+
/// <param name="Source">The symbolic name of the dependent resource (the resource that depends on the target).</param>
262+
/// <param name="Target">The symbolic name of the dependency (the resource being depended upon).</param>
123263
public record Edge(
124264
string Source,
125265
string Target);
126266
}
127267

268+
/// <summary>
269+
/// Request to format a Bicep file according to Bicep formatting standards.
270+
/// Requires Bicep CLI version 0.37.1 or later.
271+
/// </summary>
272+
/// <param name="Path">The file path to the Bicep file to format.</param>
128273
public record FormatRequest(
129274
string Path);
130275

276+
/// <summary>
277+
/// Response containing the formatted Bicep file content.
278+
/// </summary>
279+
/// <param name="Contents">The formatted Bicep source code as a string.</param>
131280
public record FormatResponse(
132281
string Contents);

0 commit comments

Comments
 (0)