Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit db56bee

Browse files
committed
add comments
1 parent b3399a6 commit db56bee

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

src/APIM_ARMTemplate/apimtemplate/Commands/Create.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public CreateCommand()
1717
// list command options
1818
CommandOption openAPISpecFile = this.Option("--openAPISpecFile <openAPISpecFile>", "Open API spec file location", CommandOptionType.SingleValue);
1919
CommandOption openAPISpecURL = this.Option("--openAPISpecURL <openAPISpecURL>", "Open API spec remote url", CommandOptionType.SingleValue);
20-
CommandOption outputLocation = this.Option("--outputLocation <outputLocation>", "Template output location", CommandOptionType.SingleValue);
20+
CommandOption outputLocation = this.Option("--outputLocation <outputLocation>", "Template output location", CommandOptionType.SingleValue).IsRequired();
2121
CommandOption xmlPolicyFile = this.Option("--xmlPolicyFile <xmlPolicyFile>", "XML policy file location", CommandOptionType.SingleValue);
2222
CommandOption xmlPolicyURL = this.Option("--xmlPolicyURL <xmlPolicyURL>", "XML policy remote url", CommandOptionType.SingleValue);
2323
CommandOption linked = this.Option("--linked <linked>", "Creates linked templates versus inlined into a single file", CommandOptionType.SingleValue);
@@ -34,9 +34,9 @@ public CreateCommand()
3434

