-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Handle shortened JSON file in dotnet openapi
#36171
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
Conversation
dougbu
commented
Sep 4, 2021
- dotnet-openapi refresh does not truncate json documents. #35767
- an existing JSON file must be truncated
- #35767 - an existing JSON file must be truncated
@ryanbrandenburg are you available to check this out❔ @mkArtakMSFT please add a reviewer familiar with |
@mkArtakMSFT @bradygaster should we backport this to any of our servicing branches or release/6.0❔ If yes, which❔ |
PR needs a test for the #35767 scenario |
CancellationToken cancellationToken = default, | ||
int retryCount = 60) | ||
int retryCount = 60, | ||
CancellationToken cancellationToken = default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit odd. The method is only ever called w/ a single argument.
@@ -572,12 +557,13 @@ private async Task WriteToFileAsync(Stream content, string destinationPath, bool | |||
|
|||
// Create or overwrite the destination file. | |||
reachedCopy = true; | |||
using var fileStream = new FileStream(destinationPath, FileMode.OpenOrCreate, FileAccess.Write); | |||
using var fileStream = new FileStream(destinationPath, FileMode.Create, FileAccess.Write); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most important parts of the PR are this and changes in src/Tools/Microsoft.dotnet-openapi/test/OpenApiRefreshTests.cs
@@ -16,18 +12,18 @@ public class OpenApiAddFileTests : OpenApiTestBase | |||
{ | |||
public OpenApiAddFileTests(ITestOutputHelper output) : base(output) { } | |||
|
|||
[Fact(Skip = "https://github.com/dotnet/aspnetcore/issues/32686")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will close this issue if tests run smoothly on CI. They're fine in VS locally 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good news…
@mkArtakMSFT could you review or assign a reviewer please❔ @mkArtakMSFT @bradygaster should we backport this to any of our servicing branches or release/6.0❔ If yes, which❔ |
/fyi @captainsafia this PR definitely and successfully cleans up the last of #32686 😀 |
switch(StatusCode) | ||
return StatusCode switch | ||
{ | ||
case HttpStatusCode.OK: | ||
case HttpStatusCode.Created: | ||
case HttpStatusCode.NoContent: | ||
case HttpStatusCode.Accepted: | ||
return true; | ||
case HttpStatusCode.NotFound: | ||
default: | ||
return false; | ||
} | ||
HttpStatusCode.OK or HttpStatusCode.Created or HttpStatusCode.NoContent or HttpStatusCode.Accepted => true, | ||
_ => false, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I rarely remember how to write a switch
expression, they're certainly easy to read 😺
How far back would be far-enough back to start causing you headaches? I'd definitely support going back to support 3.1, but 5.0, not so sure if there'd be a strong-enough case. |
var json = await File.ReadAllTextAsync(expectedJsonPath); | ||
json += "trash"; | ||
await File.WriteAllTextAsync(expectedJsonPath, json); | ||
await File.WriteAllTextAsync(expectedJsonPath, "trash"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean it is safe to override the contents of expectedJsonPath
instead of appending?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file is only read to check its SHA in this test. Put another way, the intent is to demonstrate downloading a longer JSON file than the original. New tests demonstrate identical and shorter downloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(The dotnet openapi
tool does not itself parse OpenAPI files. That comes later, when the changed project is built.)
The main differences between branches appear to be slight improvements in syntax and test code. I suspect the only trip-ups will be forced returns to older C# syntax. Note: I would I also recommend we take this to release/5.0 and release/6.0 if we decide to update release/3.1. |
Adding @rafikiassumanimsft and removing @mkArtakMSFT given ownership |
default: | ||
return false; | ||
} | ||
HttpStatusCode.OK or HttpStatusCode.Created or HttpStatusCode.NoContent or HttpStatusCode.Accepted => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You get 100 @pranavkm points
Thanks all❕ |
/backport to release/6.0 |
Started backporting to release/6.0: https://github.com/dotnet/aspnetcore/actions/runs/1219400869 |