Skip to content

Commit

Permalink
Merge pull request #1324 from microsoft/vnext
Browse files Browse the repository at this point in the history
Release libs
  • Loading branch information
baywet authored Aug 31, 2023
2 parents 137a456 + c022557 commit 97c5364
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 138 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ jobs:
name: Build
runs-on: windows-latest
steps:
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: 11
java-version: 17
- name: Setup .NET 5 # At the moment the scanner requires dotnet 5 https://www.nuget.org/packages/dotnet-sonarscanner
uses: actions/setup-dotnet@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.2.6</Version>
<Version>1.2.7</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
<PackageProjectUrl>https://github.com/Microsoft/OpenAPI.NET</PackageProjectUrl>
Expand All @@ -10,7 +11,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi.Readers</Title>
<PackageId>Microsoft.OpenApi.Readers</PackageId>
<Version>1.6.6</Version>
<Version>1.6.7</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
42 changes: 21 additions & 21 deletions src/Microsoft.OpenApi.Readers/V2/OpenApiResponseDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,35 @@ private static void ProcessProduces(MapNode mapNode, OpenApiResponse response, P
}

var produces = context.GetFromTempStorage<List<string>>(TempStorageKeys.OperationProduces)
?? context.GetFromTempStorage<List<string>>(TempStorageKeys.GlobalProduces);
if (produces != null)
?? context.GetFromTempStorage<List<string>>(TempStorageKeys.GlobalProduces)
?? new List<string> { "application/octet-stream" };

var schema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema, response);

foreach (var produce in produces)
{
foreach (var produce in produces)
{
var schema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema, response);

if (response.Content.ContainsKey(produce) && response.Content[produce] != null)
if (response.Content.TryGetValue(produce, out var produceValue))
{
if (schema != null)
{
if (schema != null)
{
response.Content[produce].Schema = schema;
ProcessAnyFields(mapNode, response.Content[produce], _mediaTypeAnyFields);
}
produceValue.Schema = schema;
ProcessAnyFields(mapNode, produceValue, _mediaTypeAnyFields);
}
else
}
else
{
var mediaType = new OpenApiMediaType
{
var mediaType = new OpenApiMediaType
{
Schema = schema
};
Schema = schema
};

response.Content.Add(produce, mediaType);
}
response.Content.Add(produce, mediaType);
}

context.SetTempStorage(TempStorageKeys.ResponseSchema, null, response);
context.SetTempStorage(TempStorageKeys.ResponseProducesSet, true, response);
}

context.SetTempStorage(TempStorageKeys.ResponseSchema, null, response);
context.SetTempStorage(TempStorageKeys.ResponseProducesSet, true, response);
}

private static void LoadExamples(OpenApiResponse response, ParseNode node)
Expand Down
68 changes: 15 additions & 53 deletions src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.Collections.Generic;
Expand Down Expand Up @@ -29,10 +29,11 @@ private static void ParseMap<T>(
return;
}

foreach (var propertyNode in mapNode)
var allFields = fixedFieldMap.Keys.Union(mapNode.Select(static x => x.Name));
foreach (var propertyNode in allFields)
{
propertyNode.ParseField(domainObject, fixedFieldMap, patternFieldMap);
requiredFields?.Remove(propertyNode.Name);
mapNode[propertyNode]?.ParseField(domainObject, fixedFieldMap, patternFieldMap);
requiredFields?.Remove(propertyNode);
}
}

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

mapNode.Context.StartObject(anyListFieldName);

var list = anyListFieldMap[anyListFieldName].PropertyGetter(domainObject);
if (list != null)
if (anyListFieldMap.TryGetValue(anyListFieldName, out var fieldName))
{
foreach (var propertyElement in list)
var list = fieldName.PropertyGetter(domainObject);
if (list != null)
{
newProperty.Add(
OpenApiAnyConverter.GetSpecificOpenApiAny(
propertyElement,
anyListFieldMap[anyListFieldName].SchemaGetter(domainObject)));
foreach (var propertyElement in list)
{
newProperty.Add(
OpenApiAnyConverter.GetSpecificOpenApiAny(
propertyElement,
anyListFieldMap[anyListFieldName].SchemaGetter(domainObject)));
}
}
}

Expand All @@ -104,47 +107,6 @@ private static void ProcessAnyListFields<T>(
}
}

