sgcOpenAPI Stop hand-writing REST clients. Spec in, Pascal out.

Point sgcOpenAPI at an OpenAPI 3.x document. The parser reads it, the generator emits a native Object Pascal SDK, and the OpenAPI server component publishes your own endpoints back out as a live spec.

  • OpenAPI 3.0 and 3.1
  • JSON and YAML
  • Swagger 2.0 auto-converted
  • Delphi 7 to RAD Studio 13
  • C++ Builder
  • 1,195+Pre-built cloud SDKs, generated from the official specifications
  • 280+Amazon AWS services
  • 650+Microsoft Azure services
  • 250+Google Cloud services
  • 15+Microsoft Graph SDKs
Watch it run

See sgcOpenAPI in two minutes.

A specification in, Pascal out, and a server at either end. Narrated and captioned. Nothing downloads until you press play.

sgcOpenAPI quickstart

Turn a specification into Delphi code, and turn Delphi code into a running server.

  1. Generate a clientGive the command line an input specification and an output Pascal file. The input can be a file or a URL, JSON or YAML.
  2. What comes outOrdinary Pascal: every operation becomes a method, every schema becomes a class. Add -s for a server skeleton instead.
  3. Spec-First serverCreate TsgcWSAPIServer_OpenAPI, LoadFromFile, handle OnRequest, assign it to your server and go Active.
  4. Code-First serverAnnotate a Delphi class with attributes and the specification is generated from the class at startup.
  5. ValidationSwitch on ValidateRequest and ValidateRequestBody and a request that does not match the specification never reaches your code.
Pre-built SDK library

Four clouds, already in Pascal.

You do not have to generate anything to get started. The four largest cloud platforms ship as ready-to-use Pascal SDKs inside sgcOpenAPI, generated from the official specifications and kept up to date.

Amazon AWS, 280+ services

REST service SDKs covering S3, EC2, Lambda, DynamoDB, SQS, SNS, CloudFormation and more. Drop the unit into the project and call the service with typed request and response classes.

View AWS SDKs →

Microsoft Azure, 650+ services

The largest set in the library. Azure VMs, Blob Storage, Functions, Cosmos DB, Key Vault and the rest of the Azure control plane, each one a generated Pascal client.

View Azure SDKs →

Google Cloud, 250+ services

Compute Engine, Cloud Storage, BigQuery, Pub/Sub, Cloud Functions and more.

View Google SDKs →

Microsoft Graph, 15+ SDKs

Office 365, Microsoft Teams, OneDrive, Outlook and Active Directory, through the Graph API.

View Microsoft SDKs →

Any other spec

If the API publishes an OpenAPI or Swagger document, the generator turns it into the same kind of typed Pascal unit. There is no allow list.

Generator features →

Every tier, everything included

Single, Team and Site all bundle the parser, the code generator, the OpenAPI server component and the whole pre-built SDK library. Nothing is sold separately.

All pre-built SDKs →

Worked guides, from a public specification to a compiling Delphi client

The pipeline

Spec in, compiling code out.

Five steps, all of them inside the IDE. No Node.js, no Java code generator, no template engine to learn.

# one input, one output, and you have a unit
> sgcOpenAPI.exe -i "api.github.com.json" -o "github.pas" -a 2

File successfully created github.pas

# -a 2 wires up token auth   -u sets the base url
# -x drops operations        -p prunes the classes they used
# -s emits a server stub instead of a client
# exit 0 ok, 5 bad input, 6 bad output, 7 not convertible
uses
  github;  // the unit you just generated

procedure TForm1.btnReposClick(Sender: TObject);
var
  oResponse: TsgcOpenAPI_reposlistforauthenticateduser_Response;
  oRepo: TsgcOpenAPI_repository_Class;
begin
  GetOpenAPIClient.Authentication.Token.BearerToken := 'ghp_...';

  oResponse := GetOpenAPIClient.reposlistforauthenticateduser(
    'private', 'owner', 'all', 'full_name', '', 100, 1);
  try
    if oResponse.IsSuccessful then
      for oRepo in oResponse.Successful.Items do
        Memo1.Lines.Add(oRepo.Full_name)
    else
      Memo1.Lines.Add(IntToStr(oResponse.ResponseCode) + ' ' +
        oResponse.ResponseError);
  finally
    oResponse.Free;
  end;
end;
uses
  sgcHTTP_Server, sgcHTTP_OpenAPI_Server, sgcWebSocket_Server_API_OpenAPI;

procedure TForm1.btnStartClick(Sender: TObject);
begin
  FServer := TsgcHTTPServer.Create(Self);
  FServer.Port := 8080;

  FOpenAPI := TsgcWSAPIServer_OpenAPI.Create(Self);
  FOpenAPI.OpenAPIOptions.Endpoint.ServeSpec := True;
  FOpenAPI.OpenAPIOptions.Endpoint.ServeSwaggerUI := True;
  FOpenAPI.OpenAPIOptions.Validation.ValidateRequest := True;
  FOpenAPI.LoadFromFile('petstore.json');
  FOpenAPI.OnRequest := OnOpenAPIRequest;
  FOpenAPI.Server := FServer;

  FServer.Active := True;
