sdk

package
v0.40.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 11 Imported by: 0

README

SDK generation

generator/sdk prepares client contracts from OpenAPI and finite workflows from Arazzo. Language emitters consume that prepared contract. Generated clients do not import libopenapi or parse specifications at runtime.

The first emitter is generator/sdk/gosdk. It generates:

  • reachable models through generator/golang;
  • one shared HTTP client and security runtime;
  • resource-oriented methods such as client.Widgets.List;
  • typed success values, declared API errors, raw unknown errors, status and response headers;
  • a narrow generated helper for supported finite Arazzo workflows.

Generate a Go client

contract, err := sdk.Prepare(openAPIDocument, sdk.PrepareOptions{
    Operations: []string{"listWidgets", "getWidget"},
    Names: map[string]sdk.OperationName{
        "listWidgets": {Resource: "Widgets", Method: "List"},
        "getWidget":  {Resource: "Widgets", Method: "Get"},
    },
})
if err != nil {
    return err
}

result, err := gosdk.GenerateContract(contract, gosdk.Options{
    PackageName: "exampleapi",
})

result.Files is deterministic and caller-owned. The caller decides where to write it. result.Diagnostics contains notable model-generation decisions. Unsupported selected wire behavior returns an error naming the operation and feature; the emitter does not silently drop parameters, bodies, responses, or security requirements.

Generated runtime

The generated client accepts an absolute server URL, an injected HTTPDoer, named credentials, default headers, a response-size bound, and a timeout for the default http.Client. Configuration is copied during construction and resource methods are safe to share between goroutines. Per-call request options operate on a new request.

Security keeps OpenAPI semantics: requirement objects are alternatives (OR), while every scheme inside one object is required (AND). Bearer, Basic, API-key, OAuth/OpenID bearer-token, and mutual-TLS hooks are represented as named credentials. The default redirect policy returns a cross-origin redirect response without following it. This also prevents 307 and 308 redirects from replaying request bodies to another origin. A caller-supplied HTTP client owns its redirect and TLS policy.

The initial wire surface supports JSON request and response bodies, scalar and array path/query/header parameters using their standard styles, explicit 2xx statuses, declared JSON errors, cancellation, and bounded response buffering. Cookie parameters, object/deep-object parameters, allowReserved, form and multipart bodies, binary downloads, and streaming produce generation errors until their dedicated runtime paths land.

Optional nullable generated model fields use an opt-in double-pointer shape:

  • nil outer pointer: omit the field;
  • non-nil outer pointer containing nil: encode JSON null;
  • two non-nil pointers: encode the value, including its zero value.

The generated runtime provides Null[T] and NullableValue[T] helpers.

Finite Arazzo workflows

sdk.PrepareArazzo currently accepts one operation step with direct $inputs.<name> JSON payload bindings and simple status-code success criteria. The Go emitter turns it into a typed client method using the same generated resource operation. Unsupported workflow control flow is an error at generation time.

The finite subset is deliberately explicit: one operation step, direct input bindings for an object request body, and simple equality checks against HTTP status codes. Runtime orchestration and long-running observation remain consumer concerns rather than generated control flow.

Ownership and next work

OpenAPI remains the HTTP and schema contract. Arazzo remains the finite workflow contract. Stable runtime code is emitted once per SDK from standard-library templates; templates receive prepared values and contain no schema traversal.

The next Go increments are form/multipart, binary and streaming responses, explicit pagination mappings, and consumer observation adapters. TypeScript models are available from generator/typescript; a TypeScript SDK should reuse the prepared contract and behavior fixtures after the Go surface is proven. External SDK repositories and publication remain consumer concerns.

Documentation

Overview

Package sdk prepares language-neutral client contracts from OpenAPI documents. Language emitters consume those contracts without requiring generated clients to depend on libopenapi at runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contract

type Contract struct {
	Servers         []string
	Operations      []*Operation
	SecuritySchemes []*SecurityScheme
	Schemas         *orderedmap.Map[string, *highbase.SchemaProxy]
}

