Skip to content

Commit 2bc960c

Browse files
committed
Fixed stack overflow described in issue #8
1 parent 188647e commit 2bc960c

File tree

4 files changed

+254
-187
lines changed

4 files changed

+254
-187
lines changed

Source/OpenApiGen.CustomAnalyzer.pas

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ TOpenApiCustomAnalyzer = class
2020
FMetaClient: TMetaClient;
2121
FOptions: TBuilderOptions;
2222
FOwnsOptions: Boolean;
23+
FObjectTypes: TDictionary<string, IMetaType>;
2324
strict private
2425
FOnGetMethodName: TGetIdentifierProc;
2526
FOnGetTypeName: TGetIdentifierProc;
@@ -134,10 +135,12 @@ constructor TOpenApiCustomAnalyzer.Create(Options: TBuilderOptions; AOwnsOptions
134135
FOwnsOptions := AOwnsOptions;
135136
FLogger := TLogManager.Instance.GetLogger(Self);
136137
FMetaClient := TMetaClient.Create;
138+
FObjectTypes := TDictionary<string, IMetaType>.Create;
137139
end;
138140

139141
destructor TOpenApiCustomAnalyzer.Destroy;
140142
begin
143+
FObjectTypes.Free;
141144
FMetaClient.Free;
142145
if FOwnsOptions then
143146
FOptions.Free;
@@ -239,8 +242,12 @@ function TOpenApiCustomAnalyzer.MetaTypeFromObject(const Name: string; Schema: T
239242
MetaProp: TMetaProperty;
240243
begin
241244
DoGetTypeName(TypeName, Name);
245+
if FObjectTypes.TryGetValue(TypeName, Result) then
246+
Exit;
247+
242248
ObjType := TObjectMetaType.Create(TypeName);
243249
Result := ObjType;
250+
FObjectTypes.Add(TypeName, Result);
244251
ObjType.SetDescription(Schema.Description);
245252
for SchemaProp in Schema.Properties do
246253
begin

Source/OpenApiGen.V3.Analyzer.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ function TOpenApiAnalyzer.GetBaseUrl: string;
292292
if Pos('://', Result) = 0 then
293293
begin
294294
if Options.DocumentUrl = '' then
295-
raise Exception.Create('Cannot determine the URL of the API spe, please provide it using DocumentUrl param');
295+
raise Exception.Create('Cannot determine the URL of the API spec, please provide it using DocumentUrl param');
296296
Result := Options.DocumentUrl + Result;
297297
end;
298298
end;

Tests/OpenApiDelphiGenTests.dpr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ uses
2323
PetStoreDtos in 'PetStore\PetStoreDtos.pas',
2424
PetStoreJson in 'PetStore\PetStoreJson.pas',
2525
PetStoreClient in 'PetStore\PetStoreClient.pas',
26-
NuvemFiscalJson in 'S:\nuvem-fiscal\nuvemfiscal-sdk-delphi\Source\NuvemFiscalJson.pas',
27-
NuvemFiscalClient in 'S:\nuvem-fiscal\nuvemfiscal-sdk-delphi\Source\NuvemFiscalClient.pas',
28-
NuvemFiscalDtos in 'S:\nuvem-fiscal\nuvemfiscal-sdk-delphi\Source\NuvemFiscalDtos.pas',
2926
OpenApiUtils in '..\Dist\OpenApiUtils.pas',
3027
PetStore3Client in 'PetStore3\PetStore3Client.pas',
3128
PetStore3Dtos in 'PetStore3\PetStore3Dtos.pas',

0 commit comments

Comments
 (0)