Skip to content

Commit

Permalink
Fix FXCopy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Schulte committed Apr 22, 2016
1 parent f325514 commit c38771d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ResourceProperty.cs" />
<Compile Include="Schema.cs" />
<Compile Include="ResourceSchema.cs" />
<Compile Include="AzureResourceSchemaCodeGenerator.cs" />
<Compile Include="$(SolutionDir)\Tools\AssemblyVersionInfo.cs">
<Link>Properties\AssemblyVersionInfo.cs</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override async Task Generate(ServiceClient serviceClient)
writer.Indentation = 2;
writer.IndentChar = ' ';

Schema schema = Schema.Parse(serviceClient);
ResourceSchema schema = ResourceSchema.Parse(serviceClient);

WriteSchema(writer, schema);
}
Expand All @@ -76,12 +76,12 @@ public override async Task Generate(ServiceClient serviceClient)
}
}

private static void WriteSchema(JsonTextWriter writer, Schema schema)
private static void WriteSchema(JsonTextWriter writer, ResourceSchema schema)
{
WriteObject(writer, () =>
{
WriteProperty(writer, "id", schema.Id);
WriteProperty(writer, "$schema", schema.SchemaUri);
WriteProperty(writer, "$schema", "http://json-schema.org/draft-04/schema#");
WriteProperty(writer, "title", schema.Title);
WriteProperty(writer, "description", schema.Description);
WriteProperty(writer, "resourceDefinitions", () =>
Expand All @@ -105,7 +105,7 @@ private static void WriteResource(JsonTextWriter writer, Resource resource)
{
WriteProperty(writer, "enum", new string[]
{
resource.Type
resource.ResourceType
});
});
Expand Down Expand Up @@ -147,9 +147,9 @@ private static void WriteResourceProperty(JsonTextWriter writer, ResourcePropert
{
WriteObjectOrExpression(writer, () =>
{
if (resourceProperty.Type != null)
if (resourceProperty.PropertyType != null)
{
WriteProperty(writer, "type", resourceProperty.Type);
WriteProperty(writer, "type", resourceProperty.PropertyType);
}
if (resourceProperty.AllowedValues != null)
Expand Down Expand Up @@ -196,12 +196,6 @@ private static void WriteProperty(JsonTextWriter writer, string propertyName, st
writer.WriteValue(propertyValue);
}

private static void WriteProperty(JsonTextWriter writer, string propertyName, int propertyValue)
{
writer.WritePropertyName(propertyName);
writer.WriteValue(propertyValue);
}

private static void WriteProperty(JsonTextWriter writer, string propertyName, Action writeObjectContents)
{
writer.WritePropertyName(propertyName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System;
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -31,4 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ namespace Microsoft.Rest.Generator.AzureResourceSchema
public class Resource
{
private readonly string name;
private readonly string type;
private readonly string resourceType;
private readonly string[] apiVersions;
private readonly IEnumerable<ResourceProperty> properties;
private readonly string description;

public Resource(string name, string type, string[] apiVersions, IEnumerable<ResourceProperty> properties, string description)
public Resource(string name, string resourceType, string[] apiVersions, IEnumerable<ResourceProperty> properties, string description)
{
this.name = name;
this.type = type;
this.resourceType = resourceType;
this.apiVersions = apiVersions;
this.properties = properties;
this.description = description;
Expand All @@ -28,12 +28,12 @@ public string Name
get { return name; }
}

public string Type
public string ResourceType
{
get { return type; }
get { return resourceType; }
}

public string[] ApiVersions
public IEnumerable<string> ApiVersions
{
get { return apiVersions; }
}
Expand All @@ -43,7 +43,7 @@ public IEnumerable<ResourceProperty> Properties
get { return properties; }
}

public string[] RequiredPropertyNames
public IEnumerable<string> RequiredPropertyNames
{
get { return Properties.Where(property => property.IsRequired).Select(property => property.Name).ToArray(); }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Generic;

namespace Microsoft.Rest.Generator.AzureResourceSchema
{
public class ResourceProperty
{
private readonly string name;
private readonly bool isRequired;
private readonly string type;
private readonly string[] allowedValues;
private readonly string propertyType;
private readonly IEnumerable<string> allowedValues;
private readonly string description;

public ResourceProperty(string name, bool isRequired = false, string type = null, string[] allowedValues = null, string description = null)
public ResourceProperty(string name, bool isRequired, string propertyType, IEnumerable<string> allowedValues, string description)
{
this.name = name;
this.isRequired = isRequired;
this.type = type;
this.propertyType = propertyType;
this.allowedValues = allowedValues;
this.description = description;
}
Expand All @@ -30,12 +32,12 @@ public bool IsRequired
get { return isRequired; }
}

public string Type
public string PropertyType
{
get { return type; }
get { return propertyType; }
}

public string[] AllowedValues
public IEnumerable<string> AllowedValues
{
get { return allowedValues; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
using Microsoft.Rest.Generator.ClientModel;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace Microsoft.Rest.Generator.AzureResourceSchema
{
public class Schema
public class ResourceSchema
{
private const string resourceMethodPrefix = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/";

Expand All @@ -17,7 +18,7 @@ public class Schema
private readonly string description;
private readonly IEnumerable<Resource> resources;

private Schema(string id, string title, string description, IEnumerable<Resource> resources)
private ResourceSchema(string id, string title, string description, IEnumerable<Resource> resources)
{
this.id = id;
this.title = title;
Expand All @@ -30,11 +31,6 @@ public string Id
get { return id; }
}

public string SchemaUri
{
get { return "http://json-schema.org/draft-04/schema#"; }
}

public string Title
{
get { return title; }
Expand All @@ -50,12 +46,17 @@ public IEnumerable<Resource> Resources
get { return resources; }
}

public static Schema Parse(ServiceClient serviceClient)
public static ResourceSchema Parse(ServiceClient serviceClient)
{
if (serviceClient == null)
{
throw new ArgumentNullException("serviceClient");
}

string resourceProvider = GetResourceProvider(serviceClient);
string apiVersion = serviceClient.ApiVersion;

string id = String.Format("http://schema.management.azure.com/schemas/{0}/{1}.json#", apiVersion, resourceProvider);
string id = String.Format(CultureInfo.InvariantCulture, "http://schema.management.azure.com/schemas/{0}/{1}.json#", apiVersion, resourceProvider);

string title = resourceProvider;

Expand Down Expand Up @@ -85,7 +86,7 @@ public static Schema Parse(ServiceClient serviceClient)
bool propertyIsRequired = property.IsRequired;
string propertyType = null;
string[] allowedValues = null;
string propertyDescription = String.Format("{0}: {1}", resourceType, property.Documentation);
string propertyDescription = String.Format(CultureInfo.InvariantCulture, "{0}: {1}", resourceType, property.Documentation);

if(property.Type is EnumType)
{
Expand All @@ -108,12 +109,12 @@ public static Schema Parse(ServiceClient serviceClient)
}
}

return new Schema(id, title, description, resources);
return new ResourceSchema(id, title, description, resources);
}

private static IEnumerable<Method> GetResourceMethods(ServiceClient serviceClient)
{
return serviceClient.Methods.Where(method => method.Url.StartsWith(resourceMethodPrefix));
return serviceClient.Methods.Where(method => method.Url.StartsWith(resourceMethodPrefix, StringComparison.Ordinal));
}

private static string GetResourceProvider(ServiceClient serviceClient)
Expand Down

0 comments on commit c38771d

Please sign in to comment.