Generate a Client from OpenAPI Definition

Using Swagger Codegen to Generate a Client from OpenAPI Definition

Swagger Codegen is a powerful tool that allows developers to generate client SDKs, server stubs, and API documentation from an OpenAPI Specification.

This guide will walk you through the steps you need to generate a client using Swagger Codegen with our public OpenAPI definition.

Prerequisites

  1. Java 8 or newer: You need a Java Development Kit (JDK) installed on your system. You can download it from the official Oracle website.
  2. Swagger Codegen: You can download the latest version of Swagger Codegen CLI jar from its GitHub repository. As mentioned in their documentation as well, there are multiple ways you can get the Swagger Codegen CLI:
    • Download Swagger Codegen CLI: Run the following command to download the Swagger Codegen CLI jar using wget:wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.44/swagger-codegen-cli-3.0.44.jar -O swagger-codegen-cli.jar
    • Alternatively, if you prefer using the CLI from a Docker image, you can do so by running the following command to pull the Swagger Codegen image from Docker Hub:docker pull swaggerapi/swagger-codegen-cli
    • If you are a Mac user, you can also use Homebrew to install the CLI:brew install swagger-codegen

Steps to Generate Client

  1. Run Swagger Codegen via jar file: Open a terminal and navigate to the directory where you have the Swagger Codegen jar file. Run the following command to generate the client:java -jar swagger-codegen-cli.jar generate -i https://api.brex.io/docs/api_docs_v2_prod.json -l yourDesiredLanguage -o ./outputDirectoryReplace yourDesiredLanguage with the language you want to generate the client in (e.g., java, python, php, etc.), and ./outputDirectory with the path where you want to save the generated client code.For Docker users: Use the following command:

    docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3 generate -i https://api.brex.io/docs/api_docs_v2_prod.json -l yourDesiredLanguage -o /local/outputDirectory

    After running the command, the generated client code will be in the specified output directory.

  2. Build and review the Generated Client: Navigate to the output directory you specified in the previous step. You will find the generated client code there. Depending on the language you chose, you will have to do extra steps that are specified in the README file inside the generated code.

How to use the Client

The README of some specific languages explains all the necessary steps for usage, including examples for every endpoint and documentation (Java, C#, Pythom, PHP, Go). We are providing an example in TypeScript, as its documentation is more limited in comparison.

For Typescript

If you want to extend the api client, you only need to import the index file and then call the necessary endpoints that you need:

import * as api from './index';


const config = new api.Configuration({
    apiKey: "YOUR API KEY"
});

const companyTest = () => {
    const responseApi = new api.V2CompanyApi(config);

    const body = {
        country: "UK",
        searchMethod: "name",
        searchValue: "test"
    };

    responseApi.company1(body).then(response => {
        console.log(response); //Handle the response
    }).catch(e => {
        console.log(e); //Handle the exception
    });
}
companyTest();

In case you want it to be used as a standalone library, you can define the package name and version and then use npm pack or npm link to save it in your local repository.

  • When using npm pack you can install your dependency as:
     npm i ../path-to/my-module-0.0.1.tgz
    

    The import is then done as

     import * as api from 'my-module';
    
  • With npm link you just run
      npm link
    

    Inside the client api, then in the package you want to use it, you run

      npm link my-module
    

Notes

  • The generated client includes everything you need to interact with the API, including models for the data, API endpoints, and even authentication code.
  • Swagger Codegen supports a wide range of programming languages. You can find the full list by running java -jar swagger-codegen-cli.jar langs.
  • If you encounter any issues or need more advanced options, refer to the official Swagger Codegen documentation.

API Endpoints list

Class Method HTTP request Description
V2ApplicationApi applicationCallback1 PUT /api/v2/application/callBack/{affectedService} Callback settings
V2ApplicationApi applicationCallback2 GET /api/v2/application/callBack Callback settings list
V2ApplicationApi applicationCallback3 GET /api/v2/application/callBack/{affectedService} Callback setting retrieval
V2ApplicationApi applicationCallback4 DELETE /api/v2/application/callBack/{affectedService} Callback setting deletion
V2CompanyApi company1 POST /api/v2/company/indexSearch Index search
V2CompanyApi company2 POST /api/v2/company/liveSearch Live search
V2CompanyApi company3 POST /api/v2/company/idSearch Id search
V2CompanyApi company4 POST /api/v2/company/dataset Dataset order
V2CompanyApi company5 GET /api/v2/company/dataset/{datasetId} Dataset retrieval
V2CompanyApi company6 POST /api/v2/company/enhanced Enhanced dataset order
V2CompanyApi company7 GET /api/v2/company/dataset Dataset list
V2CompanyApi company8 POST /api/v2/company/announcement Announcement
V2CompanyApi company9 GET /api/v2/company/announcement/{kompanyId}/{announcementId} Announcement retrieval
V2MonitorApi sMonitorGetByChangeid GET /api/v2/monitor/{monitorId}/{changeId} Monitor change retrieval
V2MonitorApi sMonitorRegister1 POST /api/v2/monitor Monitor registration
V2MonitorApi sMonitorRegister2 GET /api/v2/monitor Monitor list
V2MonitorApi sMonitorRegister3 GET /api/v2/monitor/{monitorId} Monitor retrieval
V2MonitorApi sMonitorRegister4 DELETE /api/v2/monitor/{monitorId} Monitor deletion
V2MonitorApi sMonitorSettings1 PUT /api/v2/application/monitorSettings Monitor settings
V2MonitorApi sMonitorSettings2 GET /api/v2/application/monitorSettings Monitor setting list
V2ProductApi productOrder0 GET /api/v2/product/search/{kompanyId} Product search
V2ProductApi productOrder1 GET /api/v2/product/order Product order list
V2ProductApi productOrder3 POST /api/v2/product/order Product order
V2ProductApi productOrder4 POST /api/v2/product/order/ubo UBO Discovery order
V2ProductApi productOrder4KybAssist POST /api/v2/product/order/kybAssist KYB Assist order
V2ProductApi productOrder4LandRegister POST /api/v2/product/order/landRegister Land Register order
V2ProductApi productOrder5 GET /api/v2/product/order/{orderId} Product order retrieval
V2ProductApi productOrder7 PUT /api/v2/product/order/{orderId} Product order update
V2ProductApi productOrder8 GET /api/v2/product/order/{orderId}/content Product content retrieval
V2SystemApi system1 GET /api/v2/system/countries Enabled countries
V2SystemApi system2 GET /api/v2/system/health Health status
V2SystemApi system3 GET /api/v2/system/priceList Price list
V2SystemApi system4 GET /api/v2/system/catalog/{countryCode} Product catalog
V2SystemApi system5 GET /api/v2/system/monitorChangeTypes Monitor change types
V2SystemApi system6 GET /api/v2/system/uboLegalTypes UBO Discovery legal types
V2VerificationApi verificationEinVerification1 POST /api/v2/verification/ein EIN validation
V2VerificationApi verificationIbanValidationV2 POST /api/v2/verification/iban IBAN validation
V2VerificationApi verificationIsin POST /api/v2/verification/isin ISIN validation
V2VerificationApi verificationLeiValidation1 POST /api/v2/verification/leiValidation LEI validation
V2VerificationApi verificationLeiValidation2 GET /api/v2/verification/leiValidation/{validationId} LEI validation retrieval
V2VerificationApi verificationLeiValidation3 GET /api/v2/verification/leiValidation LEI validation list
V2VerificationApi verificationTinVerification1 POST /api/v2/verification/tin TIN validation
V2VerificationApi verificationVatPost1 POST /api/v2/verification/vat VAT validation