ソースを参照

* Some corrections in service name construction, in line with method name construction

Michaël Van Canneyt 1 ヶ月 前
コミット
667607f121
1 ファイル変更10 行追加12 行削除
  1. 10 12
      packages/fcl-openapi/src/fpopenapi.pascaltypes.pp

+ 10 - 12
packages/fcl-openapi/src/fpopenapi.pascaltypes.pp

@@ -776,7 +776,8 @@ begin
   For I:=0 to aMap.Count-1 do
   For I:=0 to aMap.Count-1 do
     begin
     begin
     aMap.GetNameValue(I,N,V);
     aMap.GetNameValue(I,N,V);
-    FServiceOperationMap.Add(N,V);
+    if (N<>'') and (V<>'') then
+      FServiceOperationMap.Add(N,V);
     end;
     end;
 end;
 end;
 
 
@@ -897,7 +898,7 @@ function TAPIData.GenerateServiceName(const aUrl: String; const aPath: TPathItem
     Result:=StringReplace(S,' ','',[rfReplaceAll])
     Result:=StringReplace(S,' ','',[rfReplaceAll])
   end;
   end;
 {
 {
-  the maps contain ServiceName.MethodName.
+  the maps contain ServiceName[.MethodName]
   We use ServiceName if there is an entry in the map.
   We use ServiceName if there is an entry in the map.
   if there is no entry in the map and there is 1 tag, we take the name of the tag.
   if there is no entry in the map and there is 1 tag, we take the name of the tag.
   if there is no tag, we take the first component of the URL path.
   if there is no tag, we take the first component of the URL path.
@@ -909,17 +910,14 @@ var
 
 
 begin
 begin
   Result:='';
   Result:='';
-  if (aOperation.Tags.Count=1) then
-    lTag:=ServiceNamePrefix+CleanIdentifier(aOperation.Tags[0])+ServiceNameSuffix
-  else
-    lTag:='';
+  // We need to take into account the full map first, as is done for the method.
   if aOperation.OperationID<>'' then
   if aOperation.OperationID<>'' then
     lFullName:=FServiceOperationMap.Items[aOperation.OperationID]
     lFullName:=FServiceOperationMap.Items[aOperation.OperationID]
-  else if LTag<>'' then
-    lFullName:=lTag+'.'+aOperation.OperationID
   else
   else
     lFullName:=FServiceOperationMap.Items[aOperation.PathComponent+'.'+aURL];
     lFullName:=FServiceOperationMap.Items[aOperation.PathComponent+'.'+aURL];
-  if lFullName='' then
+  if (lFullName='') and (aOperation.Tags.Count=1) then
+    lFullName:=ServiceNamePrefix+CleanIdentifier(aOperation.Tags[0])+ServiceNameSuffix;
+  if (lFullName='') then
     begin
     begin
     lStrings:=SplitString(aURL,'/');
     lStrings:=SplitString(aURL,'/');
     // First non-empty
     // First non-empty
@@ -976,8 +974,7 @@ begin
         S:=lStrings[i];
         S:=lStrings[i];
         S:=StringReplace(S,'{','',[rfReplaceAll]);
         S:=StringReplace(S,'{','',[rfReplaceAll]);
         S:=StringReplace(S,'}','',[rfReplaceAll]);
         S:=StringReplace(S,'}','',[rfReplaceAll]);
-        For J:=1 to Length(S)-1 do
-          if not (Upcase(S[J]) in ['A'..'Z','0'..'9','_']) then
+        S:=Sanitize(S);
         Result:=Result+'_'+S;
         Result:=Result+'_'+S;
         end;
         end;
       end;
       end;
@@ -1227,7 +1224,7 @@ begin
   if Result=Nil then
   if Result=Nil then
     begin
     begin
     Result:=TAPITypeData.CreateBinaryData(aContentType);
     Result:=TAPITypeData.CreateBinaryData(aContentType);
-    S:=ObjectTypePrefix+StringReplace(aContentType,'/','_',[])+'StreamData';
+    S:=ObjectTypePrefix+Sanitize(aContentType)+'StreamData';
     AddType(S,Result);
     AddType(S,Result);
     end;
     end;
 end;
 end;
@@ -1563,6 +1560,7 @@ constructor TAPITypeData.CreateBinaryData(const aContentType: string);
 begin
 begin
   Inherited Create(0,ptUnknown,'','TStream',Nil);
   Inherited Create(0,ptUnknown,'','TStream',Nil);
   FContentType:=aContentType;
   FContentType:=aContentType;
+  FBinaryData:=True;
 end;
 end;
 
 
 function TAPITypeData.AddProperty(const aApiName, aPascalName: String): TAPIProperty;
 function TAPITypeData.AddProperty(const aApiName, aPascalName: String): TAPIProperty;