Skip to content

Commit b43807a

Browse files
committed
Process review feedback
1 parent f6c01f2 commit b43807a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+839
-652
lines changed

Diff for: JsonApiDotNetCore.sln.DotSettings

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ JsonApiDotNetCore.ArgumentGuard.NotNull($EXPR$, $NAME$);</s:String>
1515
<s:Int64 x:Key="/Default/CodeEditing/NullCheckPatterns/PatternTypeNamesToPriority/=JetBrains_002EReSharper_002EFeature_002EServices_002ECSharp_002ENullChecking_002ETraceAssertPattern/@EntryIndexedValue">50</s:Int64>
1616
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/PropagateAnnotations/@EntryValue">False</s:Boolean>
1717
<s:Boolean x:Key="/Default/CodeInspection/ExcludedFiles/FileMasksToSkip/=swagger_002Ejson/@EntryIndexedValue">True</s:Boolean>
18+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B693DE14_002DBB28_002D496F_002DAB39_002DB4E674ABCA80_002Fd_003ANamingConventions_002Fd_003ACamelCase_002Ff_003Aswagger_002Ejson/@EntryIndexedValue">ExplicitlyExcluded</s:String>
19+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B693DE14_002DBB28_002D496F_002DAB39_002DB4E674ABCA80_002Fd_003ANamingConventions_002Fd_003AKebabCase_002Ff_003Aswagger_002Ejson/@EntryIndexedValue">ExplicitlyExcluded</s:String>
20+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B693DE14_002DBB28_002D496F_002DAB39_002DB4E674ABCA80_002Fd_003ANamingConventions_002Fd_003APascalCase_002Ff_003Aswagger_002Ejson/@EntryIndexedValue">ExplicitlyExcluded</s:String>
1821
<s:String x:Key="/Default/CodeInspection/Highlighting/AnalysisEnabled/@EntryValue">SOLUTION</s:String>
1922
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/IdentifierHighlightingEnabled/@EntryValue">True</s:Boolean>
2023
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/IncludeWarningsInSwea/@EntryValue">True</s:Boolean>

Diff for: src/JsonApiDotNetCore.OpenApi.Client/ApiException.cs

+34-33
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
using JetBrains.Annotations;
22

33
// We cannot rely on generating ApiException as soon as we are generating multiple clients, see https://github.com/RicoSuter/NSwag/issues/2839#issuecomment-776647377.
4-
// Instead, we take the generated code as is and use it for the various clients.
5-
#nullable disable
6-
// @formatter:off
7-
// ReSharper disable All
8-
namespace JsonApiDotNetCore.OpenApi.Client.Exceptions
4+
// Instead, we configure NSwag to point to the exception below in the generated code.
5+
6+
// ReSharper disable once CheckNamespace
7+
namespace JsonApiDotNetCore.OpenApi.Client.Exceptions;
8+
9+
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
10+
internal class ApiException : Exception
911
{
10-
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
11-
internal class ApiException : Exception
12-
{
13-
public int StatusCode { get; }
12+
public int StatusCode { get; }
13+
14+
public string? Response { get; }
1415

15-
public string Response { get; }
16+
public IReadOnlyDictionary<string, IEnumerable<string>> Headers { get; }
1617

17-
public IReadOnlyDictionary<string, IEnumerable<string>> Headers { get; }
18+
public ApiException(string message, int statusCode, string? response, IReadOnlyDictionary<string, IEnumerable<string>> headers, Exception innerException)
19+
: base(
20+
message + "\n\nStatus: " + statusCode + "\nResponse: \n" +
21+
(response == null ? "(null)" : response[..(response.Length >= 512 ? 512 : response.Length)]), innerException)
22+
{
23+
StatusCode = statusCode;
24+
Response = response;
25+
Headers = headers;
26+
}
1827

19-
public ApiException(string message, int statusCode, string response, IReadOnlyDictionary<string, IEnumerable<string>> headers, Exception innerException)
20-
: base(
21-
message + "\n\nStatus: " + statusCode + "\nResponse: \n" +
22-
(response == null ? "(null)" : response.Substring(0, response.Length >= 512 ? 512 : response.Length)), innerException)
23-
{
24-
StatusCode = statusCode;
25-
Response = response;
26-
Headers = headers;
27-
}
28+
public override string ToString()
29+
{
30+
return $"HTTP Response: \n\n{Response}\n\n{base.ToString()}";
31+
}
32+
}
2833

29-
public override string ToString()
30-
{
31-
return $"HTTP Response: \n\n{Response}\n\n{base.ToString()}";
32-
}}
34+
[UsedImplicitly(ImplicitUseTargetFlags.Members)]
35+
internal sealed class ApiException<TResult> : ApiException
36+
{
37+
public TResult Result { get; }
3338

34-
internal sealed class ApiException<TResult> : ApiException
39+
public ApiException(string message, int statusCode, string? response, IReadOnlyDictionary<string, IEnumerable<string>> headers, TResult result,
40+
Exception innerException)
41+
: base(message, statusCode, response, headers, innerException)
3542
{
36-
public TResult Result { get; }
37-
38-
public ApiException(string message, int statusCode, string response, IReadOnlyDictionary<string, IEnumerable<string>> headers, TResult result,
39-
Exception innerException)
40-
: base(message, statusCode, response, headers, innerException)
41-
{
42-
Result = result;
43-
}}
43+
Result = result;
44+
}
4445
}

