https://github.com/mimicry-tech/openapi_validator
A small wrapper for validating OpenAPIv3 schemata in plain elixir
https://github.com/mimicry-tech/openapi_validator
elixir openapi openapi3 validation
Last synced: about 1 month ago
JSON representation
A small wrapper for validating OpenAPIv3 schemata in plain elixir
- Host: GitHub
- URL: https://github.com/mimicry-tech/openapi_validator
- Owner: mimicry-tech
- License: apache-2.0
- Created: 2021-07-13T19:30:25.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-22T22:34:20.000Z (over 2 years ago)
- Last Synced: 2025-10-21T15:03:06.065Z (5 months ago)
- Topics: elixir, openapi, openapi3, validation
- Language: Elixir
- Homepage:
- Size: 101 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenAPIv3Validator
A small library for validating OpenAPI specs independently of the [Swagger Editor](https://editor.swagger.io) - and independently of JavaScript.
Originally extracted from a branch of [mimicry](https://github.com/mimicry-tech/mimicry) as this might be useful to others.
## Installation
The package can be installedby adding `openapiv3_validator` to your list ofdependencies in `mix.exs`:
```elixir
def deps do
[
{:openapiv3_validator, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/openapi_validator](https://hexdocs.pm/openapiv3_validator).
## Usage
The package provides the openapi v3 schema as a plain elixir struct, so you can either:
```elixir
my_specification = %{}
my_specification |> OpenAPIv3Validator.valid?()
# true / false
my_specification |> OpenAPIv3Validator.validate()
# :ok | {:error, []}
```
This uses the most excellent [`ex_json_schema`](https://hex.pm/packages/ex_json_schema), you can also grab the schema directly and use it with `ex_json_schema`s `Validator`:
```elixir
alias OpenAPIv3Validator.Schemas.OpenAPI.V3, as: V3
alias ExJson.Schema
alias ExJsonSchema.Validator
my_specification = %{
"openapi" => "3.0.0",
# ...
}
V3.schema() |> Schema.resolve |> Validator.valid?(my_specification)
```