Code generation
Generating server or client code from an API specification allows you to interact with your API specification more efficiently during development and testing. Blackbird uses OpenAPI Generator to generate code for the API description. However, you can use any of the available server or client generators. For more information, see the OpenAPI Generators List.
Using a sample template to generate code
Use a sample template to explore how Blackbird's code generation process works.
To generate code using a sample template:
Download the sample petstore.yaml file to use for testing.
(Optional but recommended) Create a basic configuration for the template. While not required, this establishes a standard setup for multiple projects. For example, you can define a configuration file for the Go server template by creating a file named
blackbird-go-server-config.yaml
with the following content.Note: These options can be overwritten for different projects using the
--gen-config-values
flag with unique values likename
orversion
. You can use multiple values by repeating the flag.Run the code generate command using one of the following options:
If you didn't create a basic configuration for the template, use the following command.
If you created a basic configuration for the template, use the
--gen-config-path
flag to specify the path to the configuration file.Apply the variables prompted by the CLI. Provide the package version and package name.
When the API project is generated, it creates a new directory with all the necessary modules and Go files for the projects, including the Dockerfile you'll use to run and debug the code.
Using an existing API in Blackbird to generate code
If you want to use an existing API in Blackbird to generate code, use one of the following options.
Generate server code
Generate server-side boilerplate code to help backend developers implement and test API routes and endpoints.
To generate the server code for the API:
Generate API client code
Generate client-side code to help frontend developers interact with and test API methods and endpoints.
To generate API client code: