ern-api-gen
v0.51.2
Published
Electrode Native API Generator
Downloads
7,051
Maintainers
Readme
ern-api-gen
This package is part of Electrode Native.
The Electrode Native API Generator creates new API projects based on a Swagger schema.
The generated code uses react-native-electrode-bridge to facilitate bi-directional message exchange between native code (Android/iOS) and JavaScript (React Native).
Usage
See the documentation and CLI help for more information:
ern create-api --help
Details
ern-api-gen
is based on code from the Swagger project, mainly version
2.X of Swagger Codegen.
Stock (Swagger) Code Generators
The three primary code generators adapted from Swagger are:
In line with the main Swagger project, all three classes extend the base class
DefaultCodegen
.
Custom (ERN) Code Generators
For the purposes of ern-api-gen
there are three custom implementations
of API code generators for native code (Java/Swift) and JavaScript:
Codegen | Base Class | Template Folder
--- | --- | ---
ErnAndroidApiCodegen
| AndroidClientCodegen
| resources/android/libraries/ern/
ErnES6ApiCodegen
| ES6Codegen
| resources/es6/libraries/ern/
ErnSwiftCodegen
| SwiftCodegen
| resources/swift/libraries/ern/
Note that ErnES6ApiCodegen
extends ES6Codegen
, not
JavascriptClientCodegen
(see next section for details).
ES6 Generator
The base class of ErnES6ApiCodegen
is the ES6Codegen
class which extends
JavascriptClientCodegen
. ES6Codegen
uses a different template directory but
otherwise does not change functionality much compared to its base class. It's
important to understand that Swagger does not have a ES6Codegen
and instead
uses conditionals in JavascriptClientCodegen
to generate ES6. The ES6
template folder of Swagger differs significantly from the one in ern-api-gen
.
This is likely due to the fact that ES6 generation was not yet available in
Swagger at the time the initial code was converted for ern-api-gen
.
History
Below is a brief summary of the significant events in this module. The information was mainly obtained from Git logs and by comparing select snapshots to historic state of swagger-codegen.
Initial version
The very first version of the content in this folder can be traced back to the
addition of the ern-message-gen
folder in 36637761
on Apr 4, 2017.
When the code was first added to the repository it had not only
gone through a Java to JavaScript conversion, but also contained other changes
and additions. Some changes in the resource files (e.g. triple curly braces)
may have been a necessity due to subtle differences of the Mustache template
engine in Java, and the mustache JavaScript package used by ern-api-gen
.
For these two reasons is it very difficult (or impossible) to determine the
exact state of the Swagger project that was used as the actual "source".
The most accurate approximations point to somewhere between v2.2.1 and
v2.2.2, with most code being closer to v2.2.1
, while a few files more
closely resemble v2.2.2
. There are more than 900 commits between the two
tags.
Rename
ern-message-gen
was renamed to ern-api-gen
on Aug 9, 2017
(0f9e0e34
). This fully replaced the previous hull-based generator from
the initial commit.
TypeScript conversion
A major update (mainly formatting) was done in 8fea575a when the rest of the Electrode Native code base was converted to TypeScript on Apr 28, 2018.
In May 2019, the JavaScript sources in ern-api-gen
were converted to
TypeScript: 92b69b9b (as well as 6d8f166a, 2e7d2327).