Skip to content

Commit

Permalink
Add annotation term for OData.Community.UrlEscape.V1.UrlEscapeFuncti…
Browse files Browse the repository at this point in the history
…on. (#1307)

* Add annotation term for OData.Community.UrlEscape.V1.UrlEscapeFunction.
- Move the UrlEscapeFuntion into new Community vocabularies; AlternateKeys will be moved later.

* Update per CR comments.

* CR updates from Mike's comments.
  • Loading branch information
biaol-odata committed Nov 20, 2018
1 parent b739e24 commit 469f209
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@
<Compile Include="$(EdmLibCrossTargettingSourcePath)\Vocabularies\AlternateKeysVocabularyConstants.cs">
<Link>Microsoft\OData\Edm\Vocabularies\AlternateKeysVocabularyConstants.cs</Link>
</Compile>
<Compile Include="$(EdmLibCrossTargettingSourcePath)\Vocabularies\CommunityVocabularyConstants.cs">
<Link>Microsoft\OData\Edm\Vocabularies\CommunityVocabularyConstants.cs</Link>
</Compile>
<Compile Include="$(EdmLibCrossTargettingSourcePath)\Vocabularies\CoreVocabularyConstants.cs">
<Link>Microsoft\OData\Edm\Vocabularies\CoreVocabularyConstants.cs</Link>
</Compile>
Expand All @@ -352,6 +355,9 @@
<Compile Include="$(EdmLibCrossTargettingSourcePath)\Vocabularies\AlternateKeysVocabularyModel.cs">
<Link>Microsoft\OData\Edm\Vocabularies\AlternateKeysVocabularyModel.cs</Link>
</Compile>
<Compile Include="$(EdmLibCrossTargettingSourcePath)\Vocabularies\CommunityVocabularyModel.cs">
<Link>Microsoft\OData\Edm\Vocabularies\CommunityVocabularyModel.cs</Link>
</Compile>
<Compile Include="$(EdmLibCrossTargettingSourcePath)\Vocabularies\AuthorizationVocabularyModel.cs">
<Link>Microsoft\OData\Edm\Vocabularies\AuthorizationVocabularyModel.cs</Link>
</Compile>
Expand Down Expand Up @@ -1499,6 +1505,9 @@
</EmbeddedResource>
<EmbeddedResource Include="$(EdmLibCrossTargettingSourcePath)\Vocabularies\AlternateKeysVocabularies.xml">
<LogicalName>AlternateKeysVocabularies.xml</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="$(EdmLibCrossTargettingSourcePath)\Vocabularies\CommunityVocabularies.xml">
<LogicalName>CommunityVocabularies.xml</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="$(EdmLibCrossTargettingSourcePath)\Vocabularies\AuthorizationVocabularies.xml">
<LogicalName>AuthorizationVocabularies.xml</LogicalName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,12 @@
</Compile>
<Compile Include="..\Vocabularies\AlternateKeysVocabularyModel.cs">
<Link>Vocabularies\AlternateKeysVocabularyModel.cs</Link>
</Compile>
<Compile Include="..\Vocabularies\CommunityVocabularyConstants.cs">
<Link>Vocabularies\CommunityVocabularyConstants.cs</Link>
</Compile>
<Compile Include="..\Vocabularies\CommunityVocabularyModel.cs">
<Link>Vocabularies\CommunityVocabularyModel.cs</Link>
</Compile>
<Compile Include="..\Vocabularies\AuthorizationVocabularyModel.cs">
<Link>Vocabularies\AuthorizationVocabularyModel.cs</Link>
Expand Down Expand Up @@ -1527,6 +1533,9 @@
<ItemGroup>
<EmbeddedResource Include="..\Vocabularies\AlternateKeysVocabularies.xml">
<Link>Vocabularies\AlternateKeysVocabularies.xml</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\Vocabularies\CommunityVocabularies.xml">
<Link>Vocabularies\CommunityVocabularies.xml</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\Vocabularies\AuthorizationVocabularies.xml">
<Link>Vocabularies\AuthorizationVocabularies.xml</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<None Remove="Microsoft.OData.Edm.tt" />
<None Remove="Microsoft.OData.Edm.txt" />
<None Remove="Parameterized.Microsoft.OData.Edm.tt" />
<None Remove="Vocabularies\AlternateKeysVocabularies.xml" />
<None Remove="Vocabularies\AlternateKeysVocabularies.xml" />
<None Remove="Vocabularies\CommunityVocabularies.xml" />
<None Remove="Vocabularies\AuthorizationVocabularies.xml" />
<None Remove="Vocabularies\CapabilitiesVocabularies.xml" />
<None Remove="Vocabularies\CoreVocabularies.xml" />
Expand Down Expand Up @@ -106,6 +107,10 @@
<EmbeddedResource Include="Vocabularies\AlternateKeysVocabularies.xml">
<LogicalName>AlternateKeysVocabularies.xml</LogicalName>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Vocabularies\CommunityVocabularies.xml">
<LogicalName>CommunityVocabularies.xml</LogicalName>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Vocabularies\AuthorizationVocabularies.xml">
<LogicalName>AuthorizationVocabularies.xml</LogicalName>
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.OData.Edm/Microsoft.OData.Edm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@
<Compile Include="Vocabularies\CapabilitiesVocabularyModel.cs" />
<Compile Include="Vocabularies\AlternateKeysVocabularyConstants.cs" />
<Compile Include="Vocabularies\AlternateKeysVocabularyModel.cs" />
<Compile Include="Vocabularies\CommunityVocabularyConstants.cs" />
<Compile Include="Vocabularies\CommunityVocabularyModel.cs" />
<Compile Include="Vocabularies\CoreVocabularyConstants.cs" />
<Compile Include="Vocabularies\CoreVocabularyModel.cs" />
<Compile Include="Vocabularies\EdmExpressionEvaluator.cs" />
Expand Down Expand Up @@ -547,6 +549,10 @@
<LogicalName>AlternateKeysVocabularies.xml</LogicalName>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Vocabularies\CommunityVocabularies.xml">
<LogicalName>CommunityVocabularies.xml</LogicalName>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Vocabularies\ValidationVocabularies.xml">
<LogicalName>ValidationVocabularies.xml</LogicalName>
<SubType>Designer</SubType>
Expand Down
13 changes: 13 additions & 0 deletions src/Microsoft.OData.Edm/Vocabularies/CommunityVocabularies.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/os/vocabularies/Org.OData.Core.V1.xml">
<edmx:Include Alias="Core" Namespace="Org.OData.Core.V1" />
</edmx:Reference>
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Org.OData.Community.V1" Alias="Community">
<Term AppliesTo="Function" Type="Core.Tag" Name="UrlEscapeFunction">
<Annotation Term="Core.Description" String="Annotates a function to be substituted for a colon-escaped segment in a Url path"/>
</Term>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//---------------------------------------------------------------------
// <copyright file="CommunityVocabularyConstants.cs" company="Microsoft">
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
// </copyright>
//---------------------------------------------------------------------

namespace Microsoft.OData.Edm.Vocabularies.Community.V1
{
/// <summary>
/// Constant values for Community Vocabularies
/// </summary>
internal static class CommunityVocabularyConstants
{
/// <summary>OData.Community.V1.UrlEscapeFunction </summary>
internal const string UrlEscapeFunction = "Org.OData.Community.V1.UrlEscapeFunction";
}
}
61 changes: 61 additions & 0 deletions src/Microsoft.OData.Edm/Vocabularies/CommunityVocabularyModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//---------------------------------------------------------------------
// <copyright file="CommunityVocabularyModel.cs" company="Microsoft">
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
// </copyright>
//---------------------------------------------------------------------

using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Validation;

namespace Microsoft.OData.Edm.Vocabularies.Community.V1
{
/// <summary>
/// Representing Community Vocabulary Model.
/// </summary>
public static class CommunityVocabularyModel
{
/// <summary>
/// The EDM model with Community vocabularies.
/// </summary>
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "EdmModel is immutable")]
public static readonly IEdmModel Instance = CommunityVocabularyReader.GetEdmModel();

/// <summary>
/// The Url escape function term.
/// </summary>
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "EdmTerm is immutable")]
public static readonly IEdmTerm UrlEscapeFunctionTerm = Instance.FindDeclaredTerm(CommunityVocabularyConstants.UrlEscapeFunction);
}

