Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Demos/GenerateSwaggerJsonFromCode/GenerateSwagger.res
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ function DelphiVarName(const pVarName: string):string;

procedure TDelphiUnit.AddImplementationConstant(const pName, pValue: string);
begin
{$IF COMPILERVERSION <= 27}
fImplementationConstant.Add(pName + ' : ' + pValue);
{$ELSE}
fImplementationConstant.AddPair(pName, pValue);
{$ENDIF}
end;

procedure TDelphiUnit.AddImplementationUnit(const pFilename: string);
Expand All @@ -221,12 +225,20 @@ procedure TDelphiUnit.AddImplementationUnit(const pFilename: string);

procedure TDelphiUnit.AddInterfaceVar(const pName: string; pTypeInfo: TUnitTypeDefinition);
begin
{$IF COMPILERVERSION <= 27}
fInterfaceVar.Add(pName + ':' + pTypeInfo.TypeName);
{$ELSE}
fInterfaceVar.AddPair(pName, pTypeInfo.TypeName);
{$ENDIF}
end;

procedure TDelphiUnit.AddInterfaceConstant(const pName, pValue: string);
begin
{$IF COMPILERVERSION <= 27}
fInterfaceConstant.Add(pName + ':' + pValue);
{$ELSE}
fInterfaceConstant.AddPair(pName, pValue);
{$ENDIF}
end;

procedure TDelphiUnit.AddInterfaceUnit(const pFilename: string);
Expand Down
55 changes: 18 additions & 37 deletions Demos/GenerateUnitFileForMVCFramework/Sample.Main.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,61 @@ object Form1: TForm1
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
DesignerMobile = False
DesignerWidth = 0
DesignerHeight = 0
DesignerDeviceName = ''
DesignerOrientation = 0
DesignerOSVersion = ''
object TabControl1: TTabControl
Align = Bottom
Height = 200.000000000000000000
Position.Y = 40.000000000000000000
Size.Width = 605.000000000000000000
Size.Height = 645.000000000000000000
Size.PlatformDefault = False
TabIndex = 1
TabOrder = 2
TabPosition = PlatformDefault
Sizes = (
605s
619s
605s
619s)
Width = 200.000000000000000000
object TabItem1: TTabItem
CustomIcon = <
item
end>
Height = 24.000000000000000000
IsSelected = False
Size.Width = 98.000000000000000000
Size.Height = 26.000000000000000000
Size.PlatformDefault = False
StyleLookup = ''
TabOrder = 0
Text = 'Swagger JSON'
ExplicitSize.cx = 98.000000000000000000
ExplicitSize.cy = 26.000000000000000000
Width = 94.000000000000000000
object Memo1: TMemo
Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
DataDetectorTypes = []
Align = Client
Size.Width = 605.000000000000000000
Size.Height = 619.000000000000000000
Size.PlatformDefault = False
Height = 176.000000000000000000
TabOrder = 0
Viewport.Width = 601.000000000000000000
Viewport.Height = 615.000000000000000000
Width = 200.000000000000000000
end
end
object TabItem2: TTabItem
CustomIcon = <
item
end>
Height = 24.000000000000000000
IsSelected = True
Size.Width = 89.000000000000000000
Size.Height = 26.000000000000000000
Size.PlatformDefault = False
StyleLookup = ''
TabOrder = 0
Text = 'Delphi Client'
ExplicitSize.cx = 136.000000000000000000
ExplicitSize.cy = 26.000000000000000000
Width = 85.000000000000000000
object Memo2: TMemo
Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
DataDetectorTypes = []
Align = Client
Size.Width = 605.000000000000000000
Size.Height = 619.000000000000000000
Size.PlatformDefault = False
Height = 176.000000000000000000
TabOrder = 0
Viewport.Width = 601.000000000000000000
Viewport.Height = 615.000000000000000000
Width = 200.000000000000000000
end
end
end
object btnGenerateClient: TButton
Height = 22.000000000000000000
Position.X = 24.000000000000000000
Position.Y = 8.000000000000000000
Size.Width = 121.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TabOrder = 3
Text = 'Generate Client'
Width = 80.000000000000000000
OnClick = btnGenerateClientClick
end
end
7 changes: 5 additions & 2 deletions Demos/GenerateUnitFileForMVCFramework/Sample.Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ interface
FMX.Forms,
FMX.Graphics,
FMX.Dialogs,
{$IF COMPILERVERSION >= 28}
FMX.Controls.Presentation,
FMX.StdCtrls,
FMX.ScrollBox,
{$ENDIF}
FMX.StdCtrls,
FMX.Memo,
FMX.TabControl;
FMX.TabControl,
FMX.Layouts;

type
TForm1 = class(TForm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ procedure TSwagDocToDelphiRESTClientBuilder.HandleArray(pField : TUnitFieldDefin
end
else
begin
OutputDebugString(PChar(pJson.ToJSON));
OutputDebugString(PChar(pJson.ToString));
vJsonVal := (pJson.JsonValue as TJSONObject).Values['items'] as TJSONObject;
OutputDebugString(PChar(vJsonVal.ToJSON));
OutputDebugString(PChar(vJsonVal.ToString));
vJsonObj := vJsonVal as TJSONObject;
vJsonVal := vJsonObj.Values['$ref'];
OutputDebugString(PChar(vJsonVal.Value));
Expand All @@ -267,14 +267,14 @@ procedure TSwagDocToDelphiRESTClientBuilder.ChildType(pDelphiUnit : TDelphiUnit;
vJsonPropIndex: Integer;
vValue : string;
begin
OutputDebugString(PChar('Child: ' + pJson.ToJSON));
OutputDebugString(PChar('Child: ' + pJson.ToString));
vTypeInfo := TUnitTypeDefinition.Create;
vTypeInfo.TypeName := 'T' + CapitalizeFirstLetter(pJson.JSONString.Value);

vJsonProps := (pJson.JSONValue as TJSONObject).Values['properties'] as TJSONObject;
for vJsonPropIndex := 0 to vJsonProps.Count - 1 do
begin
OutputDebugString(PChar(vJsonProps.Pairs[vJsonPropIndex].ToJSON));
OutputDebugString(PChar(vJsonProps.Pairs[vJsonPropIndex].ToString));
vFieldInfo := TUnitFieldDefinition.Create;
vFieldInfo.FieldName := vJsonProps.Pairs[vJsonPropIndex].JsonString.Value;
vTypeObj := vJsonProps.Pairs[vJsonPropIndex].JsonValue as TJSONObject;
Expand Down Expand Up @@ -319,7 +319,7 @@ procedure TSwagDocToDelphiRESTClientBuilder.ConvertSwaggerDefinitionsToTypeDefin
vJsonProps := fSwagDoc.Definitions[DefinitionIndex].JsonSchema.Values['properties'] as TJSONObject;
for vJsonPropIndex := 0 to vJsonProps.Count - 1 do
begin
OutputDebugString(PChar(vJsonProps.Pairs[vJsonPropIndex].ToJSON));
OutputDebugString(PChar(vJsonProps.Pairs[vJsonPropIndex].ToString));
vFieldInfo := TUnitFieldDefinition.Create;
vFieldInfo.FieldName := vJsonProps.Pairs[vJsonPropIndex].JsonString.Value;
vTypeObj := vJsonProps.Pairs[vJsonPropIndex].JsonValue as TJSONObject;
Expand Down Expand Up @@ -394,7 +394,7 @@ function TSwagDocToDelphiRESTClientBuilder.ConvertSwaggerTypeToDelphiType(pSwagg
vJson := pSwaggerType.Schema.JsonSchema;
if Assigned(vJson) then
begin
OutputDebugString(PChar('TYPE: ' + vJson.ToJson));
OutputDebugString(PChar('TYPE: ' + vJson.ToString));
Result.TypeName := 'array of ' + pSwaggerType.Schema.JsonSchema.Values['type'].Value;
end
else
Expand Down
Binary file modified Demos/LoadSwaggerJsonToObject/LoadSwaggerJsonToObject.res
Binary file not shown.
17 changes: 10 additions & 7 deletions Demos/SampleApi/Sample.Main.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@ object Form1: TForm1
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
DesignerMobile = False
DesignerWidth = 0
DesignerHeight = 0
DesignerDeviceName = ''
DesignerOrientation = 0
DesignerOSVersion = ''
object Button1: TButton
Height = 22.000000000000000000
Position.X = 16.000000000000000000
Position.Y = 8.000000000000000000
TabOrder = 1
Text = 'Generate'
Width = 80.000000000000000000
OnClick = Button1Click
end
object Memo1: TMemo
Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
DataDetectorTypes = []
Anchors = [akLeft, akTop, akRight, akBottom]
Height = 633.000000000000000000
Position.X = 16.000000000000000000
Position.Y = 40.000000000000000000
Size.Width = 574.000000000000000000
Size.Height = 630.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
Viewport.Width = 570.000000000000000000
Viewport.Height = 626.000000000000000000
Width = 577.000000000000000000
end
end
7 changes: 6 additions & 1 deletion Demos/SampleApi/Sample.Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ interface
FMX.Forms,
FMX.Graphics,
FMX.Dialogs,
{$IF COMPILERVERSION >= 28}
FMX.Controls.Presentation,
FMX.StdCtrls, FMX.ScrollBox, FMX.Memo;
FMX.ScrollBox,
{$ENDIF}
FMX.StdCtrls,
FMX.Memo,
FMX.Layouts;

type
TForm1 = class(TForm)
Expand Down
Binary file modified Demos/SampleApi/SampleApi.res
Binary file not shown.
20 changes: 10 additions & 10 deletions Deploy/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,41 @@
"version":"v1",
"title":"Sample API",
"description":"Sample API Description",
"termsOfService":"http:\/\/www.apache.org\/licenses\/LICENSE-2.0.txt",
"termsOfService":"http://www.apache.org/licenses/LICENSE-2.0.txt",
"contact":
{
"name":"Marcelo Jaloto",
"email":"marcelojaloto@gmail.com",
"url":"https:\/\/github.com\/marcelojaloto\/SwagDoc"
"url":"https://github.com/marcelojaloto/SwagDoc"
}
,
"license":
{
"name":"Apache License - Version 2.0, January 2004",
"url":"http:\/\/www.apache.org\/licenses\/LICENSE-2.0"
"url":"http://www.apache.org/licenses/LICENSE-2.0"
}
}
,
"host":"localhost",
"basePath":"\/api",
"basePath":"/api",
"schemes":
[
"http"
]
,
"consumes":
[
"application\/json"
"application/json"
]
,
"produces":
[
"application\/json"
"application/json"
]
,
"paths":
{
"\/employees":
"/employees":
{
"get":
{
Expand Down Expand Up @@ -190,7 +190,7 @@
"required":true,
"schema":
{
"$ref":"#\/definitions\/employee"
"$ref":"#/definitions/employee"
}
}
]
Expand Down Expand Up @@ -307,7 +307,7 @@
}
}
,
"\/employees\/{id}":
"/employees/{id}":
{
"get":
{
Expand Down Expand Up @@ -464,7 +464,7 @@
"required":true,
"schema":
{
"$ref":"#\/definitions\/employee"
"$ref":"#/definitions/employee"
}
}
]
Expand Down
11 changes: 2 additions & 9 deletions Source/Json.Schema.Field.Objects.pas
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,11 @@ function TJsonFieldObject.GetField(const pFieldIndex: Integer): TJsonField;
end;

function TJsonFieldObject.GetFieldByName(const pName: string): TJsonField;
var
I: Integer;
begin
Result := nil;
for I := 0 to Pred(fFields.Count) do
begin
if (UpperCase(fFields[I].Name) = UpperCase(pName)) then
begin
Result := fFields[I];
for Result in fFields do
if (UpperCase(Result.Name) = UpperCase(pName)) then
Break;
end;
end;
end;

function TJsonFieldObject.GetFieldsCount: Integer;
Expand Down
12 changes: 6 additions & 6 deletions Source/Json.Schema.pas
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function TJsonSchema.GetJsonFieldClass<T>: TJsonFieldClass;
case vSchemaKind of
skObject:
begin
vClass := FindClass(string(PTypeInfo(System.TypeInfo(T))^.NameFld.ToString));
vClass := FindClass(string(PTypeInfo(System.TypeInfo(T))^.Name));
if not vClass.InheritsFrom(TJsonField) then
raise ETypeNotSupportedByAField.Create(c_ErrorTypeNotSupportedByAField);
Result := TJsonFieldClass(vClass);
Expand Down Expand Up @@ -142,25 +142,25 @@ function TJsonSchema.GetSchemaKind<T>: TSchemaKind;
tkString, tkUString, tkChar: Result := skString;
tkRecord:
begin
if vTypeInfo = System.TypeInfo(TGuid) then
if (LowerCase(string(vTypeInfo^.Name)) = 'tguid') then
Result := skGuid
end;
tkInteger: Result := skInteger;
tkInt64: Result := skInt64;
tkEnumeration:
begin
if vTypeInfo = System.TypeInfo(Boolean) then
if (LowerCase(string(vTypeInfo^.Name)) = 'boolean') then
Result := skBoolean
else
Result := skEnumeration;
end;
tkFloat:
begin
if vTypeInfo = System.TypeInfo(TDateTime) then
if (LowerCase(string(vTypeInfo^.Name)) = 'tdatetime') then
Result := skDateTime
else if vTypeInfo = System.TypeInfo(TDate) then
else if (LowerCase(string(vTypeInfo^.Name)) = 'tdate') then
Result := skDate
else if vTypeInfo = System.TypeInfo(TTime) then
else if (LowerCase(string(vTypeInfo^.Name)) = 'ttime') then
Result := skTime
else
Result := skNumber;
Expand Down
Loading