Contract is a borrowed effective view over one OpenAPI document. It retains the document's schema proxies so emitters can reuse libopenapi's model generators without introducing a second schema representation. Callers must keep the source document alive for the Contract's lifetime and should release both together. Schema traversal may warm caches on the source document.

func Prepare

func Prepare(document *highv3.Document, options PrepareOptions) (*Contract, error)

Prepare builds the effective operation contract consumed by language emitters.

type Diagnostic

type Diagnostic struct {
	Code    string
	Path    string
	Message string
}

Diagnostic reports a notable model-generation decision.

type File

type File struct {
	Path    string
	Content []byte
}

File is one deterministic generated source file.

type Operation

type Operation struct {
	ID          string
	Method      string
	Path        string
	Resource    string
	Name        string
	Summary     string
	Description string
	Servers     []string
	Parameters  []*Parameter
	RequestBody *RequestBody
	Responses   []*Response
	Security    []*SecurityRequirement
}

Operation is one effective OpenAPI operation after path-level inheritance.

type OperationName

type OperationName struct {
	Resource string
	Method   string
}

OperationName overrides the public resource and method name for an operation.

type Parameter

type Parameter struct {
	Name          string
	In            string
	Description   string
	Required      bool
	Style         string
	Explode       bool
	AllowReserved bool
	Schema        *highbase.SchemaProxy
}

Parameter is an effective operation parameter.

type ParameterBinding

type ParameterBinding struct {
	Name  string
	In    string
	Input string
}

ParameterBinding maps one OpenAPI operation parameter to one Arazzo workflow input.

type PayloadBinding

type PayloadBinding struct {
	Property string
	Input    string
}

PayloadBinding maps one JSON request property to one Arazzo workflow input.

type PrepareOptions

type PrepareOptions struct {
	Operations []string
	Names      map[string]OperationName
}

PrepareOptions selects operations and controls their public names. An empty Operations slice selects every operation with an operationId.

type RequestBody

type RequestBody struct {
	Required    bool
	Description string
	Content     *orderedmap.Map[string, *highv3.MediaType]
}

RequestBody is an operation request body.

type RequiredSecurityScheme

type RequiredSecurityScheme struct {
	Name   string
	Scopes []string
}

RequiredSecurityScheme is one named scheme and its required OAuth/OpenID scopes.

type Response

type Response struct {
	Status      string
	Description string
	Content     *orderedmap.Map[string, *highv3.MediaType]
}

Response is one declared operation response.

type Result

type Result struct {
	Files       []File
	Diagnostics []Diagnostic
}

Result contains generated files and non-fatal model-generation diagnostics.

type SecurityRequirement

type SecurityRequirement struct {
	Schemes []*RequiredSecurityScheme
}

SecurityRequirement is one OR alternative. All schemes inside an alternative are required together.

type SecurityScheme

type SecurityScheme struct {
	Name             string
	Type             string
	In               string
	ParameterName    string
	Scheme           string
	OpenIDConnectURL string
}

SecurityScheme describes how a named OpenAPI security scheme reaches a request.

type Workflow

type Workflow struct {
	ID                string
	Summary           string
	Description       string
	Operation         *Operation
	Inputs            *yaml.Node
	ParameterBindings []*ParameterBinding
	PayloadBindings   []*PayloadBinding
	SuccessStatuses   []string
}

Workflow is a finite Arazzo composition supported by a language emitter. Inputs borrows the workflow's JSON Schema node from the source Arazzo document. The initial compiler deliberately accepts one typed operation step; unsupported control flow is reported instead of being omitted.

func PrepareArazzo

func PrepareArazzo(document *higharazzo.Arazzo, contract *Contract, workflowIDs ...string) ([]*Workflow, error)

PrepareArazzo selects finite Arazzo workflows and binds their operationIds to a prepared OpenAPI contract. The current compiler supports one operation step with an object payload sourced from workflow inputs and status-code criteria.

Directories

Path Synopsis
Package gosdk emits an idiomatic, resource-oriented Go SDK from a prepared OpenAPI client contract.
Package gosdk emits an idiomatic, resource-oriented Go SDK from a prepared OpenAPI client contract.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL