amper

Amper

Amper (Api MaPpER) is a CLI that generates files for building an API wrapper, based on a sample JSON file.

Currently only the Crystal programming language is supported, but in the future, other languages will likely be added.

Greatly inspired by Z64's api_mapper.

Any null values within the sample JSON file will cause AMPER to exit with an error, as it will be unable to determine the type for that key.

Installation

TODO: Write installation instructions here

Usage

The most basic usage of amper the name of the object (in camcel case), and the location of the example JSON file, preceded by the -f flag.

$ amper Foo -f "test/files/foo.json"

This will generate a file called foo.cr within the src folder, based on the structure of the specified json file.

Other options include the -t flag to generate a test file, or a -s flag to generate a spec file.

Limitations

There are some limitations to Amper, so it's important to look through the code generated, before publishing/using it.

  • Time strings and Unix Epoch integers will be read as such, instead of being added as a Time class. If your JSON does include time, this change will have to be made manually, after the code is generated.
  • If the source JSON includes nested objects, then the key of that object will be used to generate a class name.
  • If the source JSON includes an array of objects, Amper will assume that all objects in the array are of the same format, and generate a nested class based on the first object in the array.
  • In the above-mentioned case, the class will be given a placeholder name of NestedClass with an autoincrementing integer suffix, due to their being no key to generate a class name from.

Development

TODO:

  • Add nested object processing.
  • Refactor Crystal templates to a mixin.
  • Add other languages.
  • Add Dummy lib for E2E testing.

Contributing

  1. Fork it (https://gitlab.com/HCLarsen/amper/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

amper

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 2
  • about 1 month ago
  • July 15, 2024
License

MIT License

Links
Synced at

Mon, 15 Dec 2025 22:11:13 GMT

Languages