A small library for validating OpenAPI specs independently of the Swagger Editor - and independently of JavaScript.
Originally extracted from a branch of mimicry as this might be useful to others.
The package can be installedby adding openapiv3_validator to your list ofdependencies in mix.exs:
def deps do
[
{:openapiv3_validator, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/openapi_validator.
The package provides the openapi v3 schema as a plain elixir struct, so you can either:
my_specification = %{}
my_specification |> OpenAPIv3Validator.valid?()
# true / false
my_specification |> OpenAPIv3Validator.validate()
# :ok | {:error, []}This uses the most excellent ex_json_schema, you can also grab the schema directly and use it with ex_json_schemas Validator:
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)