Closed
Description
Describe the bug
When dotnet-openapi is used to refresh a swagger.json document, if the new document is shorter than the old document, the file is not truncated to the new size leaving invalid trailing bytes that render it un-parsable, causing build errors.
To Reproduce
- Create a new webapi project and add 2 [HttpXXX] methods to the controller.
- Run
dotnet-openapi add url https://localhost:5001/swagger/v1/swagger.json --output-file MyApi.json
from a terminal. - Rebuild to verify the MyApiClient is accessible and works.
- Remove a method from the controller and rebuild and rerun.
- Run
dotnet-openapi refresh https://localhost:5001/swagger/v1/swagger.json
- Verify that the MyApi.json file retains its original file and has garbage data trailing the new, shorter, swagger definition.
Further technical details
user@mac % dotnet tool list --global
Package Id Version Commands
-------------------------------------------------------------------------
dotnet-aspnet-codegenerator 2.2.3 dotnet-aspnet-codegenerator
dotnet-ef 5.0.9 dotnet-ef
dotnet-svcutil 2.0.2 dotnet-svcutil
microsoft.dotnet-openapi 5.0.9 dotnet-openapi