Skip to main content

Generating Clients for the Telemetr.io API with Swagger Codegen

This document outlines how to use Swagger Codegen to generate client libraries for various programming languages from the Telemetr.io API OpenAPI specification located at https://api.telemetr.io/api-docs/openapi.json.

Prerequisites:

Supported Languages:

Swagger Codegen supports numerous languages. Here are some popular options:

  • Node.js (TypeScript)
  • Python
  • PHP
  • Java
  • Ruby
  • C#
  • Go
  • Swift
  • Kotlin
  • R
  • And many more...

Instructions:

  1. Open a terminal.
  2. Download swagger codegen cli.
  3. Generate client for each language:

Replace telemetrio-client with your desired output directory name and adjust the language tag (-l) accordingly.

Download swagger-codegen-cli.jar

download.sh
curl https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.52/swagger-codegen-cli-3.0.52.jar --output swagger-codegen-cli.jar

List of supported languages

java -jar swagger-codegen-cli.jar langs     
Available languages: [dart, aspnetcore, csharp, csharp-dotnet2, go, go-server, 
dynamic-html, html, html2, java, jaxrs-cxf-client, jaxrs-cxf, inflector,
jaxrs-cxf-cdi, jaxrs-spec, jaxrs-jersey, jaxrs-di, jaxrs-resteasy-eap,
jaxrs-resteasy, java-vertx, micronaut, spring, nodejs-server,
openapi, openapi-yaml, kotlin-client, kotlin-server, php, python, python-flask,
r, ruby, scala, scala-akka-http-server, swift3, swift4, swift5, typescript-angular,
typescript-axios, typescript-fetch, javascript]

General Command:

java -jar swagger-codegen-cli.jar generate \
-i https://api.telemetr.io/api-docs/openapi.json \
-l YOUR_LANGUAGE \
-o telemetrio-client

Examples:

Node.js (TypeScript):

java -jar swagger-codegen-cli.jar generate \
-i https://api.telemetr.io/api-docs/openapi.json \
-l typescript-fetch \
-o telemetrio-node-client

Python:

java -jar swagger-codegen-cli.jar generate \
-i https://api.telemetr.io/api-docs/openapi.json \
-l python \
-o telemetrio-python-client

Java:

java -jar swagger-codegen-cli.jar generate \
-i https://api.telemetr.io/api-docs/openapi.json \
-l java \
-o telemetrio-java-client

Ruby:

java -jar swagger-codegen-cli.jar generate \
-i https://api.telemetr.io/api-docs/openapi.json \
-l ruby \
-o telemetrio-ruby-client

R:

java -jar swagger-codegen-cli.jar generate \
-i https://api.telemetr.io/api-docs/openapi.json \
-l r \
-o telemetrio-r-client

Further Customization:

  • Explore additional options offered by Swagger Codegen to customize the generated code. Refer to the Swagger Codegen documentation for details: https://swagger.io/tools/swagger-codegen/
  • For advanced users, modify the generator templates to tailor the code further.

Using the Generated Clients:

  • Each generated client library will typically include:
    • Classes or functions representing API endpoints.
    • Models for data types used in requests and responses.
    • Authentication configuration methods (if applicable).
  • Refer to the specific documentation within the generated code for detailed usage instructions.

Node.js (TypeScript) generated client usage example:

channels-search-example.ts
import {Configuration, ChannelsApi} from './telemetrio-node-client';

const config = new Configuration({
apiKey: 'YOUR_API_KEY'
});

let channels = new ChannelsApi(config);

channels.search("telegram").then(rs => {
console.log(rs);
})

Additional Resources:

I hope this expanded documentation provides a clearer understanding of generating clients for various languages with Swagger Codegen. Feel free to ask if you have any further questions!