end;

// one event, dispatched by operation id
procedure TForm1.OnOpenAPIRequest(Sender: TObject;
  const aOperationId: string;
  const aContext: TsgcOpenAPIServerContext;
  var Handled: Boolean);
begin
  Handled := True;
  if aOperationId = 'getPetById' then
    aContext.RespondJSON(200,
      FPets.Values[aContext.PathParamAsString('petId')])
  else
    Handled := False;
end;
  1. Point it at a specPoint -i at a local file or a URL, in JSON or YAML. Both are read locally, and a Swagger 2.0 document is converted to OpenAPI 3 locally as well.
  2. ParseTsgcOpenAPI reads the document into Paths, Components, Security, Servers, Tags and Info, and records everything it could not honour in Warnings. External $ref pointers are pulled in beforehand by TsgcOpenAPI_Bundle.
  3. GenerateTsgcOpenAPI_Parser_Client_Pascal descends from that reader and writes one Pascal unit: one method per operation, one response class per method, and a class for every schema, with the descriptions from the document as comments.
  4. CompileAdd the generated unit to the project and put it in a uses clause. Nothing else has to be on the library path but the sgcOpenAPI Source folder, on Delphi 7 through RAD Studio 13. Typed responses need XE7 or later.
  5. CallCall GetOpenAPIClient, set the credentials on Authentication, and call the operation. The base URL is already baked in from the servers entry of the document.

The generator descends from the reader, so you can also create TsgcOpenAPI yourself, walk the parsed model and build your own tooling on top of it. The parser component →

The server side

Serve the spec, do not just consume it.

TsgcWSAPIServer_OpenAPI attaches to a TsgcHTTPServer, routes incoming requests against the document you loaded, validates them before your handler runs, and serves the document and a Swagger UI from the same port.

Spec-First: a Delphi unit loads petstore.json into TsgcWSAPIServer_OpenAPI and the route table is built from the specification.

What that gives you

GET /pets/{petId} reaches your OnRequest handler with aOperationId set to getPetById. GET /openapi.json returns the document you loaded and GET /docs opens Swagger UI, both of them switched on by Endpoint.ServeSpec and Endpoint.ServeSwaggerUI. Endpoint.BasePath moves the pair under a prefix.

Code-First: a Delphi class annotated with sgcServiceContract, sgcRoute and sgcHttpGet attributes, and the OpenAPI document generated from it at startup.

Spec-first or code-first

Load a JSON contract with LoadFromFile and dispatch on the operation id, or annotate a Pascal class with sgcServiceContract, sgcHttpGet, sgcRoute and sgcFromBody and let TsgcOpenAPICodeFirstScanner build the document. Code-First needs Delphi XE7 or later. Both demos ship in Demos\30.Server\.

Validation: requests that do not match the specification are answered with 400 Bad Request before the OnRequest handler runs.

Validation before your handler runs

Validation.ValidateRequest, ValidateRequired and ValidateRequestBody check the incoming request against the document before your handler runs. OnValidationError hands you the operation id and the list of failures, and a Continue flag that decides whether the request is rejected.

The request context: path, query and body parameters already parsed, and the response code, content type and text set in the handler.

Auth wired up from the spec

The securityScheme entries in the document drive OnValidateAPIKey, OnValidateBasic and OnValidateBearer. You write the credential lookup, the component parses the request and answers with the right status when the lookup says no.

  • API Key
  • HTTP Basic
  • Bearer
  • JWT
  • OAuth2
  • OpenID Connect
  • Swagger UI

The server runs on the same sgcWebSockets HTTP server that hosts your WebSocket endpoints and static files. One port, one TLS certificate, one logging stream. The OpenAPI server component →

Licensing

One product, three tiers.

One bundled product for Delphi and C++ Builder: an OpenAPI 3.x parser, a native Pascal SDK generator, an OpenAPI server component, and 1,195+ pre-built cloud SDKs. Full source, royalty-free deployment. Choose by team size.

Single

One developer. Parser, generator, server component and every pre-built SDK.

€399 / 1 developer

Team

Two developers. The same complete product as Single.

€649 / 2 developers

Site

Unlimited developers. The same complete product as Single.

€1,099 / unlimited developers

sgcOpenAPI is licensed on its own. Parser, code generator, server component and all 1,195+ pre-built SDKs are included in every tier.

Compare tiers and prices
Testimonials

What Developers Say

Trusted by Delphi, C++ Builder, Lazarus and .NET developers around the world.

Your sgcWebSockets library is very useful and easy to setup. Keep up the good work!
Simone Moretti Delphi Developer
sgcWebSockets is amazing and your support is the best!
Christian Meyer Founder & CTO
Thanks so much for your help and support, I love your components.
Mark Steinfeld CTO

Generate your first Pascal SDK today.

Parser, code generator, OpenAPI server component and all 1,195+ pre-built cloud SDKs, on one licence. Full source, royalty-free deployment, Delphi 7 through RAD Studio 13.

Latest from the blog

View all posts →

You are seeing the sgcOpenAPI view of eSeGeCe.

Show me another angle →
30-Day Money-Back GuaranteeNot satisfied? Request a full refund within 30 days of purchase. See refund policy