Skip to content

A small wrapper for validating OpenAPIv3 schemata in plain elixir

License

Notifications You must be signed in to change notification settings

mimicry-tech/openapi_validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAPIv3Validator

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.

Installation

The package can be installedby adding openapiv3_validator to your list ofdependencies in mix.exs:

def deps do
  [
    {:openapiv3_validator, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/openapi_validator.

Usage

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)

About

A small wrapper for validating OpenAPIv3 schemata in plain elixir

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages