From 083672e008997a12565deffde9562d0f412ea29e Mon Sep 17 00:00:00 2001 From: Dan Schulte Date: Wed, 25 May 2016 10:35:28 -0700 Subject: [PATCH] Update AzureResourceSchema generator to create DNS schema --- .../Expected/Batch/Microsoft.Batch.json | 148 ++ .../Expected/CDN/Microsoft.Cdn.json | 8 +- .../Expected/DNS/Microsoft.Network.json | 1294 ++++++++++++++++- .../Expected/Storage/Microsoft.Storage.json | 4 +- .../ResourceSchemaParser.cs | 102 +- 5 files changed, 1486 insertions(+), 70 deletions(-) diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/Batch/Microsoft.Batch.json b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/Batch/Microsoft.Batch.json index 0353b66107559..c591108e25561 100644 --- a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/Batch/Microsoft.Batch.json +++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/Batch/Microsoft.Batch.json @@ -49,12 +49,91 @@ "description": "The properties of the account." } }, + "resources": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/batchAccounts_applications_childResource" + } + ] + } + }, "required": [ "type", "apiVersion", "properties" ], "description": "Microsoft.Batch/batchAccounts" + }, + "batchAccounts_applications": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Batch/batchAccounts/applications" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2015-12-01" + ] + }, + "allowUpdates": { + "oneOf": [ + { + "type": "boolean" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "A value indicating whether packages within the application may be overwritten using the same version string." + }, + "displayName": { + "type": "string", + "description": "The display name for the application." + } + }, + "resources": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/batchAccounts_applications_versions_childResource" + } + ] + } + }, + "required": [ + "type", + "apiVersion" + ], + "description": "Microsoft.Batch/batchAccounts/applications" + }, + "batchAccounts_applications_versions": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Batch/batchAccounts/applications/versions" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2015-12-01" + ] + } + }, + "required": [ + "type", + "apiVersion" + ], + "description": "Microsoft.Batch/batchAccounts/applications/versions" } }, "definitions": { @@ -87,6 +166,75 @@ "storageAccountId" ], "description": "The properties related to auto storage account." + }, + "batchAccounts_applications_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "applications" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2015-12-01" + ] + }, + "allowUpdates": { + "oneOf": [ + { + "type": "boolean" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "A value indicating whether packages within the application may be overwritten using the same version string." + }, + "displayName": { + "type": "string", + "description": "The display name for the application." + } + }, + "resources": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/batchAccounts_applications_versions_childResource" + } + ] + } + }, + "required": [ + "type", + "apiVersion" + ], + "description": "Microsoft.Batch/batchAccounts/applications" + }, + "batchAccounts_applications_versions_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "versions" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2015-12-01" + ] + } + }, + "required": [ + "type", + "apiVersion" + ], + "description": "Microsoft.Batch/batchAccounts/applications/versions" } } } diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/CDN/Microsoft.Cdn.json b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/CDN/Microsoft.Cdn.json index 9f56f516c85c2..4cd51d56fba62 100644 --- a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/CDN/Microsoft.Cdn.json +++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/CDN/Microsoft.Cdn.json @@ -127,8 +127,8 @@ "required": [ "type", "apiVersion", - "properties", - "location" + "location", + "properties" ], "description": "Microsoft.Cdn/profiles/endpoints" }, @@ -458,8 +458,8 @@ "required": [ "type", "apiVersion", - "properties", - "location" + "location", + "properties" ], "description": "Microsoft.Cdn/profiles/endpoints" }, diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/DNS/Microsoft.Network.json b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/DNS/Microsoft.Network.json index f500133101cae..7789f4283e209 100644 --- a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/DNS/Microsoft.Network.json +++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/DNS/Microsoft.Network.json @@ -35,15 +35,1303 @@ "description": "Gets or sets the properties of the zone." } }, + "resources": { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/dnszones_TXT_childResource" + }, + { + "$ref": "#/definitions/dnszones_SRV_childResource" + }, + { + "$ref": "#/definitions/dnszones_SOA_childResource" + }, + { + "$ref": "#/definitions/dnszones_PTR_childResource" + }, + { + "$ref": "#/definitions/dnszones_NS_childResource" + }, + { + "$ref": "#/definitions/dnszones_MX_childResource" + }, + { + "$ref": "#/definitions/dnszones_CNAME_childResource" + }, + { + "$ref": "#/definitions/dnszones_AAAA_childResource" + }, + { + "$ref": "#/definitions/dnszones_A_childResource" + } + ] + } + }, "required": [ "type", "apiVersion", "properties" ], "description": "Microsoft.Network/dnszones" - } - }, - "definitions": { + }, + "dnszones_A": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Network/dnszones/A" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/A" + }, + "dnszones_AAAA": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Network/dnszones/AAAA" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/AAAA" + }, + "dnszones_CNAME": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Network/dnszones/CNAME" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/CNAME" + }, + "dnszones_MX": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Network/dnszones/MX" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/MX" + }, + "dnszones_NS": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Network/dnszones/NS" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/NS" + }, + "dnszones_PTR": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Network/dnszones/PTR" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/PTR" + }, + "dnszones_SOA": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Network/dnszones/SOA" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/SOA" + }, + "dnszones_SRV": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Network/dnszones/SRV" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/SRV" + }, + "dnszones_TXT": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "Microsoft.Network/dnszones/TXT" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/TXT" + } + }, + "definitions": { + "AaaaRecord": { + "type": "object", + "properties": { + "ipv6Address": { + "type": "string", + "description": "Gets or sets the IPv6 address of this AAAA record in string notation." + } + }, + "description": "An AAAA record." + }, + "ARecord": { + "type": "object", + "properties": { + "ipv4Address": { + "type": "string", + "description": "Gets or sets the IPv4 address of this A record in string notation." + } + }, + "description": "An A record." + }, + "CnameRecord": { + "type": "object", + "properties": { + "cname": { + "type": "string", + "description": "Gets or sets the canonical name for this record without a terminating dot." + } + }, + "description": "A CNAME record." + }, + "dnszones_A_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "A" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/A" + }, + "dnszones_AAAA_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "AAAA" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/AAAA" + }, + "dnszones_CNAME_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "CNAME" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/CNAME" + }, + "dnszones_MX_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "MX" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/MX" + }, + "dnszones_NS_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "NS" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/NS" + }, + "dnszones_PTR_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "PTR" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/PTR" + }, + "dnszones_SOA_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "SOA" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/SOA" + }, + "dnszones_SRV_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "SRV" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/SRV" + }, + "dnszones_TXT_childResource": { + "type": "object", + "properties": { + "type": { + "type": "string", + "enum": [ + "TXT" + ] + }, + "apiVersion": { + "type": "string", + "enum": [ + "2016-04-01" + ] + }, + "id": { + "type": "string", + "description": "Gets or sets the ID of the resource." + }, + "name": { + "type": "string", + "description": "Gets or sets the name of the resource." + }, + "etag": { + "type": "string", + "description": "Gets or sets the ETag of the RecordSet." + }, + "location": { + "type": "string", + "description": "Gets or sets the location of the resource." + }, + "properties": { + "oneOf": [ + { + "$ref": "#/definitions/RecordSetProperties" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the properties of the RecordSet." + } + }, + "required": [ + "type", + "apiVersion", + "properties" + ], + "description": "Microsoft.Network/dnszones/TXT" + }, + "MxRecord": { + "type": "object", + "properties": { + "preference": { + "oneOf": [ + { + "type": "integer" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the preference metric for this record." + }, + "exchange": { + "type": "string", + "description": "Gets or sets the domain name of the mail host, without a terminating dot." + } + }, + "description": "An MX record." + }, + "NsRecord": { + "type": "object", + "properties": { + "nsdname": { + "type": "string", + "description": "Gets or sets the name server name for this record, without a terminating dot." + } + }, + "description": "An NS record." + }, + "PtrRecord": { + "type": "object", + "properties": { + "ptrdname": { + "type": "string", + "description": "Gets or sets the PTR target domain name for this record without a terminating dot." + } + }, + "description": "A PTR record." + }, + "RecordSetProperties": { + "type": "object", + "properties": { + "metadata": { + "oneOf": [ + { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the metadata attached to the resource." + }, + "TTL": { + "oneOf": [ + { + "type": "integer" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the TTL of the records in the RecordSet." + }, + "ARecords": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/ARecord" + } + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the list of A records in the RecordSet." + }, + "AAAARecords": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/AaaaRecord" + } + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the list of AAAA records in the RecordSet." + }, + "MXRecords": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/MxRecord" + } + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the list of MX records in the RecordSet." + }, + "NSRecords": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/NsRecord" + } + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the list of NS records in the RecordSet." + }, + "PTRRecords": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/PtrRecord" + } + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the list of PTR records in the RecordSet." + }, + "SRVRecords": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/SrvRecord" + } + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the list of SRV records in the RecordSet." + }, + "TXTRecords": { + "oneOf": [ + { + "type": "array", + "items": { + "$ref": "#/definitions/TxtRecord" + } + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the list of TXT records in the RecordSet." + }, + "CNAMERecord": { + "oneOf": [ + { + "$ref": "#/definitions/CnameRecord" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the CNAME record in the RecordSet." + }, + "SOARecord": { + "oneOf": [ + { + "$ref": "#/definitions/SoaRecord" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the SOA record in the RecordSet." + } + }, + "description": "Represents the properties of the records in the RecordSet." + }, + "SoaRecord": { + "type": "object", + "properties": { + "host": { + "type": "string", + "description": "Gets or sets the domain name of the authoritative name server, without a temrinating dot." + }, + "email": { + "type": "string", + "description": "Gets or sets the email for this record." + }, + "serialNumber": { + "oneOf": [ + { + "type": "integer" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the serial number for this record." + }, + "refreshTime": { + "oneOf": [ + { + "type": "integer" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the refresh value for this record." + }, + "retryTime": { + "oneOf": [ + { + "type": "integer" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the retry time for this record." + }, + "expireTime": { + "oneOf": [ + { + "type": "integer" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the expire time for this record." + }, + "minimumTTL": { + "oneOf": [ + { + "type": "integer" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the minimum TTL value for this record." + } + }, + "description": "An SOA record." + }, + "SrvRecord": { + "type": "object", + "properties": { + "priority": { + "oneOf": [ + { + "type": "integer" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the priority metric for this record." + }, + "weight": { + "oneOf": [ + { + "type": "integer" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the weight metric for this this record." + }, + "port": { + "oneOf": [ + { + "type": "integer" + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the port of the service for this record." + }, + "target": { + "type": "string", + "description": "Gets or sets the domain name of the target for this record, without a terminating dot." + } + }, + "description": "An SRV record." + }, + "TxtRecord": { + "type": "object", + "properties": { + "value": { + "oneOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression" + } + ], + "description": "Gets or sets the text value of this record." + } + }, + "description": "A TXT record." + }, "ZoneProperties": { "type": "object", "properties": { diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/Storage/Microsoft.Storage.json b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/Storage/Microsoft.Storage.json index 79847f9feb66e..031edc743f3a5 100644 --- a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/Storage/Microsoft.Storage.json +++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema.Tests/Expected/Storage/Microsoft.Storage.json @@ -77,10 +77,10 @@ "required": [ "type", "apiVersion", - "properties", "sku", "kind", - "location" + "location", + "properties" ], "description": "Microsoft.Storage/storageAccounts" } diff --git a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/ResourceSchemaParser.cs b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/ResourceSchemaParser.cs index 8e0ee9a13461f..b6a68bb6093af 100644 --- a/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/ResourceSchemaParser.cs +++ b/AutoRest/Generators/AzureResourceSchema/AzureResourceSchema/ResourceSchemaParser.cs @@ -23,15 +23,15 @@ public static class ResourceSchemaParser /// /// /// - public static IDictionary Parse(ServiceClient serviceClient) + public static IDictionary Parse(ServiceClient serviceClient) { if (serviceClient == null) { throw new ArgumentNullException("serviceClient"); } - IDictionary result = new Dictionary(); - + IDictionary result = new Dictionary(); + List createResourceMethods = new List(); foreach (Method method in serviceClient.Methods) { @@ -42,12 +42,9 @@ public static IDictionary Parse(ServiceClient serviceClie } string apiVersion = serviceClient.ApiVersion; - + foreach (Method createResourceMethod in createResourceMethods) { - JsonSchema resourceDefinition = new JsonSchema(); - resourceDefinition.JsonType = "object"; - string afterPrefix = createResourceMethod.Url.Substring(resourceMethodPrefix.Length); int forwardSlashIndexAfterProvider = afterPrefix.IndexOf('/'); string resourceProvider = afterPrefix.Substring(0, forwardSlashIndexAfterProvider); @@ -74,57 +71,46 @@ public static IDictionary Parse(ServiceClient serviceClie } string methodUrlPathAfterProvider = afterPrefix.Substring(forwardSlashIndexAfterProvider + 1); - string resourceType = GetResourceTypes(resourceProvider, methodUrlPathAfterProvider, createResourceMethod.Parameters)[0]; + string[] resourceTypes = GetResourceTypes(resourceProvider, methodUrlPathAfterProvider, createResourceMethod.Parameters); + foreach (string resourceType in resourceTypes) + { + JsonSchema resourceDefinition = new JsonSchema(); + resourceDefinition.JsonType = "object"; - resourceDefinition.AddProperty("type", new JsonSchema() + resourceDefinition.AddProperty("type", new JsonSchema() { JsonType = "string" }.AddEnum(resourceType), true); + + if (!string.IsNullOrWhiteSpace(apiVersion)) { - JsonType = "string" + resourceDefinition.AddProperty("apiVersion", new JsonSchema() { JsonType = "string" }.AddEnum(apiVersion), true); } - .AddEnum(resourceType)); - - if (!string.IsNullOrWhiteSpace(apiVersion)) - { - resourceDefinition.AddProperty("apiVersion", new JsonSchema() - { - JsonType = "string" - } - .AddEnum(apiVersion)); - } - CompositeType body = createResourceMethod.Body.Type as CompositeType; - Debug.Assert(body != null, "The create resource method's body must be a CompositeType and cannot be null."); - if (body != null) - { - foreach (Property property in body.Properties) + if (createResourceMethod.Body != null) { - JsonSchema propertyDefinition = ParseProperty(property, resourceSchema.Definitions); - if (propertyDefinition != null) + CompositeType body = createResourceMethod.Body.Type as CompositeType; + Debug.Assert(body != null, "The create resource method's body must be a CompositeType and cannot be null."); + if (body != null) { - resourceDefinition.AddProperty(property.Name, propertyDefinition, property.IsRequired); + foreach (Property property in body.Properties) + { + if (!resourceDefinition.Properties.Keys.Contains(property.Name)) + { + JsonSchema propertyDefinition = ParseProperty(property, resourceSchema.Definitions); + if (propertyDefinition != null) + { + resourceDefinition.AddProperty(property.Name, propertyDefinition, property.IsRequired || property.Name == "properties"); + } + } + } } } - } - resourceDefinition.Description = resourceType; + resourceDefinition.Description = resourceType; - foreach (string standardPropertyName in new string[] { "properties", "apiVersion", "type" }) - { - if (resourceDefinition.Properties.ContainsKey(standardPropertyName)) - { - if (resourceDefinition.Required == null) - { - resourceDefinition.AddRequired(standardPropertyName); - } - else - { - resourceDefinition.Required.Insert(0, standardPropertyName); - } - } - } + string resourcePropertyName = resourceType.Substring(resourceProvider.Length + 1).Replace('/', '_'); - string resourcePropertyName = resourceType.Substring(resourceProvider.Length + 1).Replace('/', '_'); - Debug.Assert(!resourceSchema.ResourceDefinitions.ContainsKey(resourcePropertyName)); - resourceSchema.AddResourceDefinition(resourcePropertyName, resourceDefinition); + Debug.Assert(!resourceSchema.ResourceDefinitions.ContainsKey(resourcePropertyName)); + resourceSchema.AddResourceDefinition(resourcePropertyName, resourceDefinition); + } } // This loop adds child resource schemas to their parent resource schemas. We can't do @@ -264,7 +250,7 @@ private static JsonSchema ParseProperty(Property property, IDictionary bodyComposedExtensions = body.ComposedExtensions; - const string azureResource = "x-ms-azure-resource"; - result = bodyComposedExtensions.ContainsKey(azureResource) ? (bool)bodyComposedExtensions[azureResource] : false; - } + result = method.ReturnType.Body is CompositeType; } return result; @@ -399,7 +379,7 @@ public static bool IsCreateResourceMethod(Method method) /// /// /// - public static string[] GetResourceTypes(string resourceProvider, string methodPathAfterProvider, List createResourceMethodParameters) + public static string[] GetResourceTypes(string resourceProvider, string methodPathAfterProvider, IReadOnlyCollection createResourceMethodParameters) { if (string.IsNullOrWhiteSpace(resourceProvider)) { @@ -417,32 +397,32 @@ public static string[] GetResourceTypes(string resourceProvider, string methodPa for (int i = 0; i < pathSegments.Length; i += 2) { string pathSegment = pathSegments[i]; - if (pathSegment.StartsWith("{") && pathSegment.EndsWith("}")) + if (pathSegment.StartsWith("{", StringComparison.Ordinal) && pathSegment.EndsWith("}", StringComparison.Ordinal)) { string parameterName = pathSegment.Substring(1, pathSegment.Length - 2); Parameter parameter = createResourceMethodParameters.FirstOrDefault(methodParameter => methodParameter.Name == parameterName); if (parameter == null) { - string errorMessage = string.Format("Found undefined parameter reference {0} in create resource method \"{1}/{2}/{3}\".", pathSegment, resourceMethodPrefix, resourceProvider, methodPathAfterProvider); + string errorMessage = string.Format(CultureInfo.CurrentCulture, "Found undefined parameter reference {0} in create resource method \"{1}/{2}/{3}\".", pathSegment, resourceMethodPrefix, resourceProvider, methodPathAfterProvider); throw new ArgumentException(errorMessage, "createResourceMethodParameters"); } if (parameter.Type == null) { - string errorMessage = string.Format("Parameter reference {0} has no defined type.", pathSegment); + string errorMessage = string.Format(CultureInfo.CurrentCulture, "Parameter reference {0} has no defined type.", pathSegment); throw new ArgumentException(errorMessage, "createResourceMethodParameters"); } EnumType parameterType = parameter.Type as EnumType; if (parameterType == null) { - string errorMessage = string.Format("Parameter reference {0} is defined as a type other than an EnumType: {1}", pathSegment, parameter.Type.GetType().Name); + string errorMessage = string.Format(CultureInfo.CurrentCulture, "Parameter reference {0} is defined as a type other than an EnumType: {1}", pathSegment, parameter.Type.GetType().Name); throw new ArgumentException(errorMessage, "createResourceMethodParameters"); } if (parameterType.Values == null || parameterType.Values.Count == 0) { - string errorMessage = string.Format("Parameter reference {0} is defined as an EnumType, but it doesn't have any specified values.", pathSegment); + string errorMessage = string.Format(CultureInfo.CurrentCulture, "Parameter reference {0} is defined as an EnumType, but it doesn't have any specified values.", pathSegment); throw new ArgumentException(errorMessage, "createResourceMethodParameters"); }