Redoc/Swagger: Control what Sphinx elements are included

I want to add the Sphinx info to the Swagger/Redoc but do not want to include the LoginApp elements. Is there a way to block this? thanks

Also, can Redoc be enabled?

You can enable Redoc as stated in documentation:

XDataServer1.RedocOptions.Enabled := True;

You can have full control over the generated Swagger document and eventually tweak and remove what you want from it, as described here:

The TSphinxServer does not have the RedocOptions property

re Swagger Customisation: Missed my own post :face_with_peeking_eye:

thanks

I've tried that but it doesn't seem to see the LoginApp service and methods

the definition names it sees are

Sphinx.AuthorizationService.Intf.TAuthorizationRequest
Sphinx.AuthorizationService.Intf.TTokenRequest
Sphinx.AuthorizationService.Intf.TTokenResponse
Sphinx.Discovery.Metadata.TOidcProviderMetadata
Sphinx.Entities.TDBStorageItem
Sphinx.Entities.TRole
Sphinx.Entities.TRoleClaim
Sphinx.Entities.TUser
Sphinx.Entities.TUserClaim
Sphinx.Entities.TUserRole
Sphinx.Entities.TUserToken
Sphinx.Extensions.TACUser
Sphinx.LoginAppService.Intf.TAuthorizeResponse
Sphinx.LoginAppService.Intf.TSendCodeResponse
Sphinx.LoginAppService.Intf.TTwoFactorManageRequest
Sphinx.LoginAppService.Intf.TTwoFactorManageResponse
Sphinx.LoginAppService.Intf.TUserId
Sphinx.LoginAppService.Intf.TUserInfo
Sphinx.LoginAppService.Intf.TUserRegistrationInfo
Sphinx.LoginAppService.Intf.TUserStatus

Fair enough, it's indeed not published. We will add it in next version. For now it's a protected property and in the meanwhile you can access it from code using the protected property hack.

1 Like

What did you try, exactly?

procedure TAuthModule.SphinxServerGenericRequest(Sender: TObject; Context: THttpServerContext; Next: THttpServerProc);
begin
  Context.SetItem<IOpenApiEvents>(TSphinxApiEvents.Create);
  Next(Context);
end;
procedure TSphinxApiEvents.GetDefinitionName(var DefinitionName: string; TypeToken: TTypeToken);
const
  Prefix = 'Sphinx.LoginApp';
begin
//  name_List.Add(DefinitionName);
  if StartsText(Prefix, DefinitionName) then
    System.Delete(DefinitionName, 1, Length(Prefix));

end;

You should use the DocumentCreate method, not GetDefinitionName.
Could you please provide your sample project and ask exactly what you want do (what you want to remove/modify in Swagger document), I might try to implement that for you in your demo project if it's straightforward.

I've added the code to the Auth module in the Biz-Boilerplate project attached
BIZ-Boilerplate-OpenAPI.zip (21.4 KB)

We have an App specifically for server to server API, so do not want to display any of the LoginApp stuff in the Swagger or Redoc, just the oauth and openid elements.

You can use something like this:

procedure TSphinxApiEvents.DocumentCreated(Document: TOpenApiDocument);
begin
  for var I := Document.Paths.Count - 1 downto 0 do
  begin
    if StartsText('/LoginApp', Document.Paths.Keys[I]) then
      Document.Paths.Delete(I);
  end;
end;

But I wonder why do you want to enable Swagger documents for such a simple and actually standard server. All endpoints are standard in OAuth/OpenIDConnect and automatically discoverable. That's the point of .well-known endpoint, actually.

1 Like

It just makes it simpler for developers to log in and then use the access token to test the server swagger

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.