https://github.com/zero-one-group/injecto
https://github.com/zero-one-group/injecto
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/zero-one-group/injecto
- Owner: zero-one-group
- License: mit
- Created: 2023-01-14T16:36:11.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-22T15:20:03.000Z (over 3 years ago)
- Last Synced: 2025-03-18T13:47:16.250Z (about 1 year ago)
- Language: Elixir
- Size: 22.5 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Injecto
A behaviour module that defines both an Ecto schema and a JSON schema.
An Injecto schema uses the module attribute `@properties` to define an Ecto schema and
a JSON schema based on the `ex_json_schema` library. In doing so, it also injects a
`Jason` encoder implementation. The advantage of using an Injecto schema is to get a
consistent parsing and validating with Ecto changesets and JSON schema respectively
with minimal boilerplates. This consistency is helpful when working with struct-based
request or response bodies, because we can get accurate Swagger schemas for free.
Example:
```elixir
defmodule Post do
@properties %{
title: {:string, required: true},
description: {:string, []},
likes: {:integer, required: true, minimum: 0}
}
use Injecto
end
```
Refer to the [Injecto HexDocs](https://hexdocs.pm/injecto) for a more information.
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `injecto` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:injecto, "~> 0.1.0"}
]
end
```