Skip to content

Commit 97c5364

Browse files
authored
Merge pull request #1324 from microsoft/vnext
Release libs
2 parents 137a456 + c022557 commit 97c5364

15 files changed

+181
-138
lines changed

.github/workflows/sonarcloud.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ jobs:
2929
name: Build
3030
runs-on: windows-latest
3131
steps:
32-
- name: Set up JDK 11
32+
- name: Set up JDK 17
3333
uses: actions/setup-java@v3
3434
with:
3535
distribution: 'adopt'
36-
java-version: 11
36+
java-version: 17
3737
- name: Setup .NET 5 # At the moment the scanner requires dotnet 5 https://www.nuget.org/packages/dotnet-sonarscanner
3838
uses: actions/setup-dotnet@v3
3939
with:

src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
1616
<ToolCommandName>hidi</ToolCommandName>
1717
<PackageOutputPath>./../../artifacts</PackageOutputPath>
18-
<Version>1.2.6</Version>
18+
<Version>1.2.7</Version>
1919
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>OpenAPI .NET</PackageTags>

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0</TargetFrameworks>
4+
<LangVersion>latest</LangVersion>
45
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
56
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
67
<PackageProjectUrl>https://github.com/Microsoft/OpenAPI.NET</PackageProjectUrl>
@@ -10,7 +11,7 @@
1011
<Company>Microsoft</Company>
1112
<Title>Microsoft.OpenApi.Readers</Title>
1213
<PackageId>Microsoft.OpenApi.Readers</PackageId>
13-
<Version>1.6.6</Version>
14+
<Version>1.6.7</Version>
1415
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
1516
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1617
<PackageTags>OpenAPI .NET</PackageTags>

src/Microsoft.OpenApi.Readers/V2/OpenApiResponseDeserializer.cs

+21-21
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,35 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P
7373
}
7474

7575
var produces = context.GetFromTempStorage<List<string>>(TempStorageKeys.OperationProduces)
76-
?? context.GetFromTempStorage<List<string>>(TempStorageKeys.GlobalProduces);
77-
if (produces != null)
76+
?? context.GetFromTempStorage<List<string>>(TempStorageKeys.GlobalProduces)
77+
?? new List<string> { "application/octet-stream" };
78+
79+
var schema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema, response);
80+
81+
foreach (var produce in produces)
7882
{
79-
foreach (var produce in produces)
80-
{
81-
var schema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema, response);
8283

83-
if (response.Content.ContainsKey(produce) && response.Content[produce] != null)
84+
if (response.Content.TryGetValue(produce, out var produceValue))
85+
{
86+
if (schema != null)
8487
{
85-
if (schema != null)
86-
{
87-
response.Content[produce].Schema = schema;
88-
ProcessAnyFields(mapNode, response.Content[produce], _mediaTypeAnyFields);
89-
}
88+
produceValue.Schema = schema;
89+
ProcessAnyFields(mapNode, produceValue, _mediaTypeAnyFields);
9090
}
91-
else
91+
}
92+
else
93+
{
94+
var mediaType = new OpenApiMediaType
9295
{
93-
var mediaType = new OpenApiMediaType
94-
{
95-
Schema = schema
96-
};
96+
Schema = schema
97+
};
9798

98-
response.Content.Add(produce, mediaType);
99-
}
99+
response.Content.Add(produce, mediaType);
100100
}
101-
102-
context.SetTempStorage(TempStorageKeys.ResponseSchema, null, response);
103-
context.SetTempStorage(TempStorageKeys.ResponseProducesSet, true, response);
104101
}
102+
103+
context.SetTempStorage(TempStorageKeys.ResponseSchema, null, response);
104+
context.SetTempStorage(TempStorageKeys.ResponseProducesSet, true, response);
105105
}
106106

107107
private static void LoadExamples(OpenApiResponse response, ParseNode node)

src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs

+15-53
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
@@ -29,10 +29,11 @@ private static void ParseMap<T>(
2929
return;
3030
}
3131

