From sgcOpenAPI Parser 2026.2.0 the Delphi Parser supports using a library instead of a GUI executable. The OpenAPI Parser can be used as a shared library (DLL) so you can generate Pascal clients from your own applications without invoking the command line tool. The library exports a small set of functions that wrap the same parser features available in the CLI.
This article explains how to integrate the OpenAPI parser through the DLL interface and generate Delphi/Pascal client units programmatically. It focuses only on the three exported functions that are required for integration: CreateOpenAPIPascalFile, CreateOpenAPIPascalFileEx, and GetOpenAPILastErrors.
How the DLL integration works
The parser DLL encapsulates the same conversion and generation pipeline used by the command-line tool:
- Read an OpenAPI input from a local file path or URL.
- Normalize the document when needed (for example YAML or older Swagger formats).
- Build Pascal source code based on parser options.
- Write the generated unit to the output file path.
- Return True on success, or False on failure.
When a function returns False, call GetOpenAPILastErrors immediately to retrieve diagnostic details for logging or UI feedback.
Exported methods
- CreateOpenAPIPascalFile - creates a Pascal client file from an OpenAPI specification using default options.
- CreateOpenAPIPascalFileEx - creates a Pascal client file with full control over parser options.
- GetOpenAPILastErrors - returns the last error message produced by the parser.
CreateOpenAPIPascalFile
Generates a Pascal client file using the default parser options (generate classes, JSON support, documentation, method names from OperationId, no authentication, no base URL override).
Parameters
- aInputFile: full path (or URL) of the OpenAPI specification to parse. If the file is YAML or Swagger 1/2, the parser will normalize it to OpenAPI 3 JSON before generating the output.
- aOutputFile: full path of the Pascal unit to create.
Return value
Returns True if the file is generated successfully, otherwise False. If it fails, call GetOpenAPILastErrors to retrieve the error message.
Example
if not CreateOpenAPIPascalFile('c:\specs\openapi.json', 'c:\clients\orders.pas') then ShowMessage(GetOpenAPILastErrors);
CreateOpenAPIPascalFileEx
Use CreateOpenAPIPascalFile when you want a fast integration with standard output and you do not need to tune generation behavior.
Parameters
- aOutputFile: full path of the Pascal unit to create.
- aGenerateClasses: when True, the generator creates the Pascal models (classes) defined in the schema. When False, only the client interface is generated.
- aGenerateJSON: when True, JSON serialization helpers are generated in the classes. When False, JSON support is omitted.
- aGenerateDocumentation: when True, a documentation file for the OpenAPI specification is generated.
- aMethodsName: controls how method names are generated:
- 0 = OperationId (default).
- 1 = Summary.
- 2 = Endpoint.
- aAuthentication: adds authentication helpers to the client:
- 0 = None.
- 1 = Basic.
- 2 = Token.
- 3 = OAuth2.
- 4 = JWT.
- aBaseURL: override the base URL from the OpenAPI specification. Pass an empty string to keep the original value.
- aEnableLog: when True, the parser writes progress and validation messages that can help with troubleshooting.
Return value
Returns True if the file is generated successfully, otherwise False. If it fails, call GetOpenAPILastErrors to retrieve the error message.
Example: OAuth2 client with explicit base URL and logging
if not CreateOpenAPIPascalFileEx( 'c:\specs\openapi.json', 'c:\clients\orders.pas', True, True, True, 0, 3, 'https://api.example.com/v2', True) then ShowMessage(GetOpenAPILastErrors);
GetOpenAPILastErrors
Returns a message describing the last error (validation, conversion, or parsing error) produced by the parser. Call this function after CreateOpenAPIPascalFile or CreateOpenAPIPascalFileEx returns False.
Return value
A null-terminated string with the last error message. If no error has occurred, the string can be empty.
Recommended Call Sequence
- Call CreateOpenAPIPascalFile for default behavior, or CreateOpenAPIPascalFileEx for advanced control.
- Check the Boolean return value.
- If result is False, call GetOpenAPILastErrors immediately and log/report the message.
Enter your text here ...