By Admin on Monday, 09 February 2026
Category: All

OpenAPI Parser Library

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:

  1. Read an OpenAPI input from a local file path or URL.
  2. Normalize the document when needed (for example YAML or older Swagger formats).
  3. Build Pascal source code based on parser options.
  4. Write the generated unit to the output file path.
  5. 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

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


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


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

  1. Call CreateOpenAPIPascalFile for default behavior, or CreateOpenAPIPascalFileEx for advanced control.
  2. Check the Boolean return value.
  3. If result is False, call GetOpenAPILastErrors immediately and log/report the message.

Enter your text here ...