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

Update docs with deails about --no-deprecated-operations #155

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .github/workflows/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:
"--use-iso-date-format",
"--multiple-interfaces ByEndpoint",
"--match-path ^/pet/.*",
"--tag pet"
"--tag pet",
"--no-deprecated-operations"
]

steps:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ EXAMPLES:
refitter ./openapi.json --multiple-interfaces ByEndpoint
refitter ./openapi.json --tag Pet --tag Store --tag User
refitter ./openapi.json --match-path '^/pet/.*'
refitter ./openapi.json --no-deprecated-operations

ARGUMENTS:
[URL or input file] URL or file path to OpenAPI Specification file
Expand All @@ -75,6 +76,7 @@ OPTIONS:
--match-path Only include Paths that match the provided regular expression. May be set multiple times
--tag Only include Endpoints that contain this tag. May be set multiple times and result in OR'ed evaluation
--skip-validation Skip validation of the OpenAPI specification
--no-deprecated-operations Don't generate deprecated operations
```

To generate code from an OpenAPI specifications file, run the following:
Expand Down
105 changes: 105 additions & 0 deletions src/Refitter.Tests/Examples/DeprecatedEndpointTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using FluentAssertions;

using Refitter.Core;
using Refitter.Tests.Build;

using Xunit;

namespace Refitter.Tests.Examples;

public class DeprecatedEndpointTests
{
private const string OpenApiSpec = @"
openapi: '3.0.0'
paths:
/foo/{id}:
get:
tags:
- 'Foo'
operationId: 'Get foo details'
description: 'Get the details of the specified foo'
parameters:
- in: 'path'
name: 'id'
description: 'Foo ID'
required: true
schema:
type: 'string'
responses:
'200':
description: 'successful operation'
/foo:
get:
tags:
- 'Foo'
operationId: 'Get all foos'
description: 'Get all foos'
responses:
'200':
description: 'successful operation'
/bar:
get:
tags:
- 'Bar'
operationId: 'Get all bars'
description: 'Get all bars'
deprecated: true
responses:
'200':
description: 'successful operation'
/bar/{id}:
get:
tags:
- 'Bar'
operationId: 'Get bar details'
description: 'Get the details of the specified bar'
deprecated: true
responses:
'200':
description: 'successful operation'
";

[Fact]
public async Task Can_Generate_Code()
{
string generateCode = await GenerateCode();
generateCode.Should().NotBeNullOrWhiteSpace();
}

[Fact]
public async Task Should_Contain_Obsolete_Attribute()
{
string generateCode = await GenerateCode();
generateCode.Should().Contain("[System.Obsolete]");
}

[Fact]
public async Task Can_Build_Generated_Code()
{
string generateCode = await GenerateCode();
BuildHelper
.BuildCSharp(generateCode)
.Should()
.BeTrue();
}

private static async Task<string> GenerateCode()
{
var swaggerFile = await CreateSwaggerFile(OpenApiSpec);
var settings = new RefitGeneratorSettings { OpenApiPath = swaggerFile };

var sut = await RefitGenerator.CreateAsync(settings);
var generateCode = sut.Generate();
return generateCode;
}

private static async Task<string> CreateSwaggerFile(string contents)
{
var filename = $"{Guid.NewGuid()}.yml";
var folder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(folder);
var swaggerFile = Path.Combine(folder, filename);
await File.WriteAllTextAsync(swaggerFile, contents);
return swaggerFile;
}
}
123 changes: 123 additions & 0 deletions src/Refitter.Tests/Examples/DeprecatedEndpointsSkippedTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using FluentAssertions;

using Refitter.Core;
using Refitter.Tests.Build;

using Xunit;

namespace Refitter.Tests.Examples;

public class DeprecatedEndpointsSkippedTests
{
private const string OpenApiSpec = @"
openapi: '3.0.0'
paths:
/foo/{id}:
get:
tags:
- 'Foo'
operationId: 'Get foo details'
description: 'Get the details of the specified foo'
parameters:
- in: 'path'
name: 'id'
description: 'Foo ID'
required: true
schema:
type: 'string'
responses:
'200':
description: 'successful operation'
/foo:
get:
tags:
- 'Foo'
operationId: 'Get all foos'
description: 'Get all foos'
responses:
'200':
description: 'successful operation'
/bar:
get:
tags:
- 'Bar'
operationId: 'Get all bars'
description: 'Get all bars'
deprecated: true
responses:
'200':
description: 'successful operation'
/bar/{id}:
get:
tags:
- 'Bar'
operationId: 'Get bar details'
description: 'Get the details of the specified bar'
deprecated: true
responses:
'200':
description: 'successful operation'
";

[Fact]
public async Task Can_Generate_Code()
{
string generateCode = await GenerateCode();
generateCode.Should().NotBeNullOrWhiteSpace();
}

[Fact]
public async Task Should_NotContain_Obsolete_Attribute()
{
string generateCode = await GenerateCode();
generateCode.Should().NotContain("[System.Obsolete]");
}

[Fact]
public async Task Should_NotContain_GetAllBars()
{
string generateCode = await GenerateCode();
generateCode.Should().NotContain("GetAllBars");
}

[Fact]
public async Task Should_NotContain_GetBarDetails()
{
string generateCode = await GenerateCode();
generateCode.Should().NotContain("GetBarDetails");
}

[Fact]
public async Task Can_Build_Generated_Code()
{
string generateCode = await GenerateCode();
BuildHelper
.BuildCSharp(generateCode)
.Should()
.BeTrue();
}

private static async Task<string> GenerateCode()
{
var swaggerFile = await CreateSwaggerFile(OpenApiSpec);
var settings = new RefitGeneratorSettings
{
OpenApiPath = swaggerFile,
GenerateDeprecatedOperations = false
};

var sut = await RefitGenerator.CreateAsync(settings);
var generateCode = sut.Generate();
return generateCode;
}

private static async Task<string> CreateSwaggerFile(string contents)
{
var filename = $"{Guid.NewGuid()}.yml";
var folder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(folder);
var swaggerFile = Path.Combine(folder, filename);
await File.WriteAllTextAsync(swaggerFile, contents);
return swaggerFile;
}
}
2 changes: 1 addition & 1 deletion src/Refitter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ OPTIONS:
--match-path Only include Paths that match the provided regular expression. May be set multiple times
--tag Only include Endpoints that contain this tag. May be set multiple times and result in OR'ed evaluation
--skip-validation Skip validation of the OpenAPI specification
--no-deprecated-operations Don't generate deprecated operations
--no-deprecated-operations Don't generate deprecated operations
```

To generate code from an OpenAPI specifications file, run the following:
Expand Down