Generate an OpenAPI repository
Stainless can automatically generate and maintain a Git repository containing your OpenAPI specification and its variants.
This guide describes how to use the OpenAPI target to automatically generate and maintain a Git repository containing your OpenAPI specification and its variants.
Many teams maintain a public OpenAPI repository separate from their internal monorepo to:
- Provide a stable, public URL for their API specification
- Track and communicate API changes through Git history and commit messages
- Accept community contributions and bug reports via GitHub issues
- Integrate with documentation sites that reference the spec via
raw.githubusercontent.com
Previously, teams had to manually configure CI/CD pipelines to push generated specs to a separate repository. The OpenAPI target automates this workflow and runs on every Stainless build.
Getting started
Section titled “Getting started”Enable the OpenAPI target
Section titled “Enable the OpenAPI target”In the Studio, add openapi to your project’s targets:
targets: openapi: production_repo: nullThis will create a repository at stainless-sdks/<project>-openapi with your OpenAPI specification.
Generated files
Section titled “Generated files”By default, the OpenAPI target generates the following files based on your configuration:
openapi.jsonoropenapi.yml- Your base input specificationopenapi.with-transforms.yml- Generated whenopenapi.transformsare configured (learn more about Stainless Transforms)openapi.with-code-samples.yml- Generated whenopenapi.code_samplesare configured, adding SDK usage examples underx-codeSamples
The specific files generated depend on your Stainless configuration. If you haven’t configured transforms or code samples, only the base specification file will be generated.
Link a production repository
Section titled “Link a production repository”Once you’re ready to make your OpenAPI specification public, set up a production repository under your own organization:
- Create a new empty repository in your organization (e.g.,
my-org/petstore-openapi) - Install the Stainless GitHub App and grant it access to this repository (see linking production repos for detailed instructions)
- Update your Stainless configuration:
targets: openapi: production_repo: my-org/petstore-openapi- On your next build, Stainless will automatically push your OpenAPI specification to this repository
Customizing output files
Section titled “Customizing output files”Use targets.openapi.options.files to control exactly which files are generated and what they include:
targets: openapi: production_repo: my-org/petstore-openapi options: files: openapi.yml: with: [] openapi.with-code-samples-and-transforms.yml: with: [code-samples, transforms]Each key under files is the output filename, and the with array specifies which features to include:
code-samples- Include SDK usage examples underx-codeSamplestransforms- Include Stainless Transforms applied to your specification
Pro tip: If you’re using Stainless AI commit messages, these will automatically be included in your OpenAPI repository’s commit history, making it even easier to communicate changes to your API consumers.
Next Steps
Section titled “Next Steps”If you find a bug, have a question, or want to provide product feedback, let us know at support@stainless.com.