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

Release libs v1.4.0-preview3 #997

Merged
merged 59 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
254b70f
Add logic to check whether the properties of anyOf/oneOf/allOf match…
MaggieKimani1 Jul 21, 2022
96cfc45
Add test case
MaggieKimani1 Jul 21, 2022
2b34d2d
Update public Api
MaggieKimani1 Jul 21, 2022
6af10c2
Remove whitespace
MaggieKimani1 Jul 21, 2022
5fd6039
Update the validation process to be recursive
MaggieKimani1 Aug 2, 2022
2707493
Code cleanup
MaggieKimani1 Aug 2, 2022
13fa9e8
Update public API interface
MaggieKimani1 Aug 2, 2022
3682cea
Clean up code
MaggieKimani1 Aug 4, 2022
1b55a1d
Remove param
MaggieKimani1 Aug 4, 2022
50610be
Adds an issue template
MaggieKimani1 Aug 11, 2022
9cbac86
Adds a feature template
MaggieKimani1 Aug 11, 2022
aba7694
Edit bug template
MaggieKimani1 Aug 11, 2022
c2a23a0
Bump SharpYaml from 1.9.2 to 2.1.0
dependabot[bot] Aug 12, 2022
ffc7c1b
Remove unnecessary info
MaggieKimani1 Aug 13, 2022
aa503ff
Fix anyOf and oneOf serialization by checking for null first before w…
millicentachieng Aug 13, 2022
19d9edc
Remove unused method
millicentachieng Aug 14, 2022
e0b3061
Publish release notes and .exe before pushing to Nuget
MaggieKimani1 Aug 15, 2022
5938d42
Add a condition that triggers this task to run whether or not the pre…
MaggieKimani1 Aug 15, 2022
10a022a
Merge pull request #970 from microsoft/mk/enhancement-add-issue-and-f…
MaggieKimani1 Aug 15, 2022
1e42e51
Merge pull request #976 from microsoft/dependabot/nuget/SharpYaml-2.1.0
MaggieKimani1 Aug 15, 2022
c902bfc
Merge pull request #980 from microsoft/mk/fix-missing-release-notes
MaggieKimani1 Aug 15, 2022
3b260ad
Bump Verify.Xunit from 17.9.0 to 17.10.0
dependabot[bot] Aug 15, 2022
06b608c
Merge pull request #981 from microsoft/dependabot/nuget/Verify.Xunit-…
baywet Aug 15, 2022
c43f024
Merge pull request #978 from microsoft/ma/fix-anyOf-oneOf-v2-serializ…
millicentachieng Aug 15, 2022
529400d
Bump Verify.Xunit from 17.10.0 to 17.10.2
dependabot[bot] Aug 16, 2022
a9e91fe
Merge pull request #951 from microsoft/mk/fix-parent-schema-discrimin…
darrelmiller Aug 17, 2022
c1b173e
Merge pull request #984 from microsoft/dependabot/nuget/Verify.Xunit-…
darrelmiller Aug 17, 2022
0636e4a
Add a hashCode field to the diagnostics object to keep track of the h…
MaggieKimani1 Aug 17, 2022
500f0c7
Override the base GetHashCode() to compute the hash value for an Open…
MaggieKimani1 Aug 17, 2022
7a58221
Simplify using statement, add tests, test file and cleanup
MaggieKimani1 Aug 17, 2022
f9a32fa
Refactor failing tests
MaggieKimani1 Aug 17, 2022
9c0fa21
Merge branch 'vnext' into mk/enhancement-create-hash-code
MaggieKimani1 Aug 19, 2022
c7e3ed8
Compute hash value using hashing algorithm during serialization
MaggieKimani1 Aug 22, 2022
8d20075
Clean up test
MaggieKimani1 Aug 22, 2022
a676e37
Code cleanup
MaggieKimani1 Aug 22, 2022
96f060b
Code cleanup
MaggieKimani1 Aug 22, 2022
9772ad0
Update public Api interface
MaggieKimani1 Aug 22, 2022
d50f857
Revert "Update public Api interface"
MaggieKimani1 Aug 22, 2022
df65299
Cater for file content transferred with base64 encoding
MaggieKimani1 Aug 24, 2022
9b8e16b
Add braces to the conditional statement
MaggieKimani1 Aug 24, 2022
8674fe3
Revert previous changes
MaggieKimani1 Aug 26, 2022
ba73777
Refactor hashing logic and add test cases
MaggieKimani1 Aug 26, 2022
2bb383c
Update public API interface
MaggieKimani1 Aug 26, 2022
feebffc
Remove framework display name from interface
MaggieKimani1 Aug 26, 2022
2539576
Address PR feedback
MaggieKimani1 Aug 26, 2022
fb6ea09
Merge pull request #985 from microsoft/mk/enhancement-create-hash-code
MaggieKimani1 Aug 26, 2022
6d7f735
Update string comparison logic
MaggieKimani1 Aug 29, 2022
5c6d17f
Attach changelog labels for improved release notes experience
MaggieKimani1 Aug 29, 2022
39a2cc8
Merge pull request #987 from microsoft/mk/fix-multipart-formdata-issue
MaggieKimani1 Aug 29, 2022
5d69c0f
Merge pull request #988 from microsoft/mk/improve-release-notes
MaggieKimani1 Aug 29, 2022
f0a3fde
Bump Microsoft.NET.Test.Sdk from 17.3.0 to 17.3.1
dependabot[bot] Aug 30, 2022
9c296e1
Merge pull request #991 from microsoft/dependabot/nuget/Microsoft.NET…
baywet Aug 30, 2022
4ecd027
Add child schema format to parent schema when serializing as V2
MaggieKimani1 Sep 1, 2022
00fe8db
Retrieve Format property
irvinesunday Sep 1, 2022
348e8cf
Merge remote-tracking branch 'origin/is/patch-fix' into mk/remove-roo…
MaggieKimani1 Sep 1, 2022
0818fb7
Clean up code
MaggieKimani1 Sep 1, 2022
86c585a
Merge pull request #994 from microsoft/mk/remove-root-format-property-V3
MaggieKimani1 Sep 2, 2022
8cec362
Bump lib versions
MaggieKimani1 Sep 2, 2022
cf77bb7
Merge pull request #996 from microsoft/mk/bump-lib-versions
MaggieKimani1 Sep 2, 2022
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
8 changes: 7 additions & 1 deletion .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ stages:
echo "$artifactName"
echo "$artifactVersion"
displayName: 'Fetch Artifact Name'

