Skip to content

Commit f51eb63

Browse files
committed
Process feedback
1 parent c14587c commit f51eb63

File tree

12 files changed

+447
-276
lines changed

12 files changed

+447
-276
lines changed

src/JsonApiDotNetCore.OpenApi.Client/ApiException.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace JsonApiDotNetCore.OpenApi.Client.Exceptions;
88

99
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
10-
internal class ApiException : Exception
10+
public sealed class ApiException : Exception
1111
{
1212
public int StatusCode { get; }
1313

@@ -28,16 +28,3 @@ public override string ToString()
2828
return $"HTTP Response: \n\n{Response}\n\n{base.ToString()}";
2929
}
3030
}
31-
32-
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
33-
internal sealed class ApiException<TResult> : ApiException
34-
{
35-
public TResult Result { get; }
36-
37-
public ApiException(string message, int statusCode, string? response, IReadOnlyDictionary<string, IEnumerable<string>> headers, TResult result,
38-
Exception innerException)
39-
: base(message, statusCode, response, headers, innerException)
40-
{
41-
Result = result;
42-
}
43-
}

src/JsonApiDotNetCore.OpenApi/StringExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ namespace JsonApiDotNetCore.OpenApi;
44

55
internal static class StringExtensions
66
{
7-
private static readonly Regex PatternForPascalCaseConversion = new("(?:^|-|_| +)(.)", RegexOptions.Compiled);
7+
private static readonly Regex Regex = new("(?:^|-|_| +)(.)", RegexOptions.Compiled);
88

99
public static string ToPascalCase(this string source)
1010
{
11-
return PatternForPascalCaseConversion.Replace(source, match => match.Groups[1].Value.ToUpper());
11+
return Regex.Replace(source, match => match.Groups[1].Value.ToUpper());
1212
}
1313
}

test/OpenApiClientTests/NamingConventions/KebabCase/GeneratedTypesTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public void Generated_code_is_named_as_expected()
4949
_ = nameof(ToManyStaffMemberInResponse);
5050
_ = nameof(LinksInRelationshipObject);
5151
_ = nameof(StaffMemberIdentifier);
52-
_ = nameof(StaffMemberResourceType);
5352
_ = nameof(StaffMemberResourceType.StaffMembers);
5453
_ = nameof(SupermarketPrimaryResponseDocument);
5554
_ = nameof(LinksInResourceDocument);

test/OpenApiClientTests/OpenApiClientTests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
<TargetFramework>$(TargetFrameworkName)</TargetFramework>
44
</PropertyGroup>
55

6-
<ItemGroup>
7-
<ProjectReference Include="..\..\src\JsonApiDotNetCore.OpenApi.Client\JsonApiDotNetCore.OpenApi.Client.csproj" />
8-
<ProjectReference Include="..\TestBuildingBlocks\TestBuildingBlocks.csproj" />
9-
</ItemGroup>
10-
116
<ItemGroup>
127
<None Update="xunit.runner.json">
138
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
149
</None>
1510
</ItemGroup>
1611

12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\JsonApiDotNetCore.OpenApi.Client\JsonApiDotNetCore.OpenApi.Client.csproj" />
14+
<ProjectReference Include="..\TestBuildingBlocks\TestBuildingBlocks.csproj" />
15+
</ItemGroup>
16+
1717
<ItemGroup>
1818
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)" PrivateAssets="All" />
1919
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetVersion)" />

test/OpenApiTests/JsonElementExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ public static void ShouldBeString(this JsonElement source, string value)
2525
source.GetString().Should().Be(value);
2626
}
2727

28-
public static ReferenceSchemaIdContainer ShouldBeReferenceSchemaId(this JsonElement source, string value)
28+
public static SchemaReferenceIdContainer ShouldBeSchemaReferenceId(this JsonElement source, string value)
2929
{
3030
source.ValueKind.Should().Be(JsonValueKind.String);
3131

3232
string? jsonElementValue = source.GetString();
3333
jsonElementValue.ShouldNotBeNull();
3434

35-
string referenceSchemaId = jsonElementValue.Split('/').Last();
36-
referenceSchemaId.Should().Be(value);
35+
string schemaReferenceId = jsonElementValue.Split('/').Last();
36+
schemaReferenceId.Should().Be(value);
3737

38-
return new ReferenceSchemaIdContainer(value);
38+
return new SchemaReferenceIdContainer(value);
3939
}
4040

41-
public sealed class ReferenceSchemaIdContainer
41+
public sealed class SchemaReferenceIdContainer
4242
{
43-
public string ReferenceSchemaId { get; }
43+
public string SchemaReferenceId { get; }
4444

45-
public ReferenceSchemaIdContainer(string referenceSchemaId)
45+
public SchemaReferenceIdContainer(string schemaReferenceId)
4646
{
47-
ReferenceSchemaId = referenceSchemaId;
47+
SchemaReferenceId = schemaReferenceId;
4848
}
4949
}
5050

test/OpenApiTests/LegacyOpenApiIntegration/LegacyOpenApiIntegrationTests.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,32 @@ public LegacyOpenApiIntegrationTests()
1313
UseController<AirplanesController>();
1414
UseController<FlightsController>();
1515
UseController<FlightAttendantsController>();
16-
GeneratedDocumentNamespace = "OpenApiClientTests.LegacyClient";
16+
17+
SwaggerDocumentOutputPath = "test/OpenApiClientTests/LegacyClient";
1718
}
1819

1920
[Fact]
20-
public async Task Retrieved_document_matches_expected_document()
21+
public async Task Retrieved_swagger_document_matches_expected_document()
2122
{
2223
// Act
23-
JsonElement jsonElement = await LazyDocument.Value;
24+
JsonElement jsonElement = await GetSwaggerDocumentAsync();
2425

2526
// Assert
26-
const string embeddedResourceName = $"{nameof(OpenApiTests)}.{nameof(LegacyOpenApiIntegration)}.swagger.json";
27-
string expectedDocument = await LoadEmbeddedResourceAsync(embeddedResourceName);
28-
27+
string expectedJsonText = await GetExpectedSwaggerDocumentAsync();
2928
string jsonText = jsonElement.ToString();
30-
jsonText.Should().BeJson(expectedDocument);
29+
jsonText.Should().BeJson(expectedJsonText);
3130
}
3231

33-
private static async Task<string> LoadEmbeddedResourceAsync(string name)
32+
private static async Task<string> GetExpectedSwaggerDocumentAsync()
3433
{
34+
const string embeddedResourceName = $"{nameof(OpenApiTests)}.{nameof(LegacyOpenApiIntegration)}.swagger.json";
3535
var assembly = Assembly.GetExecutingAssembly();
36-
await using Stream? stream = assembly.GetManifestResourceStream(name);
36+
37+
await using Stream? stream = assembly.GetManifestResourceStream(embeddedResourceName);
3738

3839
if (stream == null)
3940
{
40-
throw new Exception($"Failed to load embedded resource '{name}'. Set Build Action to Embedded Resource in properties.");
41+
throw new Exception($"Failed to load embedded resource '{embeddedResourceName}'. Set Build Action to Embedded Resource in properties.");
4142
}
4243

4344
using var reader = new StreamReader(stream);

0 commit comments

Comments
 (0)