-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from christianhelle/fix-support-for-spaces-in-…
…operationid Fix support for spaces in operationid
- Loading branch information
Showing
13 changed files
with
303 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dotnet.defaultSolution": "src\\Refitter.sln" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#if !DEBUG | ||
using FluentAssertions; | ||
using Refitter.Core; | ||
using Refitter.Tests.Build; | ||
using Xunit; | ||
|
||
namespace Refitter.Tests.Examples; | ||
|
||
public class OpenApiUrlTests | ||
{ | ||
[Theory] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/api-with-examples.json")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/callback-example.json")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/link-example.json")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/petstore-expanded.json")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/uspto.json")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/hubspot-events.json")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/hubspot-webhooks.json")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/ingram-micro.json")] | ||
public async Task Can_Build_Generated_Code_From_OpenApi_v3_Url_Json(string url) | ||
{ | ||
var settings = new RefitGeneratorSettings { OpenApiPath = url }; | ||
var sut = await RefitGenerator.CreateAsync(settings); | ||
var generateCode = sut.Generate(); | ||
BuildHelper | ||
.BuildCSharp(generateCode) | ||
.Should() | ||
.BeTrue(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/api-with-examples.yaml")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/callback-example.yaml")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/link-example.yaml")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/petstore-expanded.yaml")] | ||
[InlineData("https://raw.githubusercontent.com/christianhelle/refitter/main/test/OpenAPI/v3.0/uspto.yaml")] | ||
public async Task Can_Build_Generated_Code_From_OpenApi_v3_Url_Yaml(string url) | ||
{ | ||
var settings = new RefitGeneratorSettings { OpenApiPath = url }; | ||
var sut = await RefitGenerator.CreateAsync(settings); | ||
var generateCode = sut.Generate(); | ||
BuildHelper | ||
.BuildCSharp(generateCode) | ||
.Should() | ||
.BeTrue(); | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using FluentAssertions; | ||
using Refitter.Core; | ||
using Refitter.Tests.Build; | ||
using Xunit; | ||
|
||
namespace Refitter.Tests.Examples; | ||
|
||
public class OperationIdWithSpacesTests | ||
{ | ||
private const string OpenApiSpec = @" | ||
openapi: '3.0.0' | ||
paths: | ||
/jobs/{job-id}: | ||
get: | ||
tags: | ||
- 'Jobs' | ||
operationId: 'Get job details' | ||
description: 'Get the details of the specified job.' | ||
parameters: | ||
- in: 'path' | ||
name: 'job-id' | ||
description: 'Job ID' | ||
required: true | ||
schema: | ||
type: 'string' | ||
responses: | ||
'200': | ||
description: 'successful operation' | ||
"; | ||
|
||
[Fact] | ||
public async Task Can_Generate_Code() | ||
{ | ||
string generateCode = await GenerateCode(); | ||
generateCode.Should().NotBeNullOrWhiteSpace(); | ||
} | ||
|
||
[Fact] | ||
public async Task Replaces_KababCase_Parameters_With_PascalCase() | ||
{ | ||
string generateCode = await GenerateCode(); | ||
generateCode.Should().Contain("string job_id"); | ||
} | ||
|
||
[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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using FluentAssertions; | ||
using Refitter.Core; | ||
using Refitter.Tests.Build; | ||
using Xunit; | ||
|
||
namespace Refitter.Tests.Examples; | ||
|
||
public class PoorOperationIdsTests | ||
{ | ||
private const string OpenApiSpec = @" | ||
{ | ||
""openapi"" : ""3.0.1"", | ||
""paths"" : { | ||
""/api/v1/{id}/foo"" : { | ||
""get"" : { | ||
""tags"" : [ ""foo"" ], | ||
""operationId"" : ""get-/api/v1/{id}/foo_getAll"", | ||
""parameters"" : [ { | ||
""name"" : ""id"", | ||
""in"" : ""path"", | ||
""required"" : true, | ||
""style"" : ""simple"", | ||
""explode"" : false, | ||
""schema"" : { | ||
""type"" : ""integer"", | ||
""format"" : ""int32"" | ||
} | ||
} ], | ||
""responses"" : { | ||
""200"" : { | ||
""description"" : ""successful operation"" | ||
} | ||
} | ||
} | ||
}, | ||
""/api/v1/{id}/bar"" : { | ||
""get"" : { | ||
""tags"" : [ ""bar"" ], | ||
""operationId"" : ""get-/api/v1/{id}/bar_getAll"", | ||
""parameters"" : [ { | ||
""name"" : ""id"", | ||
""in"" : ""path"", | ||
""required"" : true, | ||
""style"" : ""simple"", | ||
""explode"" : false, | ||
""schema"" : { | ||
""type"" : ""integer"", | ||
""format"" : ""int32"" | ||
} | ||
} ], | ||
""responses"" : { | ||
""200"" : { | ||
""description"" : ""successful operation"" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
"; | ||
|
||
[Fact] | ||
public async Task Can_Generate_Code() | ||
{ | ||
string generateCode = await GenerateCode(); | ||
generateCode.Should().NotBeNullOrWhiteSpace(); | ||
} | ||
|
||
[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 foo = new RefitGeneratorSettings { OpenApiPath = swaggerFile }; | ||
|
||
var sut = await RefitGenerator.CreateAsync(foo); | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.