Skip to content

Commit

Permalink
Can now generate fleshed out storage schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Schulte committed May 2, 2016
1 parent c38771d commit 49cc5e0
Show file tree
Hide file tree
Showing 14 changed files with 1,729 additions and 303 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Rest.Generator.AzureResourceSchema;
using Microsoft.Rest.Modeler.Swagger.Tests;
using System.IO;
using Xunit;

namespace AutoRest.Generator.AzureResourceSchema.Tests
{
[Collection("AutoRest Azure Resource Schema Tests")]
public static class AcceptanceTests
{
private static string SwaggerFile(string fileName)
{
return Path.Combine("Swagger", fileName);
}

private static string ExpectedFolder(string folderName)
{
return Path.Combine("Expected", folderName);
}

[Fact]
public static void Storage()
{
SwaggerSpecHelper.RunTests<AzureResourceSchemaCodeGenerator>(
SwaggerFile("storage.json"), ExpectedFolder("Storage"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AcceptanceTests.cs" />
<Compile Include="AzureResourceSchemaCodeGeneratorTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand All @@ -75,11 +76,21 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Expected\Storage\Microsoft.Storage.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="Swagger\storage.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Modelers\Swagger.Tests\AutoRest.Modeler.Swagger.Tests.csproj">
<Project>{c6c4e139-d7af-486c-95ba-2b879f58f18d}</Project>
<Name>AutoRest.Modeler.Swagger.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\AzureResourceSchema\AutoRest.Generator.AzureResourceSchema.csproj">
<Project>{654344a5-0556-49c7-bfb3-59676d7440d3}</Project>
<Name>AutoRest.Generator.AzureResourceSchema</Name>
Expand All @@ -88,6 +99,7 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,49 @@ public void UsageInstructionsWithOutputFileSetting()
[Fact]
public async void GenerateWithEmptyServiceClient()
{
await TestGenerate(new string[0],
await TestGenerate(null, new string[0],
@"{
'id': 'http://schema.management.azure.com/schemas//Microsoft.Storage.json#',
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'Microsoft.Storage',
'description': 'Microsoft Storage Resource Types',
'resourceDefinitions': { }
""id"": null,
""$schema"": ""http://json-schema.org/draft-04/schema#"",
""title"": null,
""description"": null,
""resourceDefinitions"": { }
}");
}

[Fact]
public async void GenerateWithServiceClientWithOneType()
{
await TestGenerate(new string[]
await TestGenerate(null, new string[]
{
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Mock.Provider/mockType"
},
@"{
'id': 'http://schema.management.azure.com/schemas//Microsoft.Storage.json#',
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'Microsoft.Storage',
'description': 'Microsoft Storage Resource Types',
'resourceDefinitions': {
'mockType': {
""id"": null,
""$schema"": ""http://json-schema.org/draft-04/schema#"",
""title"": ""Mock.Provider"",
""description"": ""Mock Provider Resource Types"",
""resourceDefinitions"": {
""mockType"": {
""type"": ""object"",
""properties"": {
""type"": {
""enum"": [
""Mock.Provider/mockType""
]
},
""apiVersion"": {
""enum"": [
null
]
}
},
""required"": [
""type"",
""apiVersion"",
""properties""
],
""description"": ""Mock.Provider/mockType""
}
}
}");
Expand All @@ -85,20 +104,58 @@ await TestGenerate(new string[]
[Fact]
public async void GenerateWithServiceClientWithTwoTypes()
{
await TestGenerate(new string[]
await TestGenerate("2016-05-01", new string[]
{
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Mock.Provider/mockType1",
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Mock.Provider/mockType2"
},
@"{
'id': 'http://schema.management.azure.com/schemas//Microsoft.Storage.json#',
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'Microsoft.Storage',
'description': 'Microsoft Storage Resource Types',
'resourceDefinitions': {
'mockType1': {
""id"": ""http://schema.management.azure.com/schemas/2016-05-01/Mock.Provider.json#"",
""$schema"": ""http://json-schema.org/draft-04/schema#"",
""title"": ""Mock.Provider"",
""description"": ""Mock Provider Resource Types"",
""resourceDefinitions"": {
""mockType1"": {
""type"": ""object"",
""properties"": {
""type"": {
""enum"": [
""Mock.Provider/mockType1""
]
},
""apiVersion"": {
""enum"": [
""2016-05-01""
]
}
},
""required"": [
""type"",
""apiVersion"",
""properties""
],
""description"": ""Mock.Provider/mockType1""
},
'mockType2': {
""mockType2"": {
""type"": ""object"",
""properties"": {
""type"": {
""enum"": [
""Mock.Provider/mockType2""
]
},
""apiVersion"": {
""enum"": [
""2016-05-01""
]
}
},
""required"": [
""type"",
""apiVersion"",
""properties""
],
""description"": ""Mock.Provider/mockType2""
}
}
}");
Expand All @@ -122,19 +179,21 @@ private static AzureResourceSchemaCodeGenerator CreateGenerator(Settings setting
return new AzureResourceSchemaCodeGenerator(settings);
}

private static async Task TestGenerate(string[] methodUrls, string expectedJsonString)
private static async Task TestGenerate(string apiVersion, string[] methodUrls, string expectedJsonString)
{
MemoryFileSystem fileSystem = new MemoryFileSystem();

Settings settings = new Settings();
settings.FileSystem = fileSystem;

ServiceClient serviceClient = new ServiceClient();
serviceClient.ApiVersion = apiVersion;
foreach(string methodUrl in methodUrls)
{
serviceClient.Methods.Add(new Method()
{
Url = methodUrl
Url = methodUrl,
HttpMethod = HttpMethod.Put,
});
}
await CreateGenerator(settings).Generate(serviceClient);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"id": "http://schema.management.azure.com/schemas/2016-01-01/Microsoft.Storage.json#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Microsoft.Storage",
"description": "Microsoft Storage Resource Types",
"resourceDefinitions": {
"storageAccounts": {
"type": "object",
"properties": {
"type": {
"enum": [
"Microsoft.Storage/storageAccounts"
]
},
"apiVersion": {
"enum": [
"2016-01-01"
]
},
"sku": {
"$ref": "#/definitions/Sku",
"description": "Required. Gets or sets the sku type."
},
"kind": {
"type": "string",
"enum": [
"Storage",
"BlobStorage"
],
"description": "Required. Indicates the type of storage account. Possible values include: 'Storage', 'BlobStorage'"
},
"location": {
"type": "string",
"description": "Required. Gets or sets the location of the resource. This will be one of the supported and registered Azure Geo Regions (e.g. West US, East US, Southeast Asia, etc.). The geo region of a resource cannot be changed once it is created, but if an identical geo region is specified on update the request will succeed."
},
"tags": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "Gets or sets a list of key value pairs that describe the resource. These tags can be used in viewing and grouping this resource (across resource groups). A maximum of 15 tags can be provided for a resource. Each tag must have a key no greater than 128 characters and value no greater than 256 characters."
},
"properties": {
"$ref": "#/definitions/StorageAccountPropertiesCreateParameters"
}
},
"required": [
"type",
"apiVersion",
"properties",
"sku",
"kind",
"location"
],
"description": "Microsoft.Storage/storageAccounts"
}
},
"definitions": {
"CustomDomain": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Gets or sets the custom domain name. Name is the CNAME source."
},
"useSubDomain": {
"type": "boolean",
"description": "Indicates whether indirect CName validation is enabled. Default value is false. This should only be set on updates"
}
},
"required": [
"name"
],
"description": "The custom domain assigned to this storage account. This can be set via Update."
},
"Encryption": {
"type": "object",
"properties": {
"services": {
"$ref": "#/definitions/EncryptionServices",
"description": "Gets the services which are encrypted."
},
"keySource": {
"type": "string",
"enum": [
"Microsoft.Storage"
],
"description": "Gets the encryption keySource(provider). Possible values (case-insensitive): Microsoft.Storage"
}
},
"required": [
"keySource"
],
"description": "The encryption settings on the account."
},
"EncryptionService": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean",
"description": "A boolean indicating whether or not the service is encrypted."
}
},
"description": "An encrypted service."
},
"EncryptionServices": {
"type": "object",
"properties": {
"blob": {
"$ref": "#/definitions/EncryptionService",
"description": "The blob service."
}
},
"description": "The encrypted services."
},
"Sku": {
"type": "object",
"properties": {
"name": {
"type": "string",
"enum": [
"Standard_LRS",
"Standard_GRS",
"Standard_RAGRS",
"Standard_ZRS",
"Premium_LRS"
],
"description": "Gets or sets the sku name. Required for account creation, optional for update. Note that in older versions, sku name was called accountType. Possible values include: 'Standard_LRS', 'Standard_GRS', 'Standard_RAGRS', 'Standard_ZRS', 'Premium_LRS'"
}
},
"required": [
"name"
],
"description": "The SKU of the storage account."
},
"StorageAccountPropertiesCreateParameters": {
"type": "object",
"properties": {
"customDomain": {
"$ref": "#/definitions/CustomDomain",
"description": "User domain assigned to the storage account. Name is the CNAME source. Only one custom domain is supported per storage account at this time. To clear the existing custom domain, use an empty string for the custom domain name property."
},
"encryption": {
"$ref": "#/definitions/Encryption",
"description": "Provides the encryption settings on the account. If left unspecified the account encryption settings will remain. The default setting is unencrypted."
},
"accessTier": {
"type": "string",
"enum": [
"Hot",
"Cool"
],
"description": "Required for StandardBlob accounts. The access tier used for billing. Access tier cannot be changed more than once every 7 days (168 hours). Access tier cannot be set for StandardLRS, StandardGRS, StandardRAGRS, or PremiumLRS account types. Possible values include: 'Hot', 'Cool'"
}
}
}
}
}
Loading

0 comments on commit 49cc5e0

Please sign in to comment.