Packages
open_api_spex
3.22.2
3.22.3
3.22.2
3.22.1
3.22.0
3.21.5
3.21.4
3.21.3
3.21.2
3.21.1
3.21.0
3.20.1
3.20.0
3.19.1
3.19.0
3.18.3
3.18.2
3.18.1
3.18.0
3.17.3
3.17.2
3.17.1
3.17.0
3.16.4
3.16.3
3.16.2
3.16.1
3.16.0
3.15.0
3.14.0
3.13.0
3.12.0
3.11.0
3.10.0
3.9.0
3.8.0
3.7.0
3.6.0
3.5.2
3.5.1
3.5.0
3.4.0
3.3.0
3.2.1
3.2.0
3.1.0
3.0.0
2.3.1
2.3.0
2.2.0
2.1.1
2.1.0
2.0.0
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.1
1.0.0
Leverage Open Api Specification 3 (swagger) to document, test, validate and explore your Plug and Phoenix APIs.
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/openapi.spec.yaml.ex
defmodule Mix.Tasks.Openapi.Spec.Yaml do
@default_filename "openapi.yaml"
@moduledoc """
Serialize the given OpenApi spec module to a YAML file.
## Examples
$ mix openapi.spec.yaml --spec PhoenixAppWeb.ApiSpec apispec.yaml
$ mix openapi.spec.yaml --spec PhoenixAppWeb.ApiSpec --check=true
$ mix openapi.spec.yaml --spec PhoenixAppWeb.ApiSpec --start-app=false
$ mix openapi.spec.yaml --spec PhoenixAppWeb.ApiSpec --vendor-extensions=false
## Command line options
* `--spec` - The ApiSpec module from which to generate the OpenAPI YAML file
* `--check` - Whether to only compare the generated YAML with the spec file (defaults to false)
* `--start-app` - Whether to start the application before generating the schema (defaults to true)
* `--vendor-extensions` - Whether to include open_api_spex OpenAPI vendor extensions
(defaults to true)
* `--quiet` - Whether to disable output printing (defaults to false)
* `--filename` - The output filename (defaults to "#{@default_filename}")
"""
use Mix.Task
require Mix.Generator
@dialyzer {:nowarn_function, encoder: 0}
@impl Mix.Task
def run(argv) do
{opts, _, _} = OptionParser.parse(argv, strict: [start_app: :boolean])
Keyword.get(opts, :start_app, true) |> maybe_start_app()
OpenApiSpex.ExportSpec.call(argv, &encode/2, @default_filename)
end
defp maybe_start_app(true), do: Mix.Task.run("app.start")
defp maybe_start_app(_), do: Mix.Task.run("app.config", preload_modules: true)
defp encode(spec, opts) do
spec
|> encoder().encode(opts)
|> case do
{:ok, yaml} ->
yaml
{:error, error} ->
Mix.raise("could not encode #{inspect(spec)}, error: #{inspect(error)}.")
end
end
defp encoder do
OpenApiSpex.OpenApi.yaml_encoder() ||
Mix.raise(
"could not load YAML encoder, please add one of supported encoders to dependencies."
)
end
end