Diff for: src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Links/LinksInRelationshipObject.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using System.Text.Json.Serialization;
23
using JetBrains.Annotations;
34

45
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
@@ -7,8 +8,10 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
78
internal sealed class LinksInRelationshipObject
89
{
910
[Required]
11+
[JsonPropertyName("self")]
1012
public string Self { get; set; } = null!;
1113

1214
[Required]
15+
[JsonPropertyName("related")]
1316
public string Related { get; set; } = null!;
1417
}

Diff for: src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Links/LinksInResourceCollectionDocument.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using System.Text.Json.Serialization;
23
using JetBrains.Annotations;
34

45
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
@@ -7,16 +8,22 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
78
internal sealed class LinksInResourceCollectionDocument
89
{
910
[Required]
11+
[JsonPropertyName("self")]
1012
public string Self { get; set; } = null!;
1113

14+
[JsonPropertyName("describedby")]
1215
public string Describedby { get; set; } = null!;
1316

1417
[Required]
18+
[JsonPropertyName("first")]
1519
public string First { get; set; } = null!;
1620

21+
[JsonPropertyName("last")]
1722
public string Last { get; set; } = null!;
1823

24+
[JsonPropertyName("prev")]
1925
public string Prev { get; set; } = null!;
2026

27+
[JsonPropertyName("next")]
2128
public string Next { get; set; } = null!;
2229
}

Diff for: src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Links/LinksInResourceDocument.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using System.Text.Json.Serialization;
23
using JetBrains.Annotations;
34

45
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
@@ -7,7 +8,9 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
78
internal sealed class LinksInResourceDocument
89
{
910
[Required]
11+
[JsonPropertyName("self")]
1012
public string Self { get; set; } = null!;
1113

14+
[JsonPropertyName("describedby")]
1215
public string Describedby { get; set; } = null!;
1316
}

Diff for: src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Links/LinksInResourceIdentifierCollectionDocument.cs

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using System.Text.Json.Serialization;
23
using JetBrains.Annotations;
34

45
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
@@ -7,19 +8,26 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
78
internal sealed class LinksInResourceIdentifierCollectionDocument
89
{
910
[Required]
11+
[JsonPropertyName("self")]
1012
public string Self { get; set; } = null!;
1113

14+
[JsonPropertyName("describedby")]
1215
public string Describedby { get; set; } = null!;
1316

1417
[Required]
18+
[JsonPropertyName("related")]
1519
public string Related { get; set; } = null!;
1620

1721
[Required]
22+
[JsonPropertyName("first")]
1823
public string First { get; set; } = null!;
1924

25+
[JsonPropertyName("last")]
2026
public string Last { get; set; } = null!;
2127

28+
[JsonPropertyName("prev")]
2229
public string Prev { get; set; } = null!;
2330

31+
[JsonPropertyName("next")]
2432
public string Next { get; set; } = null!;
2533
}

Diff for: src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Links/LinksInResourceIdentifierDocument.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using System.Text.Json.Serialization;
23
using JetBrains.Annotations;
34

45
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
@@ -7,10 +8,13 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
78
internal sealed class LinksInResourceIdentifierDocument
89
{
910
[Required]
11+
[JsonPropertyName("self")]
1012
public string Self { get; set; } = null!;
1113

14+
[JsonPropertyName("describedby")]
1215
public string Describedby { get; set; } = null!;
1316

1417
[Required]
18+
[JsonPropertyName("related")]
1519
public string Related { get; set; } = null!;
1620
}

Diff for: src/JsonApiDotNetCore.OpenApi/JsonApiObjects/Links/LinksInResourceObject.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using System.Text.Json.Serialization;
23
using JetBrains.Annotations;
34

45
namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
@@ -7,5 +8,6 @@ namespace JsonApiDotNetCore.OpenApi.JsonApiObjects.Links;
78
internal sealed class LinksInResourceObject
89
{
910
[Required]
11+
[JsonPropertyName("self")]
1012
public string Self { get; set; } = null!;
1113
}

