Skip to content

[Bug]: openapi.yml file being generated with corrupted values #2887

@timandella

Description

@timandella

Describe the bug

With the latest version of Swashbuckle, when running the command to generate the openapi file, the file can appear to be corrupted. It looks like it is not always clearing down lines fully, and the end of the old line still appears in the new line. For example, in one case, the yaml generated contained this line:

type: stringtring

And in another case. it contained this:

additionalProperties: falseoperties: false

The command being run to generate the openapi was as follows:

dotnet swagger tofile --output src/TestService/docs/openapi.yaml --yaml src\TestService\bin\Debug\net8.0\TestService.dll v1

If the openapi.yml file is deleted prior to generation, it is generated successfully without any corruption

Expected behavior

Give the following record:

public record TesterFeedResponse(Guid TenantId, TesterPlatform TesterPlatform, string FeedUrl, string? FeedName);

Where TesterPlatform is an enum, like so:

public enum TesterPlatform
{
    ThisTest = 0,
    ThatTest = 1,
}

The expected openapi.yml should could yaml like this:

TesterFeedResponse:
  type: object
  properties:
	tenantId:
	  type: string
	  format: uuid
	TesterPlatform:
	  $ref: '#/components/schemas/TesterPlatform'
	feedUrl:
	  type: string
	  nullable: true
	feedName:
	  type: string
	  nullable: true
  additionalProperties: false
TesterPlatform:
  enum:
	- ThisTest
	- ThatTest
  type: string

Actual behavior

The openapi generated looked like this

TesterFeedResponse:
  type: object
  properties:
	tenantId:
	  type: string
	  format: uuid
	TesterPlatform:
	  $ref: '#/components/schemas/TesterPlatform'
	feedUrl:
	  type: string
	  nullable: true
	feedName:
	  type: string
	  nullable: true
  additionalProperties: false
TesterPlatform:
  enum:
	- ThisTest
	- ThatTest
  type: stringble: true
  additionalProperties: false
TesterPlatform:
  enum:
	- ThisTest
	- ThatTest
  type: string

Steps to reproduce

A simpler way to reproduce would to be manually edit an existing openapi.yml file, and add some random text to the last line, then run the command.

For example, if the last line of the file is this:

type: string

Then change it to this:

type: this is a made up type

Then run the following command (paths adjusted accordingly)

dotnet swagger tofile --output src/TestService/docs/openapi.yaml --yaml src\TestService\bin\Debug\net8.0\TestService.dll v1

The last line then becomes this:

type: strings a made up type

Exception(s) (if any)

No exceptions occur (other than when the openapi.yml is actually used to generate an api client)

Swashbuckle.AspNetCore version

6.6.1

.NET Version

.net 8.0

Anything else?

This was working fine in 6.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions