test custom sources and improve formatter · gtechsltn/NpgsqlRest@51027e4 · GitHub
Skip to content

Commit 51027e4

Browse files
committed
test custom sources and improve formatter
1 parent 2ba54da commit 51027e4

14 files changed

Lines changed: 653 additions & 87 deletions

File tree

NpgsqlRest/Defaults/DefaultEndpoint.cs

Lines changed: 13 additions & 5 deletions

NpgsqlRest/Defaults/DefaultUrlBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static string CreateUrl(Routine routine, NpgsqlRestOptions options)
1010
.Replace("\"", "")
1111
.Trim('/');
1212

13-
schema = schema == "public" ? "" : string.Concat(schema, "/");
13+
schema = string.IsNullOrEmpty(schema) || string.Equals(schema, "public", StringComparison.OrdinalIgnoreCase) ? "" : string.Concat(schema, "/");
1414
var name = routine.Name.ToLowerInvariant()
1515
.Replace("_", "-")
1616
.Replace(" ", "-")

NpgsqlRest/Interfaces.cs

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ public interface IEndpointCreateHandler
99
/// <param name="logger">configured application logger</param>
1010
/// <param name="options">current NpgsqlRest options</param>
1111
void Setup(IApplicationBuilder builder, ILogger? logger, NpgsqlRestOptions options) { }
12+
1213
/// <summary>
1314
/// After successful endpoint creation.
1415
/// </summary>
1516
void Handle(Routine routine, RoutineEndpoint endpoint) { }
17+
1618
/// <summary>
1719
/// After all endpoints are created.
1820
/// </summary>
1921
void Cleanup(ref (Routine routine, RoutineEndpoint endpoint)[] endpoints) { }
22+
2023
/// <summary>
2124
/// After all endpoints are created.
2225
/// </summary>
@@ -26,36 +29,65 @@ void Cleanup() { }
2629
public interface IRoutineSourceParameterFormatter
2730
{
2831
/// <summary>
29-
/// Return true to call FormatCommand and FormatEmpty.
30-
/// Return false to call AppendCommandParameter and AppendEmpty.
32+
/// Return true to call FormatCommand
33+
/// Return false to call AppendCommandParameter or AppendEmpty (when no parameters are present).
3134
/// </summary>
3235
bool IsFormattable { get; }
36+
37+
/// <summary>
38+
/// Return true to call format methods with HttpContext reference.
39+
/// Return false to call format methods without HttpContext reference.
40+
/// </summary>
41+
bool RefContext { get => false; }
42+
3343
/// <summary>
3444
/// Appends result to the command expression string.
3545
/// </summary>
3646
/// <param name="parameter">NpgsqlRestParameter extended parameter with actual name and type descriptor</param>
3747
/// <param name="index">index of the current parameter</param>
3848
/// <param name="count">total parameter count</param>
39-
/// <returns>string to append to expression or null to skip (404)</returns>
49+
/// <returns>string to append to expression or null to skip (404 if endpoint is not handled in the next handler)</returns>
4050
string? AppendCommandParameter(ref NpgsqlRestParameter parameter, ref int index, ref int count) => null;
51+
4152
/// <summary>
4253
/// Formats the command expression string.
4354
/// </summary>
44-
/// <param name="routine">Current routine metadata</param>
55+
/// <param name="routine">Current routine data</param>
4556
/// <param name="parameters">Extended parameters list.</param>
46-
/// <returns>expression string or null to skip (404)</returns>
57+
/// <returns>expression string or null to skip (404 if endpoint is not handled in the next handler)</returns>
4758
string? FormatCommand(ref Routine routine, ref List<NpgsqlRestParameter> parameters) => null;
59+
4860
/// <summary>
4961
/// Called when there are no parameters to append.
5062
/// </summary>
51-
/// <returns>string to append to expression or null to skip (404)</returns>
63+
/// <returns>string to append to expression or null to skip (404 if endpoint is not handled in the next handler)</returns>
5264
string? AppendEmpty() => null;
65+
66+
/// <summary>
67+
/// Appends result to the command expression string.
68+
/// </summary>
69+
/// <param name="parameter">NpgsqlRestParameter extended parameter with actual name and type descriptor</param>
70+
/// <param name="index">index of the current parameter</param>
71+
/// <param name="count">total parameter count</param>
72+
/// <param name="context">HTTP context reference</param>
73+
/// <returns>string to append to expression or null to skip (404 if endpoint is not handled in the next handler)</returns>
74+
string? AppendCommandParameter(ref NpgsqlRestParameter parameter, ref int index, ref int count, ref HttpContext context) => null;
75+
76+
/// <summary>
77+
/// Formats the command expression string.
78+
/// </summary>
79+
/// <param name="routine">Current routine data</param>
80+
/// <param name="parameters">Extended parameters list.</param>
81+
/// <param name="context">HTTP context reference</param>
82+
/// <returns>expression string or null to skip (404 if endpoint is not handled in the next handler)</returns>
83+
string? FormatCommand(ref Routine routine, ref List<NpgsqlRestParameter> parameters, ref HttpContext context) => null;
84+
5385
/// <summary>
54-
/// Called when there are no parameters to format.
86+
/// Called when there are no parameters to append.
5587
/// </summary>
56-
/// <param name="routine"></param>
57-
/// <returns>expression string or null to skip (404)</returns>
58-
string? FormatEmpty(ref Routine routine) => null;
88+
/// <param name="context">HTTP context reference</param>
89+
/// <returns>string to append to expression or null to skip (404 if endpoint is not handled in the next handler)</returns>
90+
string? AppendEmpty(ref HttpContext context) => null;
5991
}
6092

6193
public interface IRoutineSource
@@ -64,6 +96,7 @@ public interface IRoutineSource
6496
/// Comments mode for the current routine source.
6597
/// </summary>
6698
CommentsMode? CommentsMode { get => null; }
99+
67100
/// <summary>
68101
/// Yield all routines with the formatters from the current source.
69102
/// </summary>

NpgsqlRest/MiddlewareExtension.cs

Lines changed: 58 additions & 15 deletions

0 commit comments

Comments
 (0)