Diff for: src/JsonApiDotNetCore.OpenApi/JsonApiOperationIdSelector.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private string ApplyTemplate(string operationIdTemplate, ResourceType resourceTy
112112
throw new UnreachableCodeException();
113113
}
114114

115-
string method = endpoint.HttpMethod!.ToLowerInvariant();
115+
string method = endpoint.HttpMethod.ToLowerInvariant();
116116
string relationshipName = operationIdTemplate.Contains("[RelationshipName]") ? endpoint.RelativePath.Split("/").Last() : string.Empty;
117117

118118
// @formatter:wrap_chained_method_calls chop_always
@@ -122,7 +122,7 @@ private string ApplyTemplate(string operationIdTemplate, ResourceType resourceTy
122122
.Replace("[Method]", method)
123123
.Replace("[PrimaryResourceName]", resourceType.PublicName.Singularize())
124124
.Replace("[RelationshipName]", relationshipName)
125-
.Pascalize();
125+
.ToPascalCase();
126126

127127
// @formatter:keep_existing_linebreaks restore
128128
// @formatter:wrap_chained_method_calls restore

Diff for: src/JsonApiDotNetCore.OpenApi/JsonApiSchemaIdSelector.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public string GetSchemaId(Type type)
7171
throw new UnreachableCodeException();
7272
}
7373

74-
string pascalCaseSchemaId = OpenTypeToSchemaTemplateMap[openType].Replace("[ResourceName]", resourceType.PublicName.Singularize()).Pascalize();
74+
string pascalCaseSchemaId = OpenTypeToSchemaTemplateMap[openType].Replace("[ResourceName]", resourceType.PublicName.Singularize()).ToPascalCase();
7575

7676
return _namingPolicy != null ? _namingPolicy.ConvertName(pascalCaseSchemaId) : pascalCaseSchemaId;
7777
}

Diff for: src/JsonApiDotNetCore.OpenApi/ServiceCollectionExtensions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ private static void AddCustomApiExplorer(IServiceCollection services, IMvcCoreBu
4141
var apiDescriptionProviders = provider.GetRequiredService<IEnumerable<IApiDescriptionProvider>>();
4242

4343
JsonApiActionDescriptorCollectionProvider descriptorCollectionProviderWrapper = new(controllerResourceMapping, actionDescriptorCollectionProvider);
44-
4544
return new ApiDescriptionGroupCollectionProvider(descriptorCollectionProviderWrapper, apiDescriptionProviders);
4645
});
4746

Diff for: src/JsonApiDotNetCore.OpenApi/StringExtensions.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ namespace JsonApiDotNetCore.OpenApi;
44

55
internal static class StringExtensions
66
{
7-
public static string Pascalize(this string source)
7+
private static readonly Regex Pattern = new("(?:^|-|_| +)(.)", RegexOptions.Compiled);
8+
9+
public static string ToPascalCase(this string source)
810
{
9-
return Regex.Replace(source, "(?:^|-|_| +)(.)", match => match.Groups[1].Value.ToUpper());
11+
return Pattern.Replace(source, match => match.Groups[1].Value.ToUpper());
1012
}
1113
}

Diff for: src/JsonApiDotNetCore.OpenApi/SwaggerComponents/NullableReferenceSchemaGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ internal sealed class NullableReferenceSchemaGenerator
1010
private readonly NullableReferenceSchemaStrategy _nullableReferenceStrategy =
1111
Enum.Parse<NullableReferenceSchemaStrategy>(NullableReferenceSchemaStrategy.Implicit.ToString());
1212

13-
private readonly string _nullableSchemaReferenceId;
1413
private readonly ISchemaRepositoryAccessor _schemaRepositoryAccessor;
14+
private readonly string _nullableSchemaReferenceId;
1515

1616
private OpenApiSchema? _referenceSchemaForExplicitNullValue;
1717

Diff for: src/JsonApiDotNetCore.OpenApi/SwaggerComponents/ResourceTypeSchemaGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public OpenApiSchema Get(Type resourceClrType)
6363

6464
private string GetSchemaId(ResourceType resourceType)
6565
{
66-
string pascalCaseSchemaId = ResourceTypeSchemaIdTemplate.Replace("[ResourceName]", resourceType.PublicName.Singularize()).Pascalize();
66+
string pascalCaseSchemaId = ResourceTypeSchemaIdTemplate.Replace("[ResourceName]", resourceType.PublicName.Singularize()).ToPascalCase();
6767

6868
return _namingPolicy != null ? _namingPolicy.ConvertName(pascalCaseSchemaId) : pascalCaseSchemaId;
6969
}

Diff for: test/OpenApiClientTests/NamingConvention/CamelCase/GeneratedTypesTests.cs

-78
This file was deleted.

0 commit comments

Comments
 (0)