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 generated class and any enclosing modules (in camel case), and the location of the example JSON file.

$ amper Wrapper::Foo "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. If you wish to give the file a different name or location, you can use the -c flag, as so:

$ amper Foo "test/files/foo.json" -c "src/bar/foo.json"

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

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

This command generates a spec file located at spec/foo_spec.cr. The location and filename can be customized by providing the file path immediately after the -s flag.

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

This command generates a spec file located at test/foo_test.cr. As with the spec flag, you can also provide a custom file path for the generated 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, the class will be given a placeholder name of NestedClass with an autoincrementing integer suffix, due to there being no key to generate a class name from.
  • If the objects in the abovementioned case have individual variations, then Amper will attempt to consolidate those objects into a single class definition.
  • If an array is composed of objects and simple values, then Amper will fail with an error.

Development

TODO:

  • Add test generators.
  • Add spec generators.

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 9 hours ago
  • July 15, 2024
License

MIT License

Links
Synced at

Thu, 08 Jan 2026 03:15:49 GMT

Languages