Skip to content

Commit 305e848

Browse files
committed
Support string constants in endpoint action parameter overrides
1 parent 84613a3 commit 305e848

15 files changed

Lines changed: 171 additions & 129 deletions

File tree

src/Dibix.Http.Server/Model/HttpParameterSourceSelector.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public void ResolveParameterFromConstant(string targetParameterName, int value)
2020
{
2121
this.ResolveParameter(targetParameterName, new HttpParameterConstantSource(value));
2222
}
23+
public void ResolveParameterFromConstant(string targetParameterName, string value)
24+
{
25+
this.ResolveParameter(targetParameterName, new HttpParameterConstantSource(value));
26+
}
2327
public void ResolveParameterFromNull(string targetParameterName)
2428
{
2529
this.ResolveParameter(targetParameterName, new HttpParameterConstantSource(null));

src/Dibix.Http.Server/Model/IHttpParameterSourceSelector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public interface IHttpParameterSourceSelector
44
{
55
void ResolveParameterFromConstant(string targetParameterName, bool value);
66
void ResolveParameterFromConstant(string targetParameterName, int value);
7+
void ResolveParameterFromConstant(string targetParameterName, string value);
78
void ResolveParameterFromNull(string targetParameterName);
89
void ResolveParameterFromSource(string targetParameterName, string sourceName, string sourcePropertyName);
910
void ResolveParameterFromSource(string targetParameterName, string sourceName, string sourcePropertyName, string converterName);

src/Dibix.Sdk/CodeGeneration/Model/ControllerDefinitionProvider.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,12 @@ private bool TryReadSource(JProperty property, string filePath, bool isItem, out
287287
return true;
288288

289289
case JTokenType.String:
290-
source = ReadPropertySource((JValue)property.Value, filePath);
290+
string stringValue = (string)property.Value;
291+
if (stringValue != null && stringValue.Contains('.'))
292+
source = this.ReadPropertySource((JValue)property.Value, filePath);
293+
else
294+
source = ReadConstantSource((JValue)property.Value);
295+
291296
return true;
292297

293298
default:

src/Dibix.Sdk/CodeGeneration/Output/ApiDescriptionWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ private static string ComputeConstantLiteral(object value)
203203
switch (value)
204204
{
205205
case bool boolValue: return boolValue.ToString().ToLowerInvariant();
206+
case string stringValue: return $"\"{stringValue}\"";
206207
case null: return "null";
207208
default: return value.ToString();
208209
}

src/Dibix.Sdk/Schema/dibix.endpoints.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
{
3434
"type": "number"
3535
},
36+
{
37+
"type": "string",
38+
"pattern": "^[^.]+$"
39+
},
3640
{
3741
"type": "null"
3842
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"AnotherInputContract": {
3-
"U": "string",
4-
"V": "string",
5-
"W": {
3+
"A": "string",
4+
"B": "string",
5+
"C": {
66
"type": "string",
77
"isOptional": true
88
},
99
"SomeIds": "#AnotherEntry*",
10-
"X": "uuid",
10+
"D": "uuid",
1111
"Password": "string",
12-
"Y": "boolean",
13-
"Z": "int32"
12+
"E": "boolean",
13+
"F": "int32",
14+
"G": "string"
1415
}
1516
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"InputContract": {
3-
"U": "string",
4-
"V": "string",
5-
"W": {
3+
"A": "string",
4+
"B": "string",
5+
"C": {
66
"type": "string",
77
"isOptional": true
88
},
99
"Ids": "#Entry*",
10-
"X": "uuid",
10+
"D": "uuid",
1111
"Password": "string",
12-
"Y": "boolean",
13-
"Z": "int32"
12+
"E": "boolean",
13+
"F": "int32",
14+
"G": "string"
1415
}
1516
}

tests/Dibix.Sdk.Tests.Database/Endpoints/GenericEndpoint.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
"target": "EmptyWithParams",
1212
"childRoute": "{password}/Fixed",
1313
"params": {
14-
"u": "HEADER.User-Agent",
15-
"v": "HEADER.Authorization.Parameter",
16-
"w": {
14+
"a": "HEADER.User-Agent",
15+
"b": "HEADER.Authorization.Parameter",
16+
"c": {
1717
"source": "DBX.X",
1818
"converter": "DBX"
1919
},
2020
"password": null,
21-
"x": "REQUEST.Language",
22-
"y": true,
23-
"z": 5
21+
"d": "REQUEST.Language",
22+
"e": true,
23+
"f": 5,
24+
"g": "cake"
2425
}
2526
},
2627
{

tests/Dibix.Sdk.Tests.Database/Endpoints/GenericEndpointWithErrors.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"method": "GET",
66
"target": "EmptyWithParams",
77
"params": {
8-
"u": "WTF.Is.This",
9-
"v": "ENV.MachinePassword"
8+
"a": "WTF.Is.This",
9+
"b": "ENV.MachinePassword"
1010
}
1111
},
1212
{
@@ -15,8 +15,8 @@
1515
"body": "Request",
1616
"childRoute": "this/get/is/wrong",
1717
"params": {
18-
"v": "BODY.X",
19-
"w": "BODY.Id.Nm",
18+
"a": "BODY.X",
19+
"b": "BODY.Id.Nm",
2020
"ids": {
2121
"source": "BODY.Ids",
2222
"items": {
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
-- @Name EmptyWithParams
22
CREATE PROCEDURE [dbo].[dbx_tests_syntax_empty_params]
3-
@u NVARCHAR(50)
4-
, @v NVARCHAR(50)
5-
, @w UNIQUEIDENTIFIER NULL
3+
@a NVARCHAR(50)
4+
, @b NVARCHAR(50)
5+
, @c UNIQUEIDENTIFIER NULL
66
, /* @Obfuscate */ @password NVARCHAR(128)
77
, @ids [dbo].[dbx_codeanalysis_udt_generic] READONLY
8-
, @x NVARCHAR(50) NULL = NULL
9-
, @y BIT = 1
10-
, /* @ClrType Direction */ @z INT NULL = NULL
8+
, @d NVARCHAR(50) NULL = NULL
9+
, @e BIT = 1
10+
, /* @ClrType Direction */ @f INT NULL = NULL
11+
, @g NVARCHAR(50) NULL = N'Cake'
1112
AS
12-
PRINT CONCAT(@u, @v, @w, @password, @ids, @x, @y, @z)
13+
PRINT CONCAT(@a, @b, @c, @password, @ids, @d, @e, @f, @g)

0 commit comments

Comments
 (0)