Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve AzureResourceSchema generator #1018

Merged
merged 27 commits into from May 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
94b15ef
Automatically detect MSBuild tools version in Windows platform
Apr 6, 2016
0522974
Add initial AzureResourceSchema project and test project
Apr 6, 2016
f7840bf
Update AzureResourceSchema projects and add initial c# files
Apr 6, 2016
7bfc5c2
Add AzureResourceSchema to configuration file
Apr 6, 2016
a8c0328
AzureResourceSchemaCodeGenerator shows up in AutoRest help and tests …
Apr 6, 2016
ffb8fa3
Almost have Storage schema generating from swagger spec
Apr 7, 2016
0eb8d0f
Merge latest from Azure/AutoRest
Apr 18, 2016
ce58306
Fix AzureResourceSchema project
Apr 18, 2016
a757cc4
Can generate storage schema from swagger
Apr 20, 2016
f325514
Merge branch 'master' of https://github.com/Azure/autorest
Apr 22, 2016
c38771d
Fix FXCopy issues
Apr 22, 2016
49cc5e0
Can now generate fleshed out storage schema
May 2, 2016
4c5f556
Add Batch acceptance test
May 4, 2016
df8fb81
Merge branch 'master' of https://github.com/Azure/autorest
May 4, 2016
5e54326
Storage and Batch passing
May 6, 2016
c4c32d2
Working on model
May 6, 2016
42cd603
Storage, Batch, and CDN schemas generating
May 9, 2016
3eef4f2
Fixed all analysis errors
May 10, 2016
31f3a92
Fixed parsing SequenceTypes and add Compute acceptance test
May 10, 2016
d406c85
Add Network test
May 10, 2016
01d7a12
Merge branch 'master' of https://github.com/Azure/autorest
May 11, 2016
e0fde05
Rename JSONSchema.cs to JsonSchema.cs
May 11, 2016
5604cf9
Added support for Microsoft.Web. Change resource schema resource name…
May 11, 2016
fb19554
Add support for child resources
May 11, 2016
b14c51d
Merge branch 'master' of https://github.com/Azure/autorest
May 11, 2016
075398c
Merge branch 'dev/daschult/AddChildResources'
May 11, 2016
30ed59c
Added expression support
May 11, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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
{
[Fact]
public static void Storage()
{
RunSwaggerTest("storage.json", "Storage");
}

[Fact]
public static void Batch()
{
RunSwaggerTest("BatchManagement.json", "Batch");
}

[Fact]
public static void Cdn()
{
RunSwaggerTest("cdn.json", "CDN");
}

[Fact]
public static void Compute()
{
RunSwaggerTest("compute.json", "Compute");
}

[Fact]
public static void Network()
{
RunSwaggerTest("network.json", "Network");
}

[Fact]
public static void Web()
{
RunSwaggerTest("web.json", "Web");
}

private static void RunSwaggerTest(string swaggerFileName, string expectedFolderName)
{
SwaggerSpecHelper.RunTests<AzureResourceSchemaCodeGenerator>(
Path.Combine("Swagger", swaggerFileName),
Path.Combine("Expected", expectedFolderName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AcceptanceTests.cs" />
<Compile Include="AzureResourceSchemaCodeGeneratorTests.cs" />
<Compile Include="JSONSchemaTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResourceSchemaParserTests.cs" />
<Compile Include="ResourceSchemaWriterTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\AutoRest.Core\AutoRest.Core.csproj">
Expand All @@ -75,11 +79,57 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Expected\Storage\Microsoft.Storage.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Expected\Batch\Microsoft.Batch.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Expected\CDN\Microsoft.Cdn.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Expected\Compute\Microsoft.Compute.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Expected\Network\Microsoft.Network.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Expected\Web\Microsoft.Web.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Expected\Web\Microsoft.DomainRegistration.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Expected\Web\Microsoft.CertificateRegistration.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="Swagger\storage.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Swagger\BatchManagement.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Swagger\cdn.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Swagger\compute.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Swagger\network.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Swagger\web.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 +138,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 @@ -35,7 +35,7 @@ public void Name()
public void UsageInstructionsWithNoOutputFileSetting()
{
AzureResourceSchemaCodeGenerator codeGen = CreateGenerator();
Assert.Equal("Your Azure Resource Schema can be found at " + codeGen.SchemaPath, codeGen.UsageInstructions);
Assert.Equal("Your Azure Resource Schema(s) can be found in " + codeGen.Settings.OutputDirectory, codeGen.UsageInstructions);
}

[Fact]
Expand All @@ -47,61 +47,7 @@ public void UsageInstructionsWithOutputFileSetting()
};
AzureResourceSchemaCodeGenerator codeGen = CreateGenerator(settings);

Assert.Equal("Your Azure Resource Schema can be found at " + codeGen.SchemaPath, codeGen.UsageInstructions);
}

[Fact]
public async void GenerateWithEmptyServiceClient()
{
await TestGenerate(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': { }
}");
}

[Fact]
public async void GenerateWithServiceClientWithOneType()
{
await TestGenerate(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': {
}
}
}");
}

[Fact]
public async void GenerateWithServiceClientWithTwoTypes()
{
await TestGenerate(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': {
},
'mockType2': {
}
}
}");
Assert.Equal("Your Azure Resource Schema(s) can be found in " + settings.OutputDirectory, codeGen.UsageInstructions);
}

[Fact]
Expand All @@ -122,19 +68,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,92 @@
{
"id": "http://schema.management.azure.com/schemas/2015-12-01/Microsoft.Batch.json#",
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Microsoft.Batch",
"description": "Microsoft Batch Resource Types",
"resourceDefinitions": {
"Microsoft.Batch_batchAccounts": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"Microsoft.Batch/batchAccounts"
]
},
"apiVersion": {
"type": "string",
"enum": [
"2015-12-01"
]
},
"location": {
"type": "string",
"description": "The region in which the account is created."
},
"tags": {
"oneOf": [
{
"type": "object",
"additionalProperties": {
"type": "string"
}
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
}
],
"description": "The user specified tags associated with the account."
},
"properties": {
"oneOf": [
{
"$ref": "#/definitions/AccountBaseProperties"
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
}
],
"description": "The properties of the account."
}
},
"required": [
"type",
"apiVersion",
"properties"
],
"description": "Microsoft.Batch/batchAccounts"
}
},
"definitions": {
"AccountBaseProperties": {
"type": "object",
"properties": {
"autoStorage": {
"oneOf": [
{
"$ref": "#/definitions/AutoStorageBaseProperties"
},
{
"$ref": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#/definitions/expression"
}
],
"description": "The properties related to auto storage account."
}
},
"description": "The properties of a Batch account."
},
"AutoStorageBaseProperties": {
"type": "object",
"properties": {
"storageAccountId": {
"type": "string",
"description": "The resource id of the storage account to be used for auto storage account."
}
},
"required": [
"storageAccountId"
],
"description": "The properties related to auto storage account."
}
}
}
Loading