- task: NuGetCommand@2
displayName: 'NuGet push'
inputs:
Expand All @@ -276,6 +275,7 @@ stages:
publishFeedCredentials: 'OpenAPI Nuget Connection'
- task: GitHubRelease@1
displayName: 'GitHub release (edit)'
condition: succeededOrFailed()
inputs:
gitHubConnection: 'Github-MaggieKimani1'
action: edit
Expand All @@ -285,6 +285,12 @@ stages:
releaseNotesSource: inline
assets: '$(Pipeline.Workspace)\**\*.exe'
changeLogType: issueBased
changeLogLabels: '[
{ "label" : "feature-work", "feature", "displayName" : "New Features", "state" : "closed" },
{ "label" : "enhancement", "V2-Enhancement", "displayName" : "Enhancements", "state" : "closed" },
{ "label" : "bug", "bug-fix", "displayName" : "Bugs", "state" : "closed" },
{ "label" : "documentation", "doc", "displayName" : "Documentation", "state" : "closed"},
{ "label" : "dependencies", "displayName" : "Package Updates", "state" : "closed" }]'

- deployment: deploy_lib
dependsOn: []
Expand Down
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the current behavior:

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots/Code Snippets**
If applicable, add screenshots of the stack trace or a code snippet to help explain your problem.
If applicable, add a link to your project

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand Down
80 changes: 1 addition & 79 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,57 +356,7 @@ public static OpenApiDocument FixReferences(OpenApiDocument document)

return doc;
}

