Skip to main content

Generate Code

This article introduces how to use Apidog to generate code for various languages and frameworks.

Based on API definitions, Apidog supports automatic generation of Server Stubs & Client SDKs code for various languages and frameworks, including but not limited to TypeScript, Java, Go, Swift, ObjectiveC, Kotlin, Dart, C++, C#, Rust and other 130 languages and frameworks.

Auto-generated Server Stubs & Client SDKs code include Model, Controller, unit test code, and so on. Standard-compliant API request code can be quickly generated in the API design page without manual writing, ensuring that the generated code is consistent with the API model definition.

Not only that, but you can also use the Custom Code Templates feature to generate code that conforms to your team's architectural specifications to meet a variety of individual needs.

info

The features of Apidog's code templates are based on OpenAPI Generator but have been further simplified. You can refer to this Youtube Video to learn more about the rules of OpenAPI generator templates.

Generate Client Code

API request code is used to initiate API requests in various development environments. Click the Generate API Request Code button on the right side of the Documentation tab in the API.

You can generate code by clicking the code icon in the Run tab in the API.

You can quickly select code from different environments in the code generation page.

Generate Server Stubs & Client SDKs Code

Server stubs and client SDKs code refer to the source code that implements a business logic, which is one of the most important components of a system, usually runs on a server, and is responsible for implementing business requirements, data processing, and logic control.

Prerequisites

1. Apidog plugin

2. Java environment

Before exporting server stubs and client SDKs code, the plug-in must be installed on your operation system.

Generate Specify Endpoint's Server Stubs & Client SDKs

On the "Endpoints" page, hover over the "Generate Code" button and click the "Generate Server Stubs & Client SDKs" button.

You can also move your mouse to an endpoint or directory in the left menu bar, right-click, and select "Generate Server Stubs & Client SDKs" from the popup menu.

Click the "Download and Install" button in the pop-up page.

In the pop-up page, choose the specific language code that you need. You can chose to generate code for all endpoints or select specific ones through tags.

Apidog custom templates simplify the use of custom code generation template directories, avoiding the need to deal with command-line issues. It is based on the OpenAPI Generator internally, so you can refer to relevant tutorials for guidance.

  1. Fully customizing is costly: It is recommended to start by modifying the official templates. There are many reference custom template variables available: openapi-generator/samples/server/petstore at master · OpenAPITools/openapi-generator, such as the Springboot 3 template: openapi-generator/samples/server/petstore/kotlin-springboot-3 at master · OpenAPITools/openapi-generator.
  2. Community tutorials: It is recommended to watch video tutorials first for easier onboarding: Video Tutorial.

General Steps:

  1. Download the template you want to override to a directory, for example, directory A.
  2. Modify the template according to the video tutorials and guidelines OpenAPI Generator Templating.
  3. When generating code in the GUI, select Custom Template and choose directory A.

Generate the data model code

Data model code is used to define schemas, and is commonly used for serialization when APIs send data and deserialization processing when data is received. After the SQL code type is generated, you can also define table creation statements in the database table creation scenario to create data tables in the database.

To access the data model, tap the Generate Code option in the model page.

Model code supports multiple code types.

Full list of code types:

C#C++CrystalDartElmFlow
GoHaskellJavaJavaScriptKotlinObjective-C
PikePythonRubyRustSQLSwift
TypeScriptPHPScala3SmithyTypeScript ZodTypeScript Effect Schema
info

The list of langues that Apidog supports grows periodically,so the table above might be a bit behind of the current version.

SQL table creation statement

Apidog supports rapid generation of data model code, including SQL table creation statements. Click the "Generate Code" button and select the SQL code type to view the table creation statement.