private static void ProcessAnyMapFields<T, U>(
MapNode mapNode,
T domainObject,
AnyMapFieldMap<T, U> anyMapFieldMap)
{
foreach (var anyMapFieldName in anyMapFieldMap.Keys.ToList())
{
try
{
var newProperty = new List<IOpenApiAny>();

mapNode.Context.StartObject(anyMapFieldName);

foreach (var propertyMapElement in anyMapFieldMap[anyMapFieldName].PropertyMapGetter(domainObject))
{
if (propertyMapElement.Value != null)
{
mapNode.Context.StartObject(propertyMapElement.Key);

var any = anyMapFieldMap[anyMapFieldName].PropertyGetter(propertyMapElement.Value);

var newAny = OpenApiAnyConverter.GetSpecificOpenApiAny(
any,
anyMapFieldMap[anyMapFieldName].SchemaGetter(domainObject));

anyMapFieldMap[anyMapFieldName].PropertySetter(propertyMapElement.Value, newAny);
}
}
}
catch (OpenApiException exception)
{
exception.Pointer = mapNode.Context.GetLocation();
mapNode.Context.Diagnostic.Errors.Add(new OpenApiError(exception));
}
finally
{
mapNode.Context.EndObject();
}
}
}

public static IOpenApiAny LoadAny(ParseNode node)
{
return OpenApiAnyConverter.GetSpecificOpenApiAny(node.CreateAny());
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi</Title>
<PackageId>Microsoft.OpenApi</PackageId>
<Version>1.6.6</Version>
<Version>1.6.7</Version>
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void ResolveTags(IList<OpenApiTag> tags)

private T ResolveReference<T>(OpenApiReference reference) where T : class, IOpenApiReferenceable, new()
{
if (string.IsNullOrEmpty(reference.ExternalResource))
if (string.IsNullOrEmpty(reference?.ExternalResource))
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
Expand Down Expand Up @@ -51,10 +51,14 @@
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithBody.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithBodyAndEmptyConsumes.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithFormData.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithResponseExamples.yaml" />
<EmbeddedResource Include="V2Tests\Samples\OpenApiOperation\operationWithEmptyProducesArrayInResponse.json" />
<EmbeddedResource Include="V2Tests\Samples\OpenApiParameter\bodyParameter.yaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
Expand Down Expand Up @@ -268,8 +272,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="FluentAssertions" Version="6.11.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="FluentAssertions" Version="6.12.0">
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3">
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,45 +163,25 @@ public void ShouldParseProducesInAnyOrder()
var reader = new OpenApiStreamReader();
var doc = reader.Read(stream, out var diagnostic);

var successSchema = new OpenApiSchema()
var okSchema = new OpenApiSchema()
{
Type = "array",
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = "Item",
HostDocument = doc
},
Items = new OpenApiSchema()
Properties = new Dictionary<string, OpenApiSchema>()
{
Reference = new OpenApiReference()
{
Type = ReferenceType.Schema,
Id = "Item",
HostDocument = doc
{ "id", new OpenApiSchema()
{
Type = "string",
Description = "Item identifier."
}
}
}
};

var okSchema = new OpenApiSchema()
{
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = "Item",
HostDocument = doc
},
Properties = new Dictionary<string, OpenApiSchema>()
{
{ "id", new OpenApiSchema()
{
Type = "string",
Description = "Item identifier."
}
}
}
};

var errorSchema = new OpenApiSchema()
{
Reference = new OpenApiReference
Expand All @@ -211,24 +191,24 @@ public void ShouldParseProducesInAnyOrder()
HostDocument = doc
},
Properties = new Dictionary<string, OpenApiSchema>()
{
{ "code", new OpenApiSchema()
{
Type = "integer",
Format = "int32"
}
},
{ "message", new OpenApiSchema()
{
Type = "string"
}
},
{ "fields", new OpenApiSchema()
{
Type = "string"
}
}
}
{
{ "code", new OpenApiSchema()
{
Type = "integer",
Format = "int32"
}
},
{ "message", new OpenApiSchema()
{
Type = "string"
}
},
{ "fields", new OpenApiSchema()
{
Type = "string"
}
}
}
};

var okMediaType = new OpenApiMediaType
Expand Down Expand Up @@ -439,7 +419,7 @@ public void ShouldAllowComponentsThatJustContainAReference()
if (schema2.UnresolvedReference && schema1.Reference.Id == schema2.Reference.Id)
{
// detected a cycle - this code gets triggered
Assert.True(false, "A cycle should not be detected");
Assert.Fail("A cycle should not be detected");
}
}
}
Expand Down
Loading

0 comments on commit 97c5364

Please sign in to comment.