Skip to content

Commit f805115

Browse files
committed
Implementing OpenAPI 3 analyzer
1 parent dca9368 commit f805115

File tree

3 files changed

+419
-28
lines changed

3 files changed

+419
-28
lines changed

Source/OpenApiGen.Builder.pas

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,11 @@ procedure TOpenApiImporter.GenerateClient;
474474
CodeType.IsInterface := True;
475475
CodeType.BaseType := TCodeTypeReference.Create('IRestClient');
476476
for Service in FMetaClient.Services do
477-
begin
478-
CodeMethod := CodeType.AddFunction(Service.ServiceName, Service.InterfaceName, mvPublic);
479-
GenerateXmlComments(CodeMethod.Comments, 'summary', Service.Description);
480-
end;
477+
if FClientUnit.FindType(Service.InterfaceName) <> nil then
478+
begin
479+
CodeMethod := CodeType.AddFunction(Service.ServiceName, Service.InterfaceName, mvPublic);
480+
GenerateXmlComments(CodeMethod.Comments, 'summary', Service.Description);
481+
end;
481482

482483
// Generate client class
483484
CodeType := TCodeTypeDeclaration.Create;
@@ -488,10 +489,11 @@ procedure TOpenApiImporter.GenerateClient;
488489
CodeType.InterfaceTypes.Add(TCodeTypeReference.Create(FMetaClient.InterfaceName));
489490

490491
for Service in FMetaClient.Services do
491-
begin
492-
CodeMethod := CodeType.AddFunction(Service.ServiceName, Service.InterfaceName, mvPublic);
493-
CodeMethod.AddSnippetFmt('Result := %s.Create(Config)', [Service.ServiceClass]);
494-
end;
492+
if FClientUnit.FindType(Service.InterfaceName) <> nil then
493+
begin
494+
CodeMethod := CodeType.AddFunction(Service.ServiceName, Service.InterfaceName, mvPublic);
495+
CodeMethod.AddSnippetFmt('Result := %s.Create(Config)', [Service.ServiceClass]);
496+
end;
495497

496498
CodeType.AddConstructor
497499
.AddSnippetFmt('inherited Create(%s.Create)', [FMetaClient.ConfigClass]);

Source/OpenApiGen.V3.Analyzer.pas

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,29 +182,29 @@ procedure TOpenApiAnalyzer.DoSolveServiceOperation(var ServiceName, ServiceDescr
182182
case Options.ServiceOptions.SolvingMode of
183183
TServiceSolvingMode.MultipleClientsFromFirstTagAndOperationId:
184184
begin
185-
// if Operation.Tags.Count > 0 then
186-
// begin
187-
// ServiceName := Operation.Tags[0];
188-
// Tag := FDocument.Tags.Find(ServiceName);
189-
// if Tag <> nil then
190-
// ServiceDescription := Tag.Description;
191-
// end
192-
// else
193-
// ServiceName := '';
194-
// OperationName := Operation.OperationId;
185+
if Operation.Tags.Count > 0 then
186+
begin
187+
ServiceName := Operation.Tags[0];
188+
Tag := FDocument.Tags.Find(ServiceName);
189+
if Tag <> nil then
190+
ServiceDescription := Tag.Description;
191+
end
192+
else
193+
ServiceName := '';
194+
OperationName := Operation.OperationId;
195195
end;
196196
TServiceSolvingMode.MultipleClientsFromXDataOperationId:
197197
begin
198-
// P := Pos('.', Operation.OperationId);
199-
// ServiceName := Copy(Operation.OperationId, 1, P - 1);
200-
// OperationName := Copy(Operation.OperationId, P + 1);
201-
// if StartsText('I', ServiceName) and EndsText('Service', ServiceName) then
202-
// ServiceName := Copy(ServiceName, 2, Length(ServiceName) - 8);
198+
P := Pos('.', Operation.OperationId);
199+
ServiceName := Copy(Operation.OperationId, 1, P - 1);
200+
OperationName := Copy(Operation.OperationId, P + 1);
201+
if StartsText('I', ServiceName) and EndsText('Service', ServiceName) then
202+
ServiceName := Copy(ServiceName, 2, Length(ServiceName) - 8);
203203
end;
204204
else
205205
// TServiceSolvingMode.SingleClientFromOperationId
206206
ServiceName := '';
207-
// OperationName := Operation.OperationId;
207+
OperationName := Operation.OperationId;
208208
end;
209209
end;
210210

0 commit comments

Comments
 (0)