internal static class CommunityVocabularyReader
{
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "EdmModel is immutable")]

internal static IEdmModel GetEdmModel()
{
Assembly assembly = typeof(CommunityVocabularyModel).GetAssembly();

// Resource name has leading namespace and folder in .NetStandard dll.
string[] allResources = assembly.GetManifestResourceNames();
string communityVocabularies = allResources.Where(x => x.Contains("CommunityVocabularies.xml")).FirstOrDefault();
Debug.Assert(communityVocabularies != null, "CommunityVocabularies.xml: not found.");

IEdmModel instance;
using (Stream stream = assembly.GetManifestResourceStream(communityVocabularies))
{
IEnumerable<EdmError> errors;
Debug.Assert(stream != null, "CommunityVocabularies.xml: stream!=null");
CsdlReader.TryParse(XmlReader.Create(stream), out instance, out errors);
}

return instance;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="..\Vocabularies\CoreVocabularyTests.cs" />
<Compile Include="..\Vocabularies\AuthorizationVocabularyTests.cs" />
<Compile Include="..\Vocabularies\ValidationVocabularyTests.cs" />
<Compile Include="..\Vocabularies\CommunityVocabularyTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\packages.config" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//---------------------------------------------------------------------
// <copyright file="CommunityVocabularyTests.cs" company="Microsoft">
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
// </copyright>
//---------------------------------------------------------------------

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Text;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Validation;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OData.Edm.Vocabularies.Community.V1;
using Xunit;

namespace Microsoft.OData.Edm.Tests.Vocabularies
{
public class CommunityVocabularyTests
{
private readonly IEdmModel model = CommunityVocabularyModel.Instance;

[Fact]
public void TestCommunityVocabularyModel()
{
const string expectedUrlEscape = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""Org.OData.Community.V1"" Alias=""Community"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
<Term Name=""UrlEscapeFunction"" Type=""Core.Tag"" AppliesTo=""Function"">
<Annotation Term=""Core.Description"" String=""Annotates a function to be substituted for a colon-escaped segment in a Url path"" />
</Term>
</Schema>";

StringWriter sw = new StringWriter();
IEnumerable<EdmError> errors;
using (var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true, Encoding = Encoding.UTF8 }))
{
Assert.True(model.TryWriteSchema(xw, out errors));
}


Assert.False(errors.Any(), "No Errors");

string output = sw.ToString();
Assert.True(expectedUrlEscape == output, "expected Community schema not matching");
}

[Fact]
public void TestUrlEscapeFunctionAnnotationTerm()
{
var urlEscapeFunctionTerm = model.FindDeclaredTerm(CommunityVocabularyConstants.UrlEscapeFunction);
Assert.NotNull(urlEscapeFunctionTerm);
Assert.Equal(CommunityVocabularyModel.UrlEscapeFunctionTerm, urlEscapeFunctionTerm);
Assert.Equal("Org.OData.Community.V1", urlEscapeFunctionTerm.Namespace);
Assert.Equal("UrlEscapeFunction", urlEscapeFunctionTerm.Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4036,6 +4036,11 @@ public sealed class Microsoft.OData.Edm.Vocabularies.Community.V1.AlternateKeysV
public static readonly Microsoft.OData.Edm.IEdmModel Instance = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsModel
}

public sealed class Microsoft.OData.Edm.Vocabularies.Community.V1.CommunityVocabularyModel {
public static readonly Microsoft.OData.Edm.IEdmModel Instance = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsModel
public static readonly Microsoft.OData.Edm.Vocabularies.IEdmTerm UrlEscapeFunctionTerm = Microsoft.OData.Edm.Csdl.CsdlSemantics.CsdlSemanticsTerm
}

public enum Microsoft.OData.BatchPayloadUriOption : int {
AbsoluteUri = 0
AbsoluteUriUsingHostHeader = 1
Expand Down

0 comments on commit 469f209

Please sign in to comment.