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

Add annotation term for Org.OData.Community.UrlEscape.V1.UrlEscapeFunction. #1307

Merged
merged 3 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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";
Copy link
Member

@mikepizzo mikepizzo Nov 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal [](start = 8, length = 8)

Either make this public or make the class internal. Unless we think there is a client scenario that requires it, I would make the class internal -- we can always make it public later. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.


In reply to: 231620168 [](ancestors = 231620168)

}
}
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
Copy link
Member

@xuzhg xuzhg Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CommunityVocabularyTests [](start = 17, length = 24)

Maybe add test cases:

  1. In the CsdlWriter, create the model with function decorated with this term?

  2. In the CsdlReader, read the csdl with function decorated with this term. #Resolved

Copy link
Contributor Author

@biaol-odata biaol-odata Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes these tests will be added, as part of EDM model validation test along with bound function, in the task for upper layer and as a separate PR. This PR here is just to add the CommunityVocabulary. #Resolved

{
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 @@ -3927,6 +3927,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