private async Task <List <TemplateResource> > GenerateSchemasARMTemplate(string apimServiceName, string apiName, string resourceGroup, string fileFolder) { List <TemplateResource> templateResources = new List <TemplateResource>(); // pull all schemas from service string schemas = await GetAPISchemasAsync(apimServiceName, resourceGroup, apiName); JObject oSchemas = JObject.Parse(schemas); foreach (var item in oSchemas["value"]) { string schemaName = ((JValue)item["name"]).Value.ToString(); Console.WriteLine("'{0}' Operation schema found", schemaName); string schemaDetails = await GetAPISchemaDetailsAsync(apimServiceName, resourceGroup, apiName, schemaName); // pull returned schema and convert to template resource RESTReturnedSchemaTemplate restReturnedSchemaTemplate = JsonConvert.DeserializeObject <RESTReturnedSchemaTemplate>(schemaDetails); SchemaTemplateResource schemaDetailsResource = JsonConvert.DeserializeObject <SchemaTemplateResource>(schemaDetails); schemaDetailsResource.properties.document.value = GetSchemaValueBasedOnContentType(restReturnedSchemaTemplate.properties); schemaDetailsResource.name = $"[concat(parameters('ApimServiceName'), '/{apiName}/{schemaName}')]"; schemaDetailsResource.apiVersion = GlobalConstants.APIVersion; schemaDetailsResource.dependsOn = new string[] { $"[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), '{apiName}')]" }; templateResources.Add(schemaDetailsResource); } return(templateResources); }
private List <TemplateResource> GenerateSchemasARMTemplate(string apimServiceName, string apiName, string resourceGroup, string fileFolder) { Console.WriteLine("------------------------------------------"); Console.WriteLine("Getting operation schemas from service"); APIExtractor apiExtractor = new APIExtractor(); List <TemplateResource> templateResources = new List <TemplateResource>(); string schemas = apiExtractor.GetApiSchemas(apimServiceName, resourceGroup, apiName).Result; JObject oSchemas = JObject.Parse(schemas); foreach (var item in oSchemas["value"]) { string schemaName = ((JValue)item["name"]).Value.ToString(); Console.WriteLine("'{0}' Schema found", schemaName); string schemaDetails = apiExtractor.GetApiSchemaDetails(apimServiceName, resourceGroup, apiName, schemaName).Result; // pull returned document and convert to correct format RESTReturnedSchemaTemplate restReturnedSchemaTemplate = JsonConvert.DeserializeObject <RESTReturnedSchemaTemplate>(schemaDetails); SchemaTemplateResource schemaDetailsResource = JsonConvert.DeserializeObject <SchemaTemplateResource>(schemaDetails); schemaDetailsResource.properties.document.value = JsonConvert.SerializeObject(restReturnedSchemaTemplate.properties.document); schemaDetailsResource.name = $"[concat(parameters('ApimServiceName'), '/{apiName}/{schemaName}')]"; schemaDetailsResource.apiVersion = "2018-06-01-preview"; schemaDetailsResource.dependsOn = new string[] { $"[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), '{apiName}')]" }; templateResources.Add(schemaDetailsResource); } return(templateResources); }