Skip to content

Commit

Permalink
Fix AzureResourceSchema projects (Azure#956)
Browse files Browse the repository at this point in the history
* Automatically detect MSBuild tools version in Windows platform

* Add initial AzureResourceSchema project and test project

* Update AzureResourceSchema projects and add initial c# files

* Add AzureResourceSchema to configuration file

* AzureResourceSchemaCodeGenerator shows up in AutoRest help and tests pass

* Almost have Storage schema generating from swagger spec

* Fix AzureResourceSchema project

* Can generate storage schema from swagger

* Fix FXCopy issues
  • Loading branch information
Dan Schulte authored and amarzavery committed Apr 30, 2016
1 parent 1f4cc35 commit 47753e5
Show file tree
Hide file tree
Showing 15 changed files with 771 additions and 15 deletions.
10 changes: 9 additions & 1 deletion AutoRest.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRest.Core", "AutoRest\AutoRest.Core\AutoRest.Core.csproj", "{C876085F-9DC3-41F0-B7B4-17022CD84684}"
EndProject
Expand Down Expand Up @@ -372,6 +372,14 @@ Global
{DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.ActiveCfg = Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.Build.0 = Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
1 change: 1 addition & 0 deletions AutoRest/AutoRest.Core/AutoRest.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<file src="binaries/net45/AutoRest.Generator.Azure.Ruby.dll" target="tools" />
<file src="binaries/net45/AutoRest.Generator.Python.dll" target="tools" />
<file src="binaries/net45/AutoRest.Generator.Azure.Python.dll" target="tools" />
<file src="binaries/net45/AutoRest.Generator.AzureResourceSchema.dll" target="tools" />
<file src="binaries/net45/AutoRest.Modeler.Swagger.dll" target="tools" />
<file src="binaries/net45/AutoRest.Modeler.CompositeSwagger.dll" target="tools" />
<file src="binaries/net45/Newtonsoft.Json.dll" target="tools" />
Expand Down
3 changes: 3 additions & 0 deletions AutoRest/AutoRest/AutoRest.Release.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
},
"Azure.Python": {
"type": "AzurePythonCodeGenerator, AutoRest.Generator.Azure.Python"
},
"AzureResourceSchema": {
"type": "AzureResourceSchemaCodeGenerator, AutoRest.Generator.AzureResourceSchema"
}
},
"modelers": {
Expand Down
3 changes: 3 additions & 0 deletions AutoRest/AutoRest/AutoRest.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
},
"Azure.Python": {
"type": "AzurePythonCodeGenerator, AutoRest.Generator.Azure.Python"
},
"AzureResourceSchema": {
"type": "AzureResourceSchemaCodeGenerator, AutoRest.Generator.AzureResourceSchema"
}
},
"modelers": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\..\..\..\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props" Condition="Exists('..\..\..\..\packages\xunit.core.2.1.0\build\portable-net45+win8+wp8+wpa81\xunit.core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1C3B4A33-E045-4C8F-9202-1B651A686567}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Rest.Generator.AzureResourceSchema.Tests</RootNamespace>
<RootNamespace>AutoRest.Generator.AzureResourceSchema.Tests</RootNamespace>
<AssemblyName>AutoRest.Generator.AzureResourceSchema.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
Expand All @@ -33,6 +35,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -42,25 +48,32 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<HintPath>..\..\..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
<HintPath>..\..\..\..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
<HintPath>..\..\..\..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
<HintPath>..\..\..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AzureResourceSchemaCodeGeneratorTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\AutoRest.Core\AutoRest.Core.csproj">
<Project>{c876085f-9dc3-41f0-b7b4-17022cd84684}</Project>
<Name>AutoRest.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -72,12 +85,16 @@
<Name>AutoRest.Generator.AzureResourceSchema</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\..\..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
<Error Condition="!Exists('..\..\..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// 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.ClientModel;
using Microsoft.Rest.Generator.Utilities;
using Newtonsoft.Json.Linq;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Microsoft.Rest.Generator.AzureResourceSchema.Tests
{
[Collection("AutoRest Tests")]
public class AzureResourceSchemaCodeGeneratorTests
{
[Fact]
public void Description()
{
Assert.Equal("Azure Resource Schema generator", CreateGenerator().Description);
}

[Fact]
public void ImplementationFileExtension()
{
Assert.Equal(".json", CreateGenerator().ImplementationFileExtension);
}

[Fact]
public void Name()
{
Assert.Equal("AzureResourceSchema", CreateGenerator().Name);
}

[Fact]
public void UsageInstructionsWithNoOutputFileSetting()
{
AzureResourceSchemaCodeGenerator codeGen = CreateGenerator();
Assert.Equal("Your Azure Resource Schema can be found at " + codeGen.SchemaPath, codeGen.UsageInstructions);
}

[Fact]
public void UsageInstructionsWithOutputFileSetting()
{
Settings settings = new Settings()
{
OutputFileName = "spam.json"
};
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': {
}
}
}");
}

