CafeRacer
OpenApiSpex.Plug.RenderSpec.init/1 is undefined
Trying to use open_api_spex in my phoenix project.
When I try compiling the project with mix a warning pops us
OpenApiTest.OpenApiSpex.Plug.RenderSpec.init/1 is undefined
I have my router defined as below:
defmodule OpenApiTestWeb.Router do
use OpenApiTestWeb, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
plug OpenApiSpex.Plug.PutApiSpec, module: OpenApiTestWeb.ApiSpec
end
scope "/", OpenApiTestWeb do
pipe_through :browser
get "/", PageController, :index
get "/payments", PaymentController, :create_payment
get "/openapi", OpenApiSpex.Plug.RenderSpec, []
end
if Mix.env() in [:dev, :test] do
import Phoenix.LiveDashboard.Router
scope "/" do
pipe_through :browser
live_dashboard "/dashboard", metrics: OpenApiTestWeb.Telemetry
end
end
end
OpenApiSpex.Plug.RenderSpec module is present in the deps as below.
defmodule OpenApiSpex.Plug.RenderSpec do
defmodule MyAppWeb.Router do
use Phoenix.Router
alias MyAppWeb.UserController
pipeline :api do
plug :accepts, ["json"]
plug OpenApiSpex.Plug.PutApiSpec, module: MyAppWeb.ApiSpec
end
scope "/api" do
pipe_through :api
resources "/users", UserController, only: [:create, :index, :show]
get "/openapi", OpenApiSpex.Plug.RenderSpec, []
end
end
alias OpenApiSpex.Plug.PutApiSpec
@behaviour Plug
@json_encoder Enum.find([Jason, Poison], &Code.ensure_loaded?/1)
@impl Plug
def init(opts), do: opts
@impl Plug
def call(conn, _opts) do
{spec, _} = PutApiSpec.get_spec_and_operation_lookup(conn)
conn
|> Plug.Conn.put_resp_content_type("application/json")
|> Plug.Conn.send_resp(200, @json_encoder.encode!(spec))
end
end
Could someone kindly help?
Marked As Solved
josevalim
Creator of Elixir
Oh, I see. The issue is the scope. The scope ..., OpenApiTestWeb will nest everything inside under OpenApiTestWeb. Do this instead:
scope "/api" do
pipe_through :api
get "/openapi", OpenApiSpex.Plug.RenderSpec, []
scope OpenApiTestWeb do
....
end
end
4
Popular in Questions
Hello, how can I check the Phoenix version ?
Thanks !
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Other popular topics
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