3535
this.OnExecute(async () =>
3636
{
37+
// ensure required parameters have been passed in
3738
if ((openAPISpecFile.HasValue() || openAPISpecURL.HasValue()) && outputLocation.HasValue())
3839
{
39-
// required parameters have been passed in
4040
// convert command options to CLIArguments class
4141
CLICreatorArguments cliArguments = new CLICreatorArguments()
4242
{
@@ -58,19 +58,21 @@ public CreateCommand()
5858

5959
if (apiVersionSet.HasValue() && AttemptAPIVersionSetConversion(cliArguments) != null)
6060
{
61-
// unable to convert version set argument into object
61+
// unable to convert version set argument into object, would cause failure down the line
6262
ColoredConsole.Error.WriteLine("Incorrect API Version Set object structure");
6363
return 0;
6464
}
6565
else
6666
{
67+
// required parameters have been supplied and versionSet has correct object structure
68+
6769
// initialize helper classes
6870
OpenAPISpecReader openAPISpecReader = new OpenAPISpecReader();
6971
ARMTemplateWriter armTemplateWriter = new ARMTemplateWriter();
7072
APITemplateCreator apiTemplateCreator = new APITemplateCreator();
7173
TagTemplateCreator tagTemplateCreator = new TagTemplateCreator();
7274

73-
// create OpenApiDocument
75+
// create OpenApiDocument from Open API spec file
7476
OpenApiDocument doc = new OpenApiDocument();
7577
if (cliArguments.openAPISpecFile != null)
7678
{

src/APIM_ARMTemplate/apimtemplate/FileHandlers/ARMTemplateWriter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void WriteAPITemplateToFile(APITemplate template, string location)
2424

2525
public void WriteTagTemplatesToFile(List<TagTemplate> tagTemplates, string location)
2626
{
27+
// give each tag template a unique file name using count
2728
int templateNumber = 0;
2829
foreach(TagTemplate tagTemplate in tagTemplates)
2930
{
@@ -33,6 +34,7 @@ public void WriteTagTemplatesToFile(List<TagTemplate> tagTemplates, string locat
3334

3435
public void WriteTagDescriptionTemplatesToFile(List<TagDescriptionTemplate> tagDescriptionTemplates, string location)
3536
{
37+
// give each tag description template a unique file name using count
3638
int templateNumber = 0;
3739
foreach (TagDescriptionTemplate tagDescriptionTemplate in tagDescriptionTemplates)
3840
{

src/APIM_ARMTemplate/apimtemplate/TemplateCreators/APITemplateCreator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public APITemplateOAuth2 CreateOAuth2(OpenApiSecurityScheme scheme)
9393
authorizationServerId = "",
9494
scope = ""
9595
};
96+
// iterate through different flows, set serverId and scope once auth flow is found
9697
if (scheme.Flows.Implicit != null)
9798
{
9899
oAuth2.authorizationServerId = scheme.Flows.Implicit.AuthorizationUrl != null ? scheme.Flows.Implicit.AuthorizationUrl.ToString() : "";
@@ -118,6 +119,7 @@ public APITemplateOAuth2 CreateOAuth2(OpenApiSecurityScheme scheme)
118119

119120
public async Task<string> CreateOpenAPISpecContentsAsync(CLICreatorArguments cliArguments)
120121
{
122+
// return contents of supplied Open API Spec file
121123
if (cliArguments.openAPISpecFile != null)
122124
{
123125
return File.ReadAllText(cliArguments.openAPISpecFile);
@@ -144,6 +146,7 @@ public async Task<string> CreateOpenAPISpecContentsAsync(CLICreatorArguments cli
144146

145147
public APITemplateSubscriptionKeyParameterNames CreateSubscriptionKeyParameterNames(OpenApiDocument doc)
146148
{
149+
// subscription key parameter names are found in security requirements, organized by parameter location
147150
string header = "";
148151
string query = "";
149152
foreach (OpenApiSecurityRequirement requirement in doc.SecurityRequirements)
@@ -186,6 +189,7 @@ public bool IsSubscriptionRequired(OpenApiDocument doc)
186189

187190
public string[] CreateProtocols(OpenApiDocument doc)
188191
{
192+
// schemes from Open API spec are concatenated onto the host during OpenApiDocument conversion, each becoming a different Server object. Split the strings to pull the protocols
189193
List<string> protocols = new List<string>();
190194
foreach (OpenApiServer server in doc.Servers)
191195
{

src/APIM_ARMTemplate/apimtemplate/TemplateCreators/OperationTemplateCreator.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public List<OperationTemplate> CreateOperationTemplates(OpenApiDocument doc)
2929
templateParameters = CreateTemplateParameters(operation.Value.Parameters).ToArray(),
3030
responses = CreateOperationResponses(operation.Value.Responses).ToArray(),
3131
request = CreateOperationRequest(operation.Value),
32-
3332
//unfinished
3433
policies = null
3534
}
@@ -46,7 +45,9 @@ public OperationTemplateRequest CreateOperationRequest(OpenApiOperation operatio
4645
OperationTemplateRequest request = new OperationTemplateRequest()
4746
{
4847
description = operation.RequestBody != null ? operation.RequestBody.Description : null,
48+
// request parameters with parameter location query
4949
queryParameters = CreateTemplateParameters(operation.Parameters.Where(p => p.In == ParameterLocation.Query).ToList()).ToArray(),
50+
// request parameters with parameter location header
5051
headers = CreateTemplateParameters(operation.Parameters.Where(p => p.In == ParameterLocation.Header).ToList()).ToArray(),
5152
representations = operation.RequestBody != null ? CreateRepresentations(operation.RequestBody.Content).ToArray() : null
5253
};
@@ -74,6 +75,7 @@ public List<OperationTemplateRepresentation> CreateRepresentations(IDictionary<s
7475
List<OperationTemplateRepresentation> representations = new List<OperationTemplateRepresentation>();
7576
foreach (KeyValuePair<string, OpenApiMediaType> pair in content)
7677
{
78+
// use representation examples to create values and default value
7779
OpenApiParameterHeaderIntersection param = new OpenApiParameterHeaderIntersection()
7880
{
7981
Example = pair.Value.Example,
@@ -123,6 +125,7 @@ public List<OperationTemplateParameter> CreateResponseHeaders(IDictionary<string
123125
List<OperationTemplateParameter> headers = new List<OperationTemplateParameter>();
124126
foreach (KeyValuePair<string, OpenApiHeader> pair in headerPairs)
125127
{
128+
// use header examples to create values and default value
126129
OpenApiParameterHeaderIntersection param = new OpenApiParameterHeaderIntersection()
127130
{
128131
Example = pair.Value.Example,
@@ -147,6 +150,7 @@ public List<OperationTemplateParameter> CreateTemplateParameters(IList<OpenApiPa
147150
List<OperationTemplateParameter> templateParameters = new List<OperationTemplateParameter>();
148151
foreach (OpenApiParameter parameter in parameters)
149152
{
153+
// use parameter examples to create values and default value
150154
OpenApiParameterHeaderIntersection param = new OpenApiParameterHeaderIntersection()
151155
{
152156
Example = parameter.Example,
@@ -171,11 +175,13 @@ public List<string> CreateParameterValues(OpenApiParameterHeaderIntersection par
171175
List<string> values = new List<string>();
172176
if (parameter.Example != null)
173177
{
178+
// add example property to values
174179
values.Add(JsonConvert.SerializeObject(parameter.Example));
175180

176181
}
177182
foreach (KeyValuePair<string, OpenApiExample> example in parameter.Examples)
178183
{
184+
// add each example in examples list property to values
179185
values.Add(JsonConvert.SerializeObject(example.Value));
180186
}
181187
return values;
@@ -185,11 +191,13 @@ public string CreateParameterDefaultValue(OpenApiParameterHeaderIntersection par
185191
{
186192
if (parameter.Example != null)
187193
{
194+
// use example property for default value if given
188195
return JsonConvert.SerializeObject(parameter.Example);
189196

190197
}
191198
else if (parameter.Examples != null)
192199
{
200+
// use first example in examples list property for default value if example property is not given
193201
return JsonConvert.SerializeObject(parameter.Examples.SingleOrDefault().Value);
194202
}
195203
else
@@ -199,11 +207,13 @@ public string CreateParameterDefaultValue(OpenApiParameterHeaderIntersection par
199207
}
200208
}
201209

210+
// used to create parameter values
202211
public class OpenApiParameterHeaderIntersection {
203212
public IOpenApiAny Example { get; set; }
204213
public IDictionary<string, OpenApiExample> Examples { get; set; }
205214
}
206215

216+
// used to give compiler known object structure in order to create form parameters
207217
public class OperationSchemaExample
208218
{
209219
public object Value { get; set; }

src/APIM_ARMTemplate/apimtemplate/TemplateCreators/SchemaTemplateCreator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public List<SchemaTemplate> CreateSchemaTemplates(OpenApiDocument doc)
1111
List<SchemaTemplate> schemaTemplates = new List<SchemaTemplate>();
1212
foreach (KeyValuePair<string, OpenApiSchema> definition in doc.Components.Schemas)
1313
{
14+
// create a new schema template for each definition found in the spec
1415
SchemaTemplate schema = new SchemaTemplate()
1516
{
1617
name = definition.Key,

src/APIM_ARMTemplate/apimtemplate/TemplateCreators/TagTemplateCreator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public List<TagTemplate> CreateTagTemplates(OpenApiDocument doc)
1010
List<TagTemplate> tagTemplates = new List<TagTemplate>();
1111
foreach (OpenApiTag tag in doc.Tags)
1212
{
13+
// create a new tag template for each tag found in the spec
1314
TagTemplate tagSchema = new TagTemplate()
1415
{
1516
name = tag.Name,
@@ -26,6 +27,7 @@ public List<TagDescriptionTemplate> CreateTagDescriptionTemplates(OpenApiDocumen
2627
List<TagDescriptionTemplate> tagDescriptionTemplates = new List<TagDescriptionTemplate>();
2728
foreach (OpenApiTag tag in doc.Tags)
2829
{
30+
// create a new tag description template for each tag found in the spec
2931
TagDescriptionTemplate tagDescriptionSchema = new TagDescriptionTemplate()
3032
{
3133
name = tag.Name,

0 commit comments

Comments
 (0)