Electrode Native API Generator

0.54.0 · active · verified Wed Apr 22

ern-api-gen is a foundational component of the Electrode Native ecosystem, designed to automate the creation of React Native API projects. It processes a Swagger (OpenAPI 2.x) schema to generate client-side API code for JavaScript (React Native), Android (Java), and iOS (Swift). This generated code leverages `react-native-electrode-bridge` to enable robust bi-directional message exchange between the native and JavaScript layers. While built upon the principles of Swagger Codegen 2.x, `ern-api-gen` introduces custom generators like `ErnAndroidApiCodegen` and `ErnES6ApiCodegen`, specifically adapted for Electrode Native's architecture and differing significantly in ES6 generation compared to upstream Swagger. Currently at version 0.54.0, the package maintains an active development pace, frequently releasing updates to ensure compatibility with evolving React Native versions (e.g., 0.81) and addressing various build and dependency-related issues. Its primary role is as a command-line interface (CLI) tool, deeply integrated into the Electrode Native CLI for streamlined API project scaffolding within a monorepo-like development workflow.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the canonical command-line interface usage of `ern-api-gen` via the Electrode Native CLI to generate a new API project from a Swagger/OpenAPI schema.

/* 
  The primary way to use ern-api-gen is via the Electrode Native CLI.
  First, ensure you have the Electrode Native CLI installed globally:
  npm install -g ern-cli

  Then, in your terminal, use the `ern create-api` command.
  Replace `path/to/your/swagger.json` with your actual OpenAPI/Swagger schema file path.
  Replace `MyAwesomeApi` with your desired API name.
*/

const SCHEMA_FILE_PATH = 'path/to/your/swagger.json'; // e.g., './api-spec/my-service.json'
const API_NAME = 'MyAwesomeApi'; // This will be the name of your generated API package

console.log(`
To generate a new Electrode Native API project named '${API_NAME}'
from your Swagger/OpenAPI schema located at '${SCHEMA_FILE_PATH}',
run the following command in your terminal:
`);

console.log(`ern create-api ${API_NAME} --schemaPath ${SCHEMA_FILE_PATH}`);

console.log(`
This will create a new directory named '${API_NAME}' containing the generated
JavaScript (React Native), Android, and iOS client code, along with models.
`);

console.log(`
After generation, you can publish the created API project to npm.
For more details, refer to the official Electrode Native documentation:
https://native.electrode.io/cli-commands/create-api
`);

view raw JSON →