Skip to content

Commit b57b808

Browse files
committed
Boolean query params were not being sent correctly. Lazarus issue with JSON fixed.
1 parent 2528ee4 commit b57b808

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

Dist/OpenApiJson.pas

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface
66

77
uses
88
{$IFDEF FPC}
9-
fpjson,
9+
fpjson, jsonparser,
1010
{$ELSE}
1111
Generics.Collections,
1212
JSON,
@@ -300,7 +300,11 @@ function TJsonWrapper.JsonToJsonValue(const Value: string): TJSONValue;
300300

301301
function TJsonWrapper.JsonValueToJson(Value: TJSONValue): string;
302302
begin
303+
{$IFDEF FPC}
304+
Result := Value.AsJSON;
305+
{$ELSE}
303306
Result := Value.ToString;
307+
{$ENDIF}
304308
end;
305309

306310
procedure TJsonWrapper.ObjAddProp(JObj: TJSONValue; const Name: string; Value: TJSONValue);

Dist/OpenApiUtils.pas

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function DateTimeToISO(const Value: TDateTime): string;
2121
function DateToISO(const Value: TDate): string;
2222
function ISOToDateTime(const Value: string): TDateTime;
2323
function ISOToDate(const Value: string): TDate;
24+
function BoolToParam(const Value: Boolean): string;
2425

2526
resourcestring
2627
SInvalidDateFormat = 'Value %s is not a valid datetime';
@@ -612,4 +613,12 @@ function ISOToDate(const Value: string): TDate;
612613
Result := InternalISOTODateTime(Value, zmAsLocal);
613614
end;
614615

616+
function BoolToParam(const Value: Boolean): string;
617+
begin
618+
if Value then
619+
Result := 'true'
620+
else
621+
Result := 'false';
622+
end;
623+
615624
end.

Source/OpenApiGen.Builder.pas

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ procedure TOpenApiImporter.Build(AMetaClient: TMetaClient);
125125

126126
FClientUnit.UseUnit('SysUtils');
127127
FClientUnit.UseUnit('OpenApiRest');
128+
FClientUnit.UseUnit('OpenApiUtils');
128129
FClientUnit.UseUnit(FJsonUnit.Name);
129130
FClientUnit.UseUnit(FDtoUnit.Name);
130131
end;

Source/OpenApiGen.Metadata.pas

+19
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,19 @@ TInt64MetaType = class(TIntegerMetaType)
6565
TBooleanMetaType = class(TMetaType)
6666
public
6767
function TypeName: string; override;
68+
function CodeToParam(const ParamName: string): string; override;
6869
end;
6970

7071
TDateTimeMetaType = class(TMetaType)
7172
public
7273
function TypeName: string; override;
74+
function CodeToParam(const ParamName: string): string; override;
7375
end;
7476

7577
TDateMetaType = class(TDateTimeMetaType)
7678
public
7779
function TypeName: string; override;
80+
function CodeToParam(const ParamName: string): string; override;
7881
end;
7982

8083
TBytesMetaType = class(TMetaType)
@@ -251,6 +254,7 @@ implementation
251254

252255
function TMetaType.CodeToParam(const ParamName: string): string;
253256
begin
257+
Result := ParamName;
254258
end;
255259

256260
function TMetaType.Description: string;
@@ -408,6 +412,11 @@ function TInt64MetaType.TypeName: string;
408412

409413
{ TBooleanMetaType }
410414

415+
function TBooleanMetaType.CodeToParam(const ParamName: string): string;
416+
begin
417+
Result := Format('BoolToParam(%s)', [ParamName]);
418+
end;
419+
411420
function TBooleanMetaType.TypeName: string;
412421
begin
413422
Result := 'Boolean';
@@ -427,13 +436,23 @@ function TBinaryMetaType.TypeName: string;
427436

428437
{ TDateTimeMetaType }
429438

439+
function TDateTimeMetaType.CodeToParam(const ParamName: string): string;
440+
begin
441+
Result := Format('DateTimeToIso(%s)', [ParamName]);
442+
end;
443+
430444
function TDateTimeMetaType.TypeName: string;
431445
begin
432446
Result := 'TDateTime';
433447
end;
434448

435449
{ TDateMetaType }
436450

451+
function TDateMetaType.CodeToParam(const ParamName: string): string;
452+
begin
453+
Result := Format('DateToIso(%s)', [ParamName]);
454+
end;
455+
437456
function TDateMetaType.TypeName: string;
438457
begin
439458
Result := 'TDate';

0 commit comments

Comments
 (0)