private static async Task<Stream> GetStream(string input, ILogger logger)
{
var stopwatch = new Stopwatch();
stopwatch.Start();

Stream stream;
if (input.StartsWith("http"))
{
try
{
var httpClientHandler = new HttpClientHandler()
{
SslProtocols = System.Security.Authentication.SslProtocols.Tls12,
};
using var httpClient = new HttpClient(httpClientHandler)
{
DefaultRequestVersion = HttpVersion.Version20
};
stream = await httpClient.GetStreamAsync(input);
}
catch (HttpRequestException ex)
{
logger.LogError($"Could not download the file at {input}, reason{ex}");
return null;
}
}
else
{
try
{
var fileInput = new FileInfo(input);
stream = fileInput.OpenRead();
}
catch (Exception ex) when (ex is FileNotFoundException ||
ex is PathTooLongException ||
ex is DirectoryNotFoundException ||
ex is IOException ||
ex is UnauthorizedAccessException ||
ex is SecurityException ||
ex is NotSupportedException)
{
logger.LogError($"Could not open the file at {input}, reason: {ex.Message}");
return null;
}
}
stopwatch.Stop();
logger.LogTrace("{timestamp}ms: Read file {input}", stopwatch.ElapsedMilliseconds, input);
return stream;
}


/// <summary>
/// Takes in a file stream, parses the stream into a JsonDocument and gets a list of paths and Http methods
/// </summary>
Expand Down Expand Up @@ -462,34 +412,6 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
return paths;
}

/// <summary>
/// Fixes the references in the resulting OpenApiDocument.
/// </summary>
/// <param name="document"> The converted OpenApiDocument.</param>
/// <returns> A valid OpenApiDocument instance.</returns>
// private static OpenApiDocument FixReferences2(OpenApiDocument document)
// {
// // This method is only needed because the output of ConvertToOpenApi isn't quite a valid OpenApiDocument instance.
// // So we write it out, and read it back in again to fix it up.

// OpenApiDocument document;
// logger.LogTrace("Parsing the OpenApi file");
// var result = await new OpenApiStreamReader(new OpenApiReaderSettings
// {
// RuleSet = ValidationRuleSet.GetDefaultRuleSet(),
// BaseUrl = new Uri(openapi)
// }
// ).ReadAsync(stream);

// document = result.OpenApiDocument;
// var context = result.OpenApiDiagnostic;
// var sb = new StringBuilder();
// document.SerializeAsV3(new OpenApiYamlWriter(new StringWriter(sb)));
// var doc = new OpenApiStringReader().Read(sb.ToString(), out _);

// return doc;
// }

/// <summary>
/// Reads stream from file system or makes HTTP request depending on the input string
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SharpYaml" Version="1.9.2" />
<PackageReference Include="SharpYaml" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public OpenApiDocument Read(YamlDocument input, out OpenApiDiagnostic diagnostic
{
diagnostic.Warnings.Add(item);
}

}

return document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal static partial class OpenApiV2Deserializer
"consumes", (o, n) => {
var consumes = n.CreateSimpleList(s => s.GetScalarValue());
if (consumes.Count > 0) {
n.Context.SetTempStorage(TempStorageKeys.OperationConsumes,consumes);
n.Context.SetTempStorage(TempStorageKeys.OperationConsumes,consumes);
}
}
},
Expand Down
24 changes: 0 additions & 24 deletions src/Microsoft.OpenApi.Readers/V2/OpenApiV2VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,6 @@ private static ReferenceType ParseReferenceType(string referenceTypeName)
}
}

private static string GetReferenceTypeV2Name(ReferenceType referenceType)
{
switch (referenceType)
{
case ReferenceType.Schema:
return "definitions";

case ReferenceType.Parameter:
return "parameters";

case ReferenceType.Response:
return "responses";

case ReferenceType.Tag:
return "tags";

case ReferenceType.SecurityScheme:
return "securityDefinitions";

default:
throw new ArgumentException();
}
}

private static ReferenceType GetReferenceTypeV2FromName(string referenceType)
{
switch (referenceType)
Expand Down
44 changes: 43 additions & 1 deletion src/Microsoft.OpenApi/Models/OpenApiDocument.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Services;
Expand Down Expand Up @@ -62,6 +65,11 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
/// </summary>
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();

/// <summary>
/// The unique hash code of the generated OpenAPI document
/// </summary>
public string HashCode => GenerateHashValue(this);

/// <summary>
/// Parameter-less constructor
/// </summary>
Expand Down Expand Up @@ -375,6 +383,40 @@ public IOpenApiReferenceable ResolveReference(OpenApiReference reference)
return ResolveReference(reference, false);
}