32-
foreach (var propertyNode in mapNode)
32+
var allFields = fixedFieldMap.Keys.Union(mapNode.Select(static x => x.Name));
33+
foreach (var propertyNode in allFields)
3334
{
34-
propertyNode.ParseField(domainObject, fixedFieldMap, patternFieldMap);
35-
requiredFields?.Remove(propertyNode.Name);
35+
mapNode[propertyNode]?.ParseField(domainObject, fixedFieldMap, patternFieldMap);
36+
requiredFields?.Remove(propertyNode);
3637
}
3738
}
3839

@@ -77,16 +78,18 @@ private static void ProcessAnyListFields<T>(
7778
var newProperty = new List<IOpenApiAny>();
7879

7980
mapNode.Context.StartObject(anyListFieldName);
80-
81-
var list = anyListFieldMap[anyListFieldName].PropertyGetter(domainObject);
82-
if (list != null)
81+
if (anyListFieldMap.TryGetValue(anyListFieldName, out var fieldName))
8382
{
84-
foreach (var propertyElement in list)
83+
var list = fieldName.PropertyGetter(domainObject);
84+
if (list != null)
8585
{
86-
newProperty.Add(
87-
OpenApiAnyConverter.GetSpecificOpenApiAny(
88-
propertyElement,
89-
anyListFieldMap[anyListFieldName].SchemaGetter(domainObject)));
86+
foreach (var propertyElement in list)
87+
{
88+
newProperty.Add(
89+
OpenApiAnyConverter.GetSpecificOpenApiAny(
90+
propertyElement,
91+
anyListFieldMap[anyListFieldName].SchemaGetter(domainObject)));
92+
}
9093
}
9194
}
9295

@@ -104,47 +107,6 @@ private static void ProcessAnyListFields<T>(
104107
}
105108
}
106109

107-
private static void ProcessAnyMapFields<T, U>(
108-
MapNode mapNode,
109-
T domainObject,
110-
AnyMapFieldMap<T, U> anyMapFieldMap)
111-
{
112-
foreach (var anyMapFieldName in anyMapFieldMap.Keys.ToList())
113-
{
114-
try
115-
{
116-
var newProperty = new List<IOpenApiAny>();
117-
118-
mapNode.Context.StartObject(anyMapFieldName);
119-
120-
foreach (var propertyMapElement in anyMapFieldMap[anyMapFieldName].PropertyMapGetter(domainObject))
121-
{
122-
if (propertyMapElement.Value != null)
123-
{
124-
mapNode.Context.StartObject(propertyMapElement.Key);
125-
126-
var any = anyMapFieldMap[anyMapFieldName].PropertyGetter(propertyMapElement.Value);
127-
128-
var newAny = OpenApiAnyConverter.GetSpecificOpenApiAny(
129-
any,
130-
anyMapFieldMap[anyMapFieldName].SchemaGetter(domainObject));
131-
132-
anyMapFieldMap[anyMapFieldName].PropertySetter(propertyMapElement.Value, newAny);
133-
}
134-
}
135-
}
136-
catch (OpenApiException exception)
137-
{
138-
exception.Pointer = mapNode.Context.GetLocation();
139-
mapNode.Context.Diagnostic.Errors.Add(new OpenApiError(exception));
140-
}
141-
finally
142-
{
143-
mapNode.Context.EndObject();
144-
}
145-
}
146-
}
147-
148110
public static IOpenApiAny LoadAny(ParseNode node)
149111
{
150112
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());

src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Company>Microsoft</Company>
1212
<Title>Microsoft.OpenApi</Title>
1313
<PackageId>Microsoft.OpenApi</PackageId>
14-
<Version>1.6.6</Version>
14+
<Version>1.6.7</Version>
1515
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
1616
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1717
<PackageTags>OpenAPI .NET</PackageTags>

src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private void ResolveTags(IList<OpenApiTag> tags)
256256

