Skip to content

Commit

Permalink
Merge pull request #110 from microsoftgraph/feature/inner-error-injec…
Browse files Browse the repository at this point in the history
…tion

adds inner error description
  • Loading branch information
baywet authored Feb 4, 2022
2 parents fd8d068 + 935876f commit 1a8cdc3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/metadata-parser-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Validate latest XSLT rules
run: ./scripts/run-metadata-validation.ps1 -repoDirectory "${{ github.workspace }}"
shell: pwsh
4 changes: 2 additions & 2 deletions scripts/run-metadata-validation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Write-Host "Tranforming beta metadata using xslt..." -ForegroundColor Green
& $transformScript -xslPath $xsltPath -inputPath $betaSnapshot -outputPath $transformedBeta

Write-Host "Validating beta metadata after the transform..." -ForegroundColor Green
& dotnet run -p $metadataParserTool $transformedBeta
& dotnet run --project $metadataParserTool $transformedBeta

Write-Host "Tranforming v1.0 metadata using xslt..." -ForegroundColor Green
& $transformScript -xslPath $xsltPath -inputPath $v1Snapshot -outputPath $transformedV1

Write-Host "Validating v1.0 metadata after the transform..." -ForegroundColor Green
& dotnet run -p $metadataParserTool $transformedV1
& dotnet run --project $metadataParserTool $transformedV1
2 changes: 1 addition & 1 deletion tools/MetadataParser/MetadataParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion tools/MetadataParser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
IEdmModel edmModel;
try
{
edmModel = CsdlReader.Parse(XmlReader.Create(args[0]));
using var reader = XmlReader.Create(args[0]);
edmModel = CsdlReader.Parse(reader);
Console.WriteLine("Parsing the metadata as an edm model was successful!");

var settings = new OpenApiConvertSettings()
Expand Down
34 changes: 34 additions & 0 deletions transforms/csdl/preprocess_csdl.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/> <!-- Remove empty space after deletions. -->
<xsl:param name="remove-capability-annotations">True</xsl:param>
<xsl:param name="add-innererror-description">False</xsl:param>

<!-- DO NOT FORMAT ON SAVE or else the match templates will become unreadable. -->
<!-- All element references should include schema namespace as we need to support multiple namespaces. -->
Expand Down Expand Up @@ -500,6 +501,38 @@
<xsl:template match="edm:Schema[@Namespace='microsoft.graph']">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<xsl:choose>
<!-- Add inner error description -->
<xsl:when test="$add-innererror-description='True'">
<xsl:element name="ComplexType">
<xsl:attribute name="Name">InnerError</xsl:attribute>
<xsl:element name="Property">
<xsl:attribute name="Name">request-id</xsl:attribute>
<xsl:attribute name="Type">Edm.String</xsl:attribute>
<xsl:element name="Annotation">
<xsl:attribute name="Term">Org.OData.Core.V1.Description</xsl:attribute>
<xsl:attribute name="String">Request Id as tracked internally by the service</xsl:attribute>
</xsl:element>
</xsl:element>
<xsl:element name="Property">
<xsl:attribute name="Name">client-request-id</xsl:attribute>
<xsl:attribute name="Type">Edm.String</xsl:attribute>
<xsl:element name="Annotation">
<xsl:attribute name="Term">Org.OData.Core.V1.Description</xsl:attribute>
<xsl:attribute name="String">Client request Id as sent by the client application.</xsl:attribute>
</xsl:element>
</xsl:element>
<xsl:element name="Property">
<xsl:attribute name="Name">Date</xsl:attribute>
<xsl:attribute name="Type">Edm.DateTimeOffset</xsl:attribute>
<xsl:element name="Annotation">
<xsl:attribute name="Term">Org.OData.Core.V1.Description</xsl:attribute>
<xsl:attribute name="String">Date when the error occured.</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:when>
</xsl:choose>
<!-- Remove navigability for workbook navigation property -->
<xsl:element name="Annotations">
<xsl:attribute name="Target">microsoft.graph.driveItem/workbook</xsl:attribute>
Expand Down Expand Up @@ -634,4 +667,5 @@
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
4 changes: 3 additions & 1 deletion transforms/csdl/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ Please use fully qualified and precise template match statements so as not to pe
> NB: The build job in the pipeline currently errors out on PRs coming in from personal forked repos.
## Command line instructions for running the transform

1. Start PowerShell
2. `cd` into `transforms\csdl` folder
3. Run `transform.ps1 <xsl_file> <input_file> <output_file>`. If files are not specified, the script will apply transformations from *preprocess_csdl.xsl* on *preprocess_csdl_test_input.xml* and override *preprocess_csdl_test_output.xml* file.
3. Run `transform.ps1 <xsl_file> <input_file> <output_file>`. If files are not specified, the script will apply transformations from *preprocess_csdl.xsl* on *preprocess_csdl_test_input.xml* and override *preprocess_csdl_test_output.xml* file.
4. You can optionally run the transform without removing capability annotations by setting the `-removeCapabilityAnnotations` flag to `$false`. The default behavior is to remove capability annotations.
5. You can optionally run the transform to inject the OData inner error description by setting the `addInnerErrorDescription` flag to `$true`. The default value is `$false`.

## Instructions for running transform against Microsoft Graph metadata

Expand Down
12 changes: 9 additions & 3 deletions transforms/csdl/transform.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ param (
[bool]
$dbg = $false,
[bool]
$removeCapabilityAnnotations = $true
$removeCapabilityAnnotations = $true,
[bool]
$addInnerErrorDescription = $false
)
function Get-PathWithPrefix([string]$requestedPath) {
if([System.IO.Path]::IsPathRooted($requestedPath)) {
Expand All @@ -36,17 +38,21 @@ $outputFullPath = Get-PathWithPrefix -requestedPath $outputPath

$xsltargs = [System.Xml.Xsl.XsltArgumentList]::new()
$xsltargs.AddParam("remove-capability-annotations", "", $removeCapabilityAnnotations.ToString())
$xsltargs.AddParam("add-innererror-description", "", $addInnerErrorDescription.ToString())

$xmlWriterSettings = [System.Xml.XmlWriterSettings]::new()
$xmlWriterSettings.Indent = $true

$xmlWriter = [System.Xml.XmlWriter]::Create($outputFullPath, $xmlWriterSettings)

$xslt = [System.Xml.Xsl.XslCompiledTransform]::new($dbg)
$xslt.Load($xslFullPath)
try {
$xslt = [System.Xml.Xsl.XslCompiledTransform]::new($dbg)
$xslt.Load($xslFullPath)
$xslt.Transform($inputFullPath, $xsltargs, $xmlWriter)
}
catch {
Write-Error $_.Exception
}
finally {
$xmlWriter.Close()
}

0 comments on commit 1a8cdc3

Please sign in to comment.