Hi @Weetch_Russell, yes, it's possible. It's not trivial, but here is the code. First, you create a class implementing IOpenApiEvents
:
uses
System.StrUtils, XData.OpenApi.Service.Internal, OpenApi.Classes.Path,
OpenApi.Document, OpenApi.Classes.Operation, Bcl.Json.Converters, XData.Model.Classes,
type
TMyOpenApiEvents = class(TInterfacedObject, IOpenApiEvents)
public
procedure DocumentCreated(Document: TOpenApiDocument);
procedure GetDefinitionName(var DefinitionName: string; TypeToken: TTypeToken);
procedure ActionProcessed(Action: TXDataAction; Operation: TOperation; Path: TPathItem);
end;
{...}
{ TMyOpenApiEvents }
procedure TMyOpenApiEvents.ActionProcessed(Action: TXDataAction; Operation: TOperation; Path: TPathItem);
begin
end;
procedure TMyOpenApiEvents.DocumentCreated(Document: TOpenApiDocument);
begin
end;
procedure TMyOpenApiEvents.GetDefinitionName(var DefinitionName: string; TypeToken: TTypeToken);
const
Prefix = 'GFSProxyDtos.';
begin
if StartsText(Prefix, DefinitionName) then
System.Delete(DefinitionName, 1, Length(Prefix));
end;
Then you set the IOpenApiEvents
in the Sparkle context. In your XData server, add a new generic middleware, and in the OnRequest
event just use:
procedure TServerModule.XDataServer1GenericRequest(Sender: TObject; Context: THttpServerContext; Next: THttpServerProc);
begin
Context.SetItem<IOpenApiEvents>(TMyOpenApiEvents.Create);
Next(Context);
end;
I hope it helps.