257257
private T ResolveReference<T>(OpenApiReference reference) where T : class, IOpenApiReferenceable, new()
258258
{
259-
if (string.IsNullOrEmpty(reference.ExternalResource))
259+
if (string.IsNullOrEmpty(reference?.ExternalResource))
260260
{
261261
try
262262
{

test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
<PrivateAssets>all</PrivateAssets>
1515
</PackageReference>
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
17-
<PackageReference Include="Moq" Version="4.18.4" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
17+
<PackageReference Include="Moq" Version="4.20.69" />
1818
<PackageReference Include="xunit" Version="2.5.0" />
1919
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
2020
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>net7.0</TargetFrameworks>
44
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
@@ -51,10 +51,14 @@
5151
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithBody.yaml">
5252
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
5353
</EmbeddedResource>
54+
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithBodyAndEmptyConsumes.yaml">
55+
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
56+
</EmbeddedResource>
5457
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithFormData.yaml">
5558
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
5659
</EmbeddedResource>
5760
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithResponseExamples.yaml" />
61+
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithEmptyProducesArrayInResponse.json" />
5862
<EmbeddedResource Include="V2Tests\Samples\OpenApiParameter\bodyParameter.yaml">
5963
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
6064
</EmbeddedResource>
@@ -268,8 +272,8 @@
268272
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
269273
<PrivateAssets>all</PrivateAssets>
270274
</PackageReference>
271-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
272-
<PackageReference Include="FluentAssertions" Version="6.11.0">
275+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
276+
<PackageReference Include="FluentAssertions" Version="6.12.0">
273277
</PackageReference>
274278
<PackageReference Include="Newtonsoft.Json" Version="13.0.3">
275279
</PackageReference>

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs

+26-46
Original file line numberDiff line numberDiff line change
@@ -163,45 +163,25 @@ public void ShouldParseProducesInAnyOrder()
163163
var reader = new OpenApiStreamReader();
164164
var doc = reader.Read(stream, out var diagnostic);
165165

166-
var successSchema = new OpenApiSchema()
166+
var okSchema = new OpenApiSchema()
167167
{
168-
Type = "array",
169168
Reference = new OpenApiReference
170169
{
171170
Type = ReferenceType.Schema,
172171
Id = "Item",
173172
HostDocument = doc
174173
},
175-
Items = new OpenApiSchema()
174+
Properties = new Dictionary<string, OpenApiSchema>()
176175
{
177-
Reference = new OpenApiReference()
178-
{
179-
Type = ReferenceType.Schema,
180-
Id = "Item",
181-
HostDocument = doc
176+
{ "id", new OpenApiSchema()
177+
{
178+
Type = "string",
179+
Description = "Item identifier."
180+
}
182181
}
183182
}
184183
};
185184

186-
var okSchema = new OpenApiSchema()
187-
{
188-
Reference = new OpenApiReference
189-
{
190-
Type = ReferenceType.Schema,
191-
Id = "Item",
192-
HostDocument = doc
193-
},
194-
Properties = new Dictionary<string, OpenApiSchema>()
195-
{
196-
{ "id", new OpenApiSchema()
197-
{
198-
Type = "string",
199-
Description = "Item identifier."
200-
}
201-
}
202-
}
203-
};
204-
205185
var errorSchema = new OpenApiSchema()
206186
{
207187
Reference = new OpenApiReference
@@ -211,24 +191,24 @@ public void ShouldParseProducesInAnyOrder()
211191
HostDocument = doc
212192
},
213193
Properties = new Dictionary<string, OpenApiSchema>()
214-
{
215-
{ "code", new OpenApiSchema()
216-
{
217-
Type = "integer",
218-
Format = "int32"
219-
}
220-
},
221-
{ "message", new OpenApiSchema()
222-
{
223-
Type = "string"
224-
}
225-
},
226-
{ "fields", new OpenApiSchema()
227-
{
228-
Type = "string"
229-
}
230-
}
231-
}
194+
{
195+
{ "code", new OpenApiSchema()
196+
{
197+
Type = "integer",
198+
Format = "int32"
199+
}
200+
},
201+
{ "message", new OpenApiSchema()
202+
{
203+
Type = "string"
204+
}
205+
},
206+
{ "fields", new OpenApiSchema()
207+
{
208+
Type = "string"
209+
}
210+
}
211+
}
232212
};
233213

234214
var okMediaType = new OpenApiMediaType
@@ -439,7 +419,7 @@ public void ShouldAllowComponentsThatJustContainAReference()
439419
if (schema2.UnresolvedReference && schema1.Reference.Id == schema2.Reference.Id)
440420
{
441421
// detected a cycle - this code gets triggered
442-
Assert.True(false, "A cycle should not be detected");
422+
Assert.Fail("A cycle should not be detected");
443423
}
444424
}
445425
}

0 commit comments

Comments
 (0)