Skip to content

dotnet-openapi refresh does not truncate json documents. #35767

Closed
@chrisbecke

Description

@chrisbecke

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

  1. Create a new webapi project and add 2 [HttpXXX] methods to the controller.
  2. Run dotnet-openapi add url https://localhost:5001/swagger/v1/swagger.json --output-file MyApi.json from a terminal.
  3. Rebuild to verify the MyApiClient is accessible and works.
  4. Remove a method from the controller and rebuild and rerun.
  5. Run dotnet-openapi refresh https://localhost:5001/swagger/v1/swagger.json
  6. 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             

Metadata

Metadata

Assignees

Labels

Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.feature-openapiold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions