Skip to content

Commit 363df8c

Browse files
committed
Merge branch 'master' into feature/is/restrictions-descriptions
2 parents 01a84f9 + 64572d8 commit 363df8c

32 files changed

+1167
-11981
lines changed
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
name: $(TeamProject)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
4+
5+
# Trigger is on github tags
6+
trigger:
7+
tags:
8+
include:
9+
- '*'
10+
11+
# No Pull request (PR) triggers for release
12+
pr: none
13+
14+
pool:
15+
vmImage: 'windows-latest'
16+
17+
variables:
18+
buildPlatform: 'Any CPU'
19+
buildConfiguration: 'Release'
20+
snExe: 'C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\sn.exe'
21+
snExe64: 'C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\sn.exe'
22+
ProductBinPath: '$(Build.SourcesDirectory)\bin\$(BuildConfiguration)'
23+
mainDll: 'Microsoft.OpenApi.OData.Reader.dll'
24+
testDll: 'Microsoft.OpenApi.OData.Reader.Tests.dll'
25+
skipComponentGovernanceDetection: true
26+
27+
steps:
28+
29+
- task: UseDotNet@2
30+
displayName: 'Use .NET 6'
31+
inputs:
32+
version: 6.x
33+
34+
- task: PoliCheck@1
35+
displayName: 'Run PoliCheck "OpenApi.OData-master\src"'
36+
inputs:
37+
inputType: CmdLine
38+
cmdLineArgs: '/F:$(Build.SourcesDirectory)/src /T:9 /Sev:"1|2" /PE:2 /O:poli_result_src.xml'
39+
40+
- task: PoliCheck@1
41+
displayName: 'Run PoliCheck "OpenApi.OData-master\test"'
42+
inputs:
43+
inputType: CmdLine
44+
cmdLineArgs: '/F:$(Build.SourcesDirectory)/test /T:9 /Sev:"1|2" /PE:2 /O:poli_result_test.xml'
45+
46+
- task: PoliCheck@1
47+
displayName: 'PoliCheck for OpenApi.OData-master\tool'
48+
inputs:
49+
inputType: CmdLine
50+
cmdLineArgs: '/F:$(Build.SourcesDirectory)/tool /T:9 /Sev:"1|2" /PE:2 /O:poli_result_tool.xml'
51+
52+
# Install the nuget tooler.
53+
- task: NuGetToolInstaller@0
54+
displayName: 'Use NuGet >=5.2.0'
55+
inputs:
56+
versionSpec: '>=5.2.0'
57+
checkLatest: true
58+
59+
# Build the Product project
60+
- task: DotNetCoreCLI@2
61+
displayName: 'build Microsoft.OpenAPI.OData.Reader.csproj '
62+
inputs:
63+
projects: '$(Build.SourcesDirectory)\src\Microsoft.OpenApi.OData.Reader\Microsoft.OpenAPI.OData.Reader.csproj'
64+
arguments: '--configuration $(BuildConfiguration) --no-incremental'
65+
66+
# Build the Unit test project
67+
- task: DotNetCoreCLI@2
68+
displayName: 'build Microsoft.OpenAPI.OData.Reader.Tests.csproj'
69+
inputs:
70+
projects: '$(Build.SourcesDirectory)\test\Microsoft.OpenAPI.OData.Reader.Tests\Microsoft.OpenApi.OData.Reader.Tests.csproj'
71+
arguments: '--configuration $(BuildConfiguration) --no-incremental'
72+
73+
# because the assemblies are delay-signed, we need to disable
74+
# strong name validation so that the tests may run,
75+
# otherwise our assemblies will fail to load
76+
- task: Powershell@2
77+
displayName: 'Skip strong name validation'
78+
inputs:
79+
targetType: 'inline'
80+
script: |
81+
& "$(snExe)" /Vr $(ProductBinPath)\net472\$(mainDll)
82+
& "$(snExe64)" /Vr $(ProductBinPath)\net472\$(mainDll)
83+
& "$(snExe)" /Vr $(ProductBinPath)\test\net472\$(testDll)
84+
& "$(snExe64)" /Vr $(ProductBinPath)\test\net472\$(testDll)
85+
86+
# Run the Unit test
87+
- task: DotNetCoreCLI@2
88+
displayName: 'Run Microsoft.OpenApi.OData.Reader.Tests.csproj'
89+
inputs:
90+
command: test
91+
projects: '$(Build.SourcesDirectory)\test\Microsoft.OpenAPI.OData.Reader.Tests\Microsoft.OpenApi.OData.Reader.Tests.csproj'
92+
arguments: '--configuration $(BuildConfiguration) --no-build'
93+
94+
# CredScan
95+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
96+
displayName: 'Run CredScan - Src'
97+
inputs:
98+
toolMajorVersion: 'V2'
99+
scanFolder: '$(Build.SourcesDirectory)\src'
100+
debugMode: false
101+
102+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
103+
displayName: 'Run CredScan - Test'
104+
inputs:
105+
toolMajorVersion: 'V2'
106+
scanFolder: '$(Build.SourcesDirectory)\test'
107+
debugMode: false
108+
109+
# Microsoft.CodeAnalysis.FxCopAnalyzers is added into the project.
110+
# Typically, .NET Standard (.NET Core) project doesn't need the FxCop.
111+
112+
# Needn't the AntiMalware@3 task?
113+
- task: AntiMalware@3
114+
displayName: 'Run MpCmdRun.exe - ProductBinPath'
115+
inputs:
116+
FileDirPath: '$(ProductBinPath)'
117+
enabled: false
118+
119+
- task: BinSkim@3
120+
displayName: 'Run BinSkim - Product Binaries'
121+
inputs:
122+
InputType: Basic
123+
AnalyzeTarget: '$(ProductBinPath)\**\Microsoft.OpenApi.OData.Reader.dll'
124+
AnalyzeSymPath: '$(ProductBinPath)'
125+
AnalyzeVerbose: true
126+
AnalyzeHashes: true
127+
AnalyzeEnvironment: true
128+
129+
- task: PublishSecurityAnalysisLogs@2
130+
displayName: 'Publish Security Analysis Logs'
131+
inputs:
132+
ArtifactName: SecurityLogs
133+
134+
- task: PostAnalysis@1
135+
displayName: 'Post Analysis'
136+
inputs:
137+
BinSkim: true
138+
CredScan: true
139+
PoliCheck: true
140+
141+
- task: EsrpCodeSigning@1
142+
displayName: 'ESRP CodeSigning'
143+
inputs:
144+
ConnectedServiceName: 'microsoftgraph ESRP CodeSign DLL and NuGet (AKV)'
145+
FolderPath: '$(Build.SourcesDirectory)\bin\$(BuildConfiguration)'
146+
Pattern: Microsoft.OpenApi.OData.Reader.dll
147+
signConfigType: inlineSignParams
148+
inlineOperation: |
149+
[
150+
{
151+
"keyCode": "CP-230012",
152+
"operationSetCode": "SigntoolSign",
153+
"parameters": [
154+
{
155+
"parameterName": "OpusName",
156+
"parameterValue": "TestSign"
157+
},
158+
{
159+
"parameterName": "OpusInfo",
160+
"parameterValue": "http://test"
161+
},
162+
{
163+
"parameterName": "PageHash",
164+
"parameterValue": "/NPH"
165+
},
166+
{
167+
"parameterName": "FileDigest",
168+
"parameterValue": "/fd sha256"
169+
},
170+
{
171+
"parameterName": "TimeStamp",
172+
"parameterValue": "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256"
173+
}
174+
],
175+
"toolName": "signtool.exe",
176+
"toolVersion": "6.2.9304.0"
177+
},
178+
{
179+
"keyCode": "CP-230012",
180+
"operationSetCode": "SigntoolVerify",
181+
"parameters": [
182+
{
183+
"parameterName": "VerifyAll",
184+
"parameterValue": "/all"
185+
}
186+
],
187+
"toolName": "signtool.exe",
188+
"toolVersion": "6.2.9304.0"
189+
}
190+
]
191+
SessionTimeout: 20
192+
193+
- task: MSBuild@1
194+
displayName: 'Get Nuget Package Metadata'
195+
inputs:
196+
solution: '$(Build.SourcesDirectory)\tool\GetNugetPackageMetadata.proj'
197+
platform: '$(BuildPlatform)'
198+
configuration: '$(BuildConfiguration)'
199+
200+
- task: PowerShell@2
201+
displayName: 'Validate project version has been incremented'
202+
inputs:
203+
targetType: 'filePath'
204+
filePath: $(System.DefaultWorkingDirectory)\scripts\ValidateProjectVersionUpdated.ps1
205+
arguments: '-projectVersion "$(VersionFullSemantic)"'
206+
207+
- task: NuGetCommand@2
208+
displayName: 'NuGet pack Release.nuspec'
209+
inputs:
210+
command: custom
211+
arguments: 'pack $(Build.SourcesDirectory)\src\Microsoft.OpenApi.OData.Reader\Microsoft.OpenAPI.OData.Reader.Release.nuspec -NonInteractive -OutputDirectory $(Build.ArtifactStagingDirectory)\Nuget -Properties Configuration=$(BuildConfiguration);ProductRoot=$(ProductBinPath);VersionFullSemantic=$(VersionFullSemantic);NightlyBuildVersion=$(VersionNugetNightlyBuild);VersionNuGetSemantic=$(VersionNuGetSemantic);OpenApiCorePackageDependency="$(OpenApiCorePackageDependency)";ODataEdmPackageDependency="$(ODataEdmPackageDependency)"; -Verbosity Detailed -Symbols -SymbolPackageFormat snupkg'
212+
213+
- task: EsrpCodeSigning@1
214+
displayName: 'ESRP CodeSigning Nuget Packages'
215+
inputs:
216+
ConnectedServiceName: 'microsoftgraph ESRP CodeSign DLL and NuGet (AKV)'
217+
FolderPath: '$(Build.ArtifactStagingDirectory)\Nuget'
218+
Pattern: '*.nupkg'
219+
signConfigType: inlineSignParams
220+
inlineOperation: |
221+
[
222+
{
223+
"keyCode": "CP-401405",
224+
"operationSetCode": "NuGetSign",
225+
"parameters": [ ],
226+
"toolName": "sign",
227+
"toolVersion": "1.0"
228+
},
229+
{
230+
"keyCode": "CP-401405",
231+
"operationSetCode": "NuGetVerify",
232+
"parameters": [ ],
233+
"toolName": "sign",
234+
"toolVersion": "1.0"
235+
}
236+
]
237+
SessionTimeout: 20
238+
239+
- task: PublishBuildArtifacts@1
240+
displayName: 'Publish Artifact - Nuget Packages'
241+
inputs:
242+
PathtoPublish: '$(Build.ArtifactStagingDirectory)\Nuget'
243+
ArtifactName: Nuget
244+
245+
- task: NuGetCommand@2
246+
displayName: 'Push nuget package to nuget.org'
247+
inputs:
248+
command: push
249+
packagesToPush: '$(Build.ArtifactStagingDirectory)\Nuget\*.nupkg'
250+
nuGetFeedType: external
251+
publishFeedCredentials: 'OpenAPI Nuget Connection'
252+
253+
- task: GithubRelease@1
254+
displayName: 'Create Github Release (v$(VersionFullSemantic))'
255+
inputs:
256+
githubConnection: 'github - danielmbaluka'
257+
title: 'v$(VersionFullSemantic)'
258+
tagSource: userSpecifiedTag
259+
tag: 'v$(VersionFullSemantic)'
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
<#
5+
.Synopsis
6+
Validates that the package version has been updated
7+
.Description
8+
Validates that the package version has been updated by comparing the version
9+
specified in the project file with the latest package version published on
10+
NuGet. If the version has not been updated, the script will fail and indicate
11+
that the project version neeeds to be updated.
12+
13+
.Parameter projectVersion
14+
Specifies the current project version. The project version currently is maintained
15+
in the versioning.props file
16+
#>
17+
18+
Param(
19+
[parameter(Mandatory = $true)]
20+
[string]$projectVersion
21+
)
22+
23+
$packageName = "Microsoft.OpenApi.OData"
24+
25+
# Cast the project version string to System.Version
26+
[version]$currentProjectVersion = $projectVersion
27+
28+
# API is case-sensitive
29+
$packageName = $packageName.ToLower()
30+
$url = "https://api.nuget.org/v3/registration5-semver1/$packageName/index.json"
31+
32+
# Call the NuGet API for the package and get the current published version.
33+
$nugetIndex = Invoke-RestMethod -Uri $url -Method Get
34+
$publishedVersionString = $nugetIndex.items[0].upper
35+
36+
# Cast the published version string to System.Version
37+
[version]$currentPublishedVersion = $publishedVersionString
38+
39+
# Validate that the version number has been updated.
40+
if ($currentProjectVersion -le $currentPublishedVersion) {
41+
Write-Error "The project version in versioning.props file ($projectVersion) `
42+
has not been bumped up. The current published version is $publishedVersionString. `
43+
Please increment the current project version."
44+
}
45+
else {
46+
Write-Host "Validated that the version has been updated from $publishedVersionString to $currentProjectVersion" -ForegroundColor Green
47+
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ private void RetrieveComplexPropertyPaths(IEdmEntityType entityType, ODataPath c
247247
.Where(x => x.Type.IsComplex() ||
248248
x.Type.IsCollection() && x.Type.Definition.AsElementType() is IEdmComplexType))
249249
{
250+
if (!ShouldCreateComplexPropertyPaths(sp, convertSettings)) continue;
251+
250252
currentPath.Push(new ODataComplexPropertySegment(sp));
251253
AppendPath(currentPath.Clone());
252254

@@ -280,6 +282,27 @@ private void RetrieveComplexPropertyPaths(IEdmEntityType entityType, ODataPath c
280282
}
281283
}
282284

285+
/// <summary>
286+
/// Evaluates whether or not to create paths for complex properties.
287+
/// </summary>
288+
/// <param name="complexProperty">The target complex property.</param>
289+
/// <param name="convertSettings">The settings for the current conversion.</param>
290+
/// <returns>true or false.</returns>
291+
private bool ShouldCreateComplexPropertyPaths(IEdmStructuralProperty complexProperty, OpenApiConvertSettings convertSettings)
292+
{
293+
Debug.Assert(complexProperty != null);
294+
Debug.Assert(convertSettings != null);
295+
296+
if (!convertSettings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths)
297+
return true;
298+
299+
bool isReadable = _model.GetRecord<ReadRestrictionsType>(complexProperty, CapabilitiesConstants.ReadRestrictions)?.Readable ?? false;
300+
bool isUpdatable = _model.GetRecord<UpdateRestrictionsType>(complexProperty, CapabilitiesConstants.UpdateRestrictions)?.Updatable ?? false;
301+
bool isInsertable = _model.GetRecord<InsertRestrictionsType>(complexProperty, CapabilitiesConstants.InsertRestrictions)?.Insertable ?? false;
302+
303+
return isReadable || isUpdatable || isInsertable;
304+
}
305+
283306
/// <summary>
284307
/// Retrieves the paths for a media entity stream.
285308
/// </summary>

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
<LangVersion Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">latest</LangVersion>
99
<LangVersion Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">latest</LangVersion>
1010
<SignAssembly>true</SignAssembly>
11-
<AssemblyOriginatorKeyFile>..\..\tool\35MSSharedLib1024.snk</AssemblyOriginatorKeyFile>
12-
<DelaySign>true</DelaySign>
11+
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
1312
<OutputPath Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">..\..\bin\Debug\</OutputPath>
1413
<OutputPath Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">..\..\bin\Release\</OutputPath>
1514
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>

src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ public string PathPrefix
225225
/// </summary>
226226
public string InnerErrorComplexTypeName { get; set; } = "InnerError";
227227

228+
/// <summary>
229+
/// Gets/Sets a value indicating whether or not to use restrictions annotations to generate paths for complex properties.
230+
/// </summary>
231+
public bool RequireRestrictionAnnotationsToGenerateComplexPropertyPaths { get; set; } = true;
232+
228233
internal OpenApiConvertSettings Clone()
229234
{
230235
var newSettings = new OpenApiConvertSettings
@@ -262,7 +267,8 @@ internal OpenApiConvertSettings Clone()
262267
EnableDeprecationInformation = this.EnableDeprecationInformation,
263268
AddEnumDescriptionExtension = this.AddEnumDescriptionExtension,
264269
ErrorResponsesAsDefault = this.ErrorResponsesAsDefault,
265-
InnerErrorComplexTypeName = this.InnerErrorComplexTypeName
270+
InnerErrorComplexTypeName = this.InnerErrorComplexTypeName,
271+
RequireRestrictionAnnotationsToGenerateComplexPropertyPaths = this.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths
266272
};
267273

268274
return newSettings;

0 commit comments

Comments
 (0)