Skip to main content

Configuration

Pass a *Config to Init in your BeforeSuite (or to RegisterSuiteHandlers).

Full reference

Init(&Config{
// API info (required)
Title: "My API",
Version: "1.0.0",
Description: "Public REST API",
TermsOfService: "https://example.com/terms",

Contact: &ContactConfig{
Name: "API Team",
URL: "https://example.com/support",
Email: "api@example.com",
},

License: &LicenseConfig{
Name: "Apache 2.0",
URL: "https://www.apache.org/licenses/LICENSE-2.0.html",
},

ExternalDocs: &ExternalDocsConfig{
Description: "Full documentation",
URL: "https://docs.example.com",
},

// Tags shown at the top of the spec
Tags: []TagConfig{
{Name: "users", Description: "User management"},
{Name: "orders", Description: "Order operations"},
},

// Output
OutputPath: "./docs/openapi.yaml", // default: ./docs/openapi.yaml
OutputFormat: YAML, // YAML (default) or JSON

// Servers
Servers: []ServerConfig{
{URL: "https://api.example.com", Description: "Production"},
{URL: "https://staging.api.example.com", Description: "Staging"},
},

// Exclude paths from the spec (tests still run)
ExcludePaths: []string{
"/internal/*",
"/admin/health",
},

// Security schemes
SecuritySchemes: map[string]SecuritySchemeConfig{
"bearerAuth": BearerJWT(),
"apiKey": APIKeyHeader("X-API-Key"),
"apiKeyQuery": APIKeyQuery("api_key"),
"oauth2": OAuth2Implicit("https://example.com/oauth/authorize", map[string]string{
"read:users": "read users",
"write:users": "modify users",
}),
},

// Response validation
EnforceResponseValidation: true,
ValidationMode: "warn", // "fail" (default) or "warn"

// Example capture from real responses
CaptureExamples: true,
MaxExampleBytes: 0, // 0 → default cap of 16 384 bytes; set > 0 to override
Sanitizer: func(b []byte) []byte {
// redact sensitive fields before attaching to the spec
return b
},

// Parallel merge timeout (default: 30s)
MergeTimeout: 60 * time.Second,
})

Fields

API info

FieldTypeRequiredDescription
TitlestringYesAPI title
VersionstringYesAPI version (e.g. "1.0.0")
DescriptionstringHuman-readable description
TermsOfServicestringURL to terms of service
Contact*ContactConfigContact information
License*LicenseConfigLicense name and URL
ExternalDocs*ExternalDocsConfigLink to external documentation

Output

FieldTypeDefaultDescription
OutputPathstring./docs/openapi.yamlFile path for WriteSpec()
OutputFormatOutputFormatYAMLYAML or JSON

Paths and security

FieldTypeDescription
Servers[]ServerConfigServer URLs listed in the spec
Tags[]TagConfigGlobal tag definitions
ExcludePaths[]stringPaths omitted from spec generation (tests still run). Supports exact matches and * prefix wildcards, e.g. "/internal/*"
SecuritySchemesmap[string]SecuritySchemeConfigNamed security schemes

Validation

FieldTypeDefaultDescription
EnforceResponseValidationboolfalseValidate responses against the spec during tests
ValidationModestring"fail""fail" to error on violations, "warn" to log only

Example capture

FieldTypeDefaultDescription
CaptureExamplesboolfalseAttach real request/response bodies as OpenAPI examples
MaxExampleBytesint0 (= 16 384)Maximum size of a captured example body
Sanitizerfunc([]byte) []bytenilTransform body bytes before attaching (use to redact secrets)

Parallel

FieldTypeDefaultDescription
MergeTimeouttime.Duration30sHow long MergeAndWriteSpec waits for slow nodes to write partial files

Security scheme helpers

HelperProduces
BearerJWT()HTTP Bearer scheme (Authorization: Bearer <token>)
APIKeyHeader(name)API key in request header
APIKeyQuery(name)API key as query parameter
APIKeyCookie(name)API key in cookie
OAuth2Implicit(authURL, scopes)OAuth2 implicit flow