/// <summary>
/// Takes in an OpenApi document instance and generates its hash value
/// </summary>
/// <param name="doc">The OpenAPI description to hash.</param>
/// <returns>The hash value.</returns>
public static string GenerateHashValue(OpenApiDocument doc)
{
using HashAlgorithm sha = SHA512.Create();
using var cryptoStream = new CryptoStream(Stream.Null, sha, CryptoStreamMode.Write);
using var streamWriter = new StreamWriter(cryptoStream);

var openApiJsonWriter = new OpenApiJsonWriter(streamWriter, new OpenApiJsonWriterSettings { Terse = true });
doc.SerializeAsV3(openApiJsonWriter);
openApiJsonWriter.Flush();

cryptoStream.FlushFinalBlock();
var hash = sha.Hash;

return ConvertByteArrayToString(hash);
}

private static string ConvertByteArrayToString(byte[] hash)
{
// Build the final string by converting each byte
// into hex and appending it to a StringBuilder
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}

return sb.ToString();
}

/// <summary>
/// Load the referenced <see cref="IOpenApiReferenceable"/> object from a <see cref="OpenApiReference"/> object
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,11 @@ public void SerializeAsV2(IOpenApiWriter writer)
{
foreach (var property in RequestBody.Content.First().Value.Schema.Properties)
{
var paramName = property.Key;
var paramSchema = property.Value;
if (paramSchema.Type == "string" && paramSchema.Format == "binary") {
if ("string".Equals(paramSchema.Type, StringComparison.OrdinalIgnoreCase)
&& ("binary".Equals(paramSchema.Format, StringComparison.OrdinalIgnoreCase)
|| "base64".Equals(paramSchema.Format, StringComparison.OrdinalIgnoreCase)))
{
paramSchema.Type = "file";
paramSchema.Format = null;
}
Expand Down
12 changes: 8 additions & 4 deletions src/Microsoft.OpenApi/Models/OpenApiSchema.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 @@ -630,6 +630,10 @@ internal void WriteAsSchemaProperties(
}

// format
Format ??= AllOf?.FirstOrDefault(static x => x.Format != null)?.Format ??
AnyOf?.FirstOrDefault(static x => x.Format != null)?.Format ??
OneOf?.FirstOrDefault(static x => x.Format != null)?.Format;

writer.WriteProperty(OpenApiConstants.Format, Format);

// title
Expand Down Expand Up @@ -695,17 +699,17 @@ internal void WriteAsSchemaProperties(
// allOf
writer.WriteOptionalCollection(OpenApiConstants.AllOf, AllOf, (w, s) => s.SerializeAsV2(w));

// If there isn't already an AllOf, and the schema contains a oneOf or anyOf write an allOf with the first
// If there isn't already an allOf, and the schema contains a oneOf or anyOf write an allOf with the first
// schema in the list as an attempt to guess at a graceful downgrade situation.
if (AllOf == null || AllOf.Count == 0)
{
// anyOf (Not Supported in V2) - Write the first schema only as an allOf.
writer.WriteOptionalCollection(OpenApiConstants.AllOf, AnyOf.Take(1), (w, s) => s.SerializeAsV2(w));
writer.WriteOptionalCollection(OpenApiConstants.AllOf, AnyOf?.Take(1), (w, s) => s.SerializeAsV2(w));

if (AnyOf == null || AnyOf.Count == 0)
{
// oneOf (Not Supported in V2) - Write the first schema only as an allOf.
writer.WriteOptionalCollection(OpenApiConstants.AllOf, OneOf.Take(1), (w, s) => s.SerializeAsV2(w));
writer.WriteOptionalCollection(OpenApiConstants.AllOf, OneOf?.Take(1), (w, s) => s.SerializeAsV2(w));
}
}

Expand Down
Loading