[Fact]
public void NormalizeClientModelDoesNothing()
{
ServiceClient serviceClient = new ServiceClient();
CreateGenerator().NormalizeClientModel(serviceClient);

// Nothing happens
}

private static AzureResourceSchemaCodeGenerator CreateGenerator()
{
return CreateGenerator(new Settings());
}
private static AzureResourceSchemaCodeGenerator CreateGenerator(Settings settings)
{
return new AzureResourceSchemaCodeGenerator(settings);
}

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

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

ServiceClient serviceClient = new ServiceClient();
foreach(string methodUrl in methodUrls)
{
serviceClient.Methods.Add(new Method()
{
Url = methodUrl
});
}
await CreateGenerator(settings).Generate(serviceClient);

Assert.Equal(2, fileSystem.VirtualStore.Count);

string folderPath = fileSystem.VirtualStore.Keys.First();
Assert.Equal("Folder", fileSystem.VirtualStore[folderPath].ToString());

JObject expectedJSON = JObject.Parse(expectedJsonString);

string fileContents = fileSystem.VirtualStore[fileSystem.VirtualStore.Keys.Skip(1).First()].ToString();
JObject actualJson = JObject.Parse(fileContents);

Assert.Equal(expectedJSON, actualJson);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
<package id="xunit" version="2.1.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net451" />
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\..\</SolutionDir>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<LibraryFxTarget Condition="'$(LibraryFxTarget)' == ''">net45</LibraryFxTarget>
<ProjectGuid>{654344A5-0556-49C7-BFB3-59676D7440D3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.Rest.Generator.AzureResourceSchema</RootNamespace>
<AssemblyName>AutoRest.Generator.AzureResourceSchema</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Configuration Condition=" '$(Configuration)' == '' ">Net45-Debug</Configuration>
</PropertyGroup>
<Import Project="$(SolutionDir)\Tools\AutoRest.Settings.targets" />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Net45-Debug|AnyCPU' ">
<Optimize>false</Optimize>
<OutputPath>bin\Net45-Debug</OutputPath>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ResourceProperty.cs" />
<Compile Include="ResourceSchema.cs" />
<Compile Include="AzureResourceSchemaCodeGenerator.cs" />
<Compile Include="$(SolutionDir)\Tools\AssemblyVersionInfo.cs">
<Link>Properties\AssemblyVersionInfo.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\AutoRest.Core\AutoRest.Core.csproj">
<Project>{c876085f-9dc3-41f0-b7b4-17022cd84684}</Project>
<Name>AutoRest.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\Extensions\Extensions\AutoRest.Generator.Extensions.csproj">
<Project>{7dd043eb-5e53-4180-b123-cc3cc5022e34}</Project>
<Name>AutoRest.Generator.Extensions</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="$(SolutionDir)\Tools\CustomDictionary.xml">
<Link>CustomDictionary.xml</Link>
</CodeAnalysisDictionary>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
Expand Down Expand Up @@ -40,6 +83,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Resource.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Loading

0 comments on commit 47753e5

Please sign in to comment.