sdk-tf-generation-best-practices
npx skills add https://github.com/speakeasy-api/agent-skills --skill sdk-tf-generation-best-practices
Agent 安装分布
Skill 文档
sdk-tf-generation-best-practices
Comprehensive best-practices reference for generating SDKs and Terraform providers with Speakeasy. Covers the full lifecycle: OpenAPI spec preparation, code-first extraction, generation workflows, language-specific guides, customization, and testing.
When to Use
- Generating an SDK from an OpenAPI spec
- Generating a Terraform provider from an OpenAPI spec
- Generating an MCP server from an OpenAPI spec
- Extracting an OpenAPI spec from existing code (FastAPI, Flask, Django, Spring Boot, NestJS, Hono, Rails, Laravel)
- Customizing SDK generation (hooks, auth, error handling, retries, pagination)
- Fixing OpenAPI validation errors or applying overlays
- Testing generated SDKs (integration, contract, Arazzo)
- Understanding language-specific SDK patterns (TypeScript, Python, Go, Java, C#, Ruby, PHP)
- Upgrading or bumping the Speakeasy CLI version in workflow.yaml
- Regenerating an SDK after spec or version changes
- Customizing SDK README documentation
- Adding examples to an OpenAPI spec via overlays
- Testing generated SDK endpoints
- User says: “generate SDK”, “regenerate SDK”, “update SDK”, “SDK best practices”, “terraform provider”, “generate MCP server”, “SDK customization”, “SDK testing”, “test my SDK”, “upgrade speakeasy”, “bump version”, “SDK readme”, “SDK documentation”, “add examples to spec”
How to Use
This skill contains detailed guides in the content/ subdirectory relative to this file. Read the specific guide for the user’s task rather than trying to answer from this index alone.
These guides are also accessible via the Speakeasy CLI:
speakeasy agent context [path]
To find the right guide, use the routing table below or the decision tree.
Quick Routing Table
What are you trying to do?
| Goal | Start Here |
|---|---|
| Generate an SDK from an OpenAPI spec | content/plans/sdk-generation.md |
| Generate a Terraform provider | content/plans/tf-provider-generation.md |
| Extract OpenAPI from existing code | content/code-first/[framework].md |
| Fix OpenAPI validation errors | content/spec-first/validation.md |
| Customize SDK generation | content/sdk-customization/ |
| Generate multiple SDK variants (Azure, GCP, etc.) | content/sdk-customization/multi-target-sdks.md |
| Set up a multi-SDK monorepo | content/plans/sdk-generation.md#advanced-multi-sdk-monorepos |
| Use overlay recipes (open enums, global headers) | content/spec-first/overlays.md#overlay-recipes |
| Use multi-overlay workflows | content/spec-first/overlays.md#multi-overlay-workflow-patterns |
| Track overlay changes with metadata | content/spec-first/overlays.md#overlay-metadata-tracking |
| Implement custom security (HMAC, signatures) | content/spec-first/overlays.md#custom-security-schemes-via-overlay |
| Add SDK hooks (user-agent, telemetry) | content/sdk-customization/hooks.md |
| Implement HTTP signature authentication | content/sdk-customization/hooks.md#custom-security-hook-http-signature-authentication |
| Configure SDK retries, timeouts, pagination | content/sdk-customization/runtime-configuration.md |
| Configure SDK authentication and security | content/sdk-customization/authentication-config.md |
| Customize SDK error handling | content/sdk-customization/error-handling.md |
| Persist custom code changes across regenerations | content/sdk-customization/custom-code.md |
| Generate MCP server for AI assistants | content/sdk-customization/mcp-server.md |
| Orchestrate multi-repo SDK generation | content/sdk-customization/multi-repo-workflows.md |
| Understand SDK language specifics | content/sdk-languages/[language].md |
| Add custom utilities to Python SDKs | content/sdk-languages/python.md#extending-the-sdk-with-sidecar-utilities |
| Publish Java SDK to Maven Central | content/sdk-languages/java.md#maven-central-publishing |
| Add custom code to TypeScript SDKs | content/sdk-languages/typescript.md#custom-code-regions |
| Publish TypeScript SDK to JSR (Deno) | content/sdk-languages/typescript.md#jsr-deno-publishing |
| Configure Ruby SDK with Sorbet typing | content/sdk-languages/ruby.md#sorbet-type-checking |
| Publish Ruby SDK to RubyGems | content/sdk-languages/ruby.md#rubygems-publishing |
| Configure PHP SDK with Laravel integration | content/sdk-languages/php.md#laravel-integration |
| Publish PHP SDK to Packagist | content/sdk-languages/php.md#publishing-to-packagist |
| Generate Go SDK with interfaces for testing | content/sdk-languages/go.md#interface-generation |
| Use Go SDK in Kubernetes operators | content/sdk-languages/go.md#kubernetes-operator-integration |
| Set up SDK integration tests | content/sdk-testing/integration-testing.md |
| Configure Arazzo API testing | content/sdk-testing/arazzo-testing.md |
| Disable tests for specific endpoints | content/sdk-testing/arazzo-testing.md#disabling-tests-via-overlay |
| Run AI-powered contract tests | content/sdk-testing/contract-testing.md |
| Fix ResponseValidationError at runtime | content/sdk-testing/contract-testing.md |
| Validate spec matches live API | content/spec-first/validation.md#dynamic-validation-contract-testing |
| Upgrade Speakeasy version in workflow.yaml | content/plans/sdk-generation.md#version-management |
| Bump pinned speakeasyVersion to latest | content/plans/sdk-generation.md#version-management |
| Regenerate SDK after spec or version change | content/plans/sdk-generation.md |
| Customize SDK README with documentation | content/sdk-customization/readme-customization.md |
| Add branding, examples, or guides to SDK README | content/sdk-customization/readme-customization.md |
| Add examples to OpenAPI spec via overlay | content/spec-first/overlays.md#add-examples |
| Add API-response-based examples to spec | content/spec-first/overlays.md#add-examples |
| Test SDK against live API | content/sdk-testing/integration-testing.md |
| Run contract tests for generated SDK | content/sdk-testing/contract-testing.md |
Directory Structure
content/
âââ INDEX.md # This index (SKILL.md)
âââ plans/ # Decision trees for workflows
â âââ sdk-generation.md # Full SDK generation workflow
â âââ tf-provider-generation.md
âââ code-first/ # Extract OpenAPI from code
â âââ fastapi.md
â âââ flask.md
â âââ django.md
â âââ spring-boot.md
â âââ nestjs.md
â âââ hono.md
â âââ rails.md
â âââ laravel.md
âââ spec-first/ # OpenAPI validation and fixes
â âââ validation.md
â âââ overlays.md # OpenAPI overlays and recipes
â âââ security-schemes.md
â âââ pagination.md
â âââ schemas.md
âââ sdk-languages/ # Language-specific SDK guides
â âââ python.md
â âââ typescript.md # TS: code regions, extra modules, Zod
â âââ go.md # Go: hooks, interfaces, mocks, K8s
â âââ java.md
â âââ csharp.md
â âââ ruby.md # Ruby: Sorbet typing, RubyGems publishing
â âââ php.md
âââ sdk-customization/ # Cross-language SDK customization
â âââ hooks.md # SDK hooks (UA, telemetry, custom security)
â âââ runtime-configuration.md # Retries, timeouts, pagination, servers
â âââ authentication-config.md # Global/per-op security, env vars
â âââ error-handling.md # Custom error classes and schemas
â âââ custom-code.md # Persist changes across regenerations
â âââ multi-target-sdks.md # Multiple variants from one repo
â âââ multi-repo-workflows.md # Cross-repo SDK orchestration (CI/CD)
â âââ mcp-server.md # MCP server for AI assistant integration
â âââ readme-customization.md # SDK README branding
âââ sdk-testing/ # SDK testing patterns
â âââ integration-testing.md # Integration test infrastructure
â âââ arazzo-testing.md # Arazzo API testing format
â âââ contract-testing.md # AI-powered contract testing
âââ terraform/ # Terraform provider specifics
â âââ crud-mapping.md
â âââ customization.md
â âââ testing-guide.md
â âââ publishing.md
âââ CLI_REFERENCE.md # Canonical CLI command documentation
Decision Tree: Where to Start
START
â
ââ Do you have an OpenAPI/Swagger spec?
â â
â ââ YES ââ⺠Is the spec valid?
â â â
â â ââ YES ââ⺠What do you want to generate?
â â â â
â â â ââ SDK ââ⺠plans/sdk-generation.md
â â â ââ Terraform Provider ââ⺠plans/tf-provider-generation.md
â â â
â â ââ NO/UNSURE ââ⺠spec-first/validation.md
â â
â ââ NO ââ⺠Do you have API code?
â â
â ââ YES ââ⺠What framework?
â â ââ FastAPI ââ⺠code-first/fastapi.md
â â ââ Flask ââ⺠code-first/flask.md
â â ââ Django ââ⺠code-first/django.md
â â ââ Spring Boot ââ⺠code-first/spring-boot.md
â â ââ NestJS ââ⺠code-first/nestjs.md
â â ââ Hono ââ⺠code-first/hono.md
â â ââ Rails ââ⺠code-first/rails.md
â â ââ Laravel ââ⺠code-first/laravel.md
â â
â ââ NO ââ⺠Cannot proceed without spec or code
Troubleshooting Tree
PROBLEM
â
ââ Getting ResponseValidationError at runtime?
â â
â ââ SDK types don't match server responses
â ââ Run contract tests to identify all mismatches
â â â sdk-testing/contract-testing.md
â ââ Fix spec or create overlay to correct types
â â spec-first/validation.md#dynamic-validation-contract-testing
â
ââ SDK doesn't match live API behavior?
â â
â ââ Spec may have drifted from API
â â â Run contract tests to detect drift
â â sdk-testing/contract-testing.md
â â
â ââ Third-party spec may be inaccurate
â â Validate with contract testing before trusting
â sdk-testing/contract-testing.md
â
ââ Type mismatch errors in generated SDK?
â â
â ââ At compile time ââ⺠Check spec schema definitions
â â spec-first/validation.md
â â
â ââ At runtime ââ⺠Server returns unexpected types
â â Contract testing required
â sdk-testing/contract-testing.md
â
ââ Enum value not recognized?
â
ââ API returned value not in spec enum
ââ Add missing value to spec/overlay
â â spec-first/overlays.md
ââ Or use open enums for anti-fragility
â spec-first/overlays.md#overlay-recipes
Working with Large OpenAPI Documents
OpenAPI specs can be thousands of lines. Do not load the full spec into context. Use yq (YAML) or jq (JSON) to extract only the sections you need.
# List all paths
yq '.paths | keys' spec.yaml
# Inspect a specific endpoint
yq '.paths["/users/{id}"]' spec.yaml
# List all schema names
yq '.components.schemas | keys' spec.yaml
# Inspect a specific schema
yq '.components.schemas.User' spec.yaml
# Check server URLs
yq '.servers' spec.yaml
# List all operationIds
yq '[.paths[][].operationId // empty] | unique' spec.yaml
# For JSON specs, use jq
jq '.paths | keys' spec.json
jq '.components.schemas.User' spec.json
Note: If
yq/jqaren’t available, use targetedgrepsearches instead of copying the full spec into context:grep -n 'operationId:' spec.yaml grep -n 'x-speakeasy-entity' spec.yaml
Common Workflows
Workflow A: First-Time SDK Generation
- Read
content/plans/sdk-generation.md - Run
speakeasy quickstart --skip-interactive --output console -s spec.yaml -t python -o ./sdk - SDK generated in output directory
Workflow B: Existing Codebase â SDK
- Identify framework in
content/code-first/ - Extract OpenAPI spec
- Validate with
speakeasy lint openapi --non-interactive -s spec.yaml - Fix issues using
content/spec-first/guides - Generate SDK via
content/plans/sdk-generation.md
Workflow C: SDK Customization
- Ensure
gen.yamlexists (from quickstart) - Read
content/sdk-customization/guides - Modify
gen.yaml - Regenerate with
speakeasy run -y --output console
Workflow D: Multi-Target SDK (Azure, GCP, etc.)
- Read
content/sdk-customization/multi-target-sdks.md - Configure multiple sources in
workflow.yaml - Set up target outputs to
packages/subdirectories - Create CI workflows per target
Workflow E: SDK Extensions (Hooks, Custom Methods)
- For persistent changes anywhere â
content/sdk-customization/custom-code.md - For cross-cutting concerns â
content/sdk-customization/hooks.md - For predefined extension points â
content/sdk-languages/typescript.md#custom-code-regions - For complex logic â
content/sdk-languages/typescript.md#extra-modules-pattern
Workflow F: Upgrade and Regenerate
- Check current
speakeasyVersionin.speakeasy/workflow.yaml - Update
speakeasyVersiontolatestor a specific version âcontent/plans/sdk-generation.md#version-management - Regenerate with
speakeasy runâcontent/plans/sdk-generation.md - Test the regenerated SDK â
content/sdk-testing/integration-testing.mdorcontent/sdk-testing/contract-testing.md - Commit changes
Essential CLI Commands
| Command | Purpose |
|---|---|
speakeasy quickstart --skip-interactive --output console -s spec.yaml -t python -o ./sdk |
Non-interactive SDK setup |
speakeasy run -y --output console |
Regenerate SDK from gen.yaml |
speakeasy lint openapi --non-interactive -s spec.yaml |
Validate OpenAPI spec |
speakeasy auth login |
Authenticate with Speakeasy |
Getting Help
- Authentication issues: Run
speakeasy auth login - Validation errors: See
content/spec-first/validation.md - Unsupported feature: Check language guide in
content/sdk-languages/ - CLI errors: See
content/CLI_REFERENCE.mdor runspeakeasy --help
Providing Feedback
If you encounter missing documentation, unclear instructions, or incorrect examples in this agent context, submit feedback directly:
# General feedback
speakeasy agent feedback -m "Description of the issue or suggestion"
# Feedback about a specific document
speakeasy agent feedback -m "Description of the issue" --context-path "path/to/document.md"
Feedback helps improve these documents for all agents. Submit feedback when:
- A guide is missing steps needed to complete a task
- An example does not work as documented
- A CLI command behaves differently than described
- You cannot find documentation for a supported feature
Related Skills
start-new-sdk-project– Quick interactive setup withspeakeasy quickstartregenerate-sdk– Re-run generation after config changesvalidate-openapi-spec– Lint and validate OpenAPI specsdiagnose-generation-failure– Troubleshoot failed generation runscreate-openapi-overlay– Create overlays for spec customizationfix-validation-errors-with-overlays– Fix lint errors with overlays