Current section

Files

Jump to
ash_json_api lib ash_json_api controllers schema.ex
Raw

lib/ash_json_api/controllers/schema.ex

# SPDX-FileCopyrightText: 2019 ash_json_api contributors <https://github.com/ash-project/ash_json_api/graphs/contributors>
#
# SPDX-License-Identifier: MIT
defmodule AshJsonApi.Controllers.Schema do
@moduledoc false
def init(options) do
options
end
# sobelow_skip ["XSS.SendResp"]
def call(conn, opts) do
domains = List.wrap(opts[:domain] || opts[:domains])
schema =
domains
|> AshJsonApi.JsonSchema.generate(prefix: opts[:prefix] || "")
|> Jason.encode!()
conn
|> Plug.Conn.put_resp_content_type("application/schema+json")
|> Plug.Conn.send_resp(200, schema)
|> Plug.Conn.halt()
end
end