Browse Source

* more fixes to googleapiconv (ref #40094)

(googlediscoverytopas)
  -Fix unit clause and "uses" for generated units

(googleapiconv)
  -Add --version parameter
  -Fix logging messages
  -Set OutputUnitName so units have correct clause

(restbase)
  -Add #todo notes for follow up
  -Move function RFC3339ToDateTime next to related functions
wsherman 2 years ago
parent
commit
3224f2c8b5

+ 17 - 11
packages/fcl-web/src/base/restbase.pp

@@ -55,8 +55,12 @@ Type
     FObjectOptions : TObjectOptions;
     FObjectOptions : TObjectOptions;
     fadditionalProperties : TJSONObject;
     fadditionalProperties : TJSONObject;
     FBits : TBits;
     FBits : TBits;
+
+{ #todo -oWayneSherman : can the next two private methods be removed and instead
+  use the rtl provided GetDynArrayProp / SetDynArrayProp in TypInfo.pp unit }
     Function GetDynArrayProp(P: PPropInfo) : Pointer; virtual;
     Function GetDynArrayProp(P: PPropInfo) : Pointer; virtual;
     procedure SetDynArrayProp(P: PPropInfo; AValue : Pointer); virtual;
     procedure SetDynArrayProp(P: PPropInfo; AValue : Pointer); virtual;
+
     procedure SetObjectOptions(AValue: TObjectOptions);
     procedure SetObjectOptions(AValue: TObjectOptions);
     Function GetAdditionalProperties : TJSONObject;
     Function GetAdditionalProperties : TJSONObject;
   protected
   protected
@@ -237,7 +241,6 @@ begin
   Result:=FormatDateTime('hh":"nn":"ss"."zzz',ADate);
   Result:=FormatDateTime('hh":"nn":"ss"."zzz',ADate);
 end;
 end;
 
 
-
 Function TryRFC3339ToDateTime(const Avalue: String; out ADateTime: TDateTime): Boolean;
 Function TryRFC3339ToDateTime(const Avalue: String; out ADateTime: TDateTime): Boolean;
 
 
 //          1         2
 //          1         2
@@ -286,6 +289,14 @@ begin
       ADateTime:=EncodeDate(lY, lM, lD) + EncodeTime(lH, lMi, lS, 0);
       ADateTime:=EncodeDate(lY, lM, lD) + EncodeTime(lH, lMi, lS, 0);
 end;
 end;
 
 
+Function RFC3339ToDateTime(const Avalue: String): TDateTime;
+
+begin
+  if Not TryRFC3339ToDateTime(AValue,Result) then
+    Result:=0;
+end;
+
+
 Function CountProperties(TypeInfo : PTypeInfo; Recurse : Boolean): Integer;
 Function CountProperties(TypeInfo : PTypeInfo; Recurse : Boolean): Integer;
 
 
    function aligntoptr(p : pointer) : pointer;inline;
    function aligntoptr(p : pointer) : pointer;inline;
@@ -318,14 +329,6 @@ begin
     end;
     end;
 end;
 end;
 
 
-
-Function RFC3339ToDateTime(const Avalue: String): TDateTime;
-
-begin
-  if Not TryRFC3339ToDateTime(AValue,Result) then
-    Result:=0;
-end;
-
 Function RESTFactory : TObjectFactory;
 Function RESTFactory : TObjectFactory;
 
 
 begin
 begin
@@ -626,6 +629,7 @@ begin
       GetObjectProp(Self,P).Free;
       GetObjectProp(Self,P).Free;
       SetObjectProp(Self,P,Nil);
       SetObjectProp(Self,P,Nil);
       end
       end
+    { #todo -oWayneSherman : is the tkDynArray type missing here?  }
   else
   else
     // Do nothing
     // Do nothing
   end;
   end;
@@ -802,7 +806,8 @@ begin
     if T^.ClassType.InheritsFrom(TBaseObjectList) then
     if T^.ClassType.InheritsFrom(TBaseObjectList) then
       begin
       begin
       L:=TBaseObjectList(TBaseObjectClass(T^.ClassType).Create);
       L:=TBaseObjectList(TBaseObjectClass(T^.ClassType).Create);
-      SetObjectProp(Self,P,L);   //what if there is an existing object, are we clobbering it?
+      { #todo -oWayneSherman : what if there is an existing object, are we clobbering it? }
+      SetObjectProp(Self,P,L);
       For D in AValue do
       For D in AValue do
         L.AddObject('').LoadFromJSON(D.Value as TJSONObject);
         L.AddObject('').LoadFromJSON(D.Value as TJSONObject);
       end
       end
@@ -810,7 +815,8 @@ begin
       begin
       begin
       S:=TJSONSchema.Create;
       S:=TJSONSchema.Create;
       S.SetArrayProperty(P,AValue);
       S.SetArrayProperty(P,AValue);
-      SetObjectProp(Self,P,S);   //what if there is an existing object, are we clobbering it?
+      { #todo -oWayneSherman : what if there is an existing object, are we clobbering it? }
+      SetObjectProp(Self,P,S);
       end
       end
     else
     else
       Raise ERESTAPI.CreateFmt('Unsupported class %s for property %s',[T^.ClassType.ClassName,P^.Name]);
       Raise ERESTAPI.CreateFmt('Unsupported class %s for property %s',[T^.ClassType.ClassName,P^.Name]);

+ 16 - 2
packages/googleapi/generator/googleapiconv.pp

@@ -20,6 +20,7 @@ uses
   googlediscoverytopas, googleservice, restbase, pascodegen, restcodegen;
   googlediscoverytopas, googleservice, restbase, pascodegen, restcodegen;
 
 
 Const
 Const
+  ProgramVersionNumber = '0.6';
 //  BaseDiscoveryURL = 'https://www.googleapis.com/discovery/v1/apis/';
 //  BaseDiscoveryURL = 'https://www.googleapis.com/discovery/v1/apis/';
   BaseDiscoveryURL = 'https://discovery.googleapis.com/discovery/v1/apis/';
   BaseDiscoveryURL = 'https://discovery.googleapis.com/discovery/v1/apis/';
 
 
@@ -167,6 +168,7 @@ begin
   Writeln('-u --url=URL               URL to download the REST description from.');
   Writeln('-u --url=URL               URL to download the REST description from.');
   Writeln('-v --serviceversion=v      Service version to download the REST description for.');
   Writeln('-v --serviceversion=v      Service version to download the REST description for.');
   Writeln('-V --verbose               Write some diagnostic messages');
   Writeln('-V --verbose               Write some diagnostic messages');
+  Writeln('   --version               Show version number and exit');
   Writeln('If the outputfilename is empty and cannot be determined, an error is returned');
   Writeln('If the outputfilename is empty and cannot be determined, an error is returned');
   Halt(Ord(Msg<>''));
   Halt(Ord(Msg<>''));
 end;
 end;
@@ -378,7 +380,6 @@ begin
         try
         try
           if not HttpGetJSON(RU,RS) then
           if not HttpGetJSON(RU,RS) then
             Raise Exception.Create('Could not download rest description from URL: '+RU);
             Raise Exception.Create('Could not download rest description from URL: '+RU);
-          ConversionLog(Self,cltInfo,Format('Converting service "%s" to unit: %s',[O.get('name'),LFN]));
           if KeepJSON then
           if KeepJSON then
             With TFIleStream.Create(ChangeFileExt(LFN,'.json'),fmCreate) do
             With TFIleStream.Create(ChangeFileExt(LFN,'.json'),fmCreate) do
               try
               try
@@ -386,6 +387,7 @@ begin
               finally
               finally
                 Free;
                 Free;
               end;
               end;
+          ConversionLog(Self,cltInfo,'Saving file: '+ChangeFileExt(LFN,'.json'));
           RS.Position:=0;
           RS.Position:=0;
           U:=UL.AddEntry;
           U:=UL.AddEntry;
           U.FileName:=LFN;
           U.FileName:=LFN;
@@ -405,7 +407,9 @@ begin
       end;
       end;
     if HasOption('I','icon') then
     if HasOption('I','icon') then
       For I:=0 to UL.Count-1 do
       For I:=0 to UL.Count-1 do
-        DownloadIcon(UL[i]);
+        DownloadIcon(UL[i]); //this isn't working with --onlydownload and --all
+                             //the icon URL is not known until after DoConversion
+                             { #todo : fix download icon}
   finally
   finally
     UL.Free;
     UL.Free;
     D.Free;
     D.Free;
@@ -429,6 +433,13 @@ Var
   APIEntry : TAPIEntry;
   APIEntry : TAPIEntry;
 
 
 begin
 begin
+  if (ParamCount=1) and HasOption('version') then
+  begin
+    WriteLn(ExtractFileName(Self.ExeName),' ', ProgramVersionNumber);
+    Terminate;
+    EXIT;
+  end;
+
   JS:=Nil;
   JS:=Nil;
   O:=Nil;
   O:=Nil;
   NonOpts:=TStringList.Create;
   NonOpts:=TStringList.Create;
@@ -495,6 +506,7 @@ begin
           finally
           finally
             Free;
             Free;
           end;
           end;
+      ConversionLog(Self,cltInfo,'Saving file: '+ChangeFileExt(OFN,'.json'));
       JS.POsition:=0;
       JS.POsition:=0;
       end
       end
     else
     else
@@ -573,6 +585,8 @@ begin
     O:=DiscoveryJSONToPas.Description.icons;
     O:=DiscoveryJSONToPas.Description.icons;
     if Assigned(O) then
     if Assigned(O) then
       AEntry.APIIcon:=O.x16;
       AEntry.APIIcon:=O.x16;
+    DiscoveryJSONToPas.OutputUnitName := AEntry.APIUnitName;
+    ConversionLog(Self,cltInfo,Format('Converting service "%s" to unit: %s',[AEntry.APIUnitName,AEntry.FileName]));
     DiscoveryJSONToPas.Execute;
     DiscoveryJSONToPas.Execute;
     DiscoveryJSONToPas.SaveToFile(AEntry.FileName);
     DiscoveryJSONToPas.SaveToFile(AEntry.FileName);
   finally
   finally

+ 2 - 2
packages/googleapi/generator/googlediscoverytopas.pp

@@ -900,7 +900,7 @@ end;
 
 
 Function TDiscoveryJSONToPas.BaseUnits: String;
 Function TDiscoveryJSONToPas.BaseUnits: String;
 begin
 begin
-  Result:='googleservice, restbase, googlebase'
+  Result:='sysutils, classes, googleservice, restbase, googlebase';
 end;
 end;
 
 
 Class function TSchema.BaseType(ATypeName: String): Boolean;
 Class function TSchema.BaseType(ATypeName: String): Boolean;
@@ -2056,7 +2056,7 @@ Procedure TDiscoveryJSONToPas.Execute;
 
 
 begin
 begin
   Source.Clear;
   Source.Clear;
-  Addln('unit '+outputunitname+';');
+  CreateUnitClause;
   CreateHeader;
   CreateHeader;
   FTypes:=TTypeDefs.Create(TTypeDef);
   FTypes:=TTypeDefs.Create(TTypeDef);
   try
   try