Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialyzer error: Function MyAppWeb.OpenApiSpex.Plug.RenderSpec.init/1 does not exist #505

Closed
Nezteb opened this issue Oct 3, 2022 · 4 comments

Comments

@Nezteb
Copy link

Nezteb commented Oct 3, 2022

Elixir: 1.14.0
Phoenix: 1.6.11

Following the docs exactly, I added the following to one of my router scopes like so:

scope "/api" do
  pipe_through :api
  resources "/users", MyAppWeb.UserController, only: [:create, :index, :show]
  get "/openapi", OpenApiSpex.Plug.RenderSpec, []
end

However, when running mix dialyzer, this gives an error:

> mix dialyzer
...
Total errors: 1, Skipped: 0, Unnecessary Skips: 0
done in 0m2.04s
lib/my_app_web/router.ex:28:unknown_function
Function MyAppWeb.OpenApiSpex.Plug.RenderSpec.init/1 does not exist.
________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2

I know this isn't actually the case, because RenderSpec.init/1 does exist when I CMD+click on it in my editor.

Dialyxir has a wiki page on using Dialyxir with Phoenix that mentions how to avoid spurious errors, but it's from 2019 and I don't know if any of it is required anymore.

Any ideas on what I might be doing incorrectly? 🤔

@mbuhot
Copy link
Collaborator

mbuhot commented Oct 3, 2022

Notice the module name: MyAppWeb.OpenApiSpex.Plug.RenderSpec.init includes your own applications module MyAppWeb as a prefix.

That suggests there's a surrounding scope "/something", MyAppWeb do in your router.

If that's the case, changing it from scope/4 to scope/3 should fix it.

edit: Updated to obfuscate module names

@Nezteb
Copy link
Author

Nezteb commented Oct 4, 2022

Ah damn.

  1. I didn't properly obfuscate the naming of my modules in this GH issue. 🤦‍♂️
  2. In the initial PR description I had copy-pasted the code snippet from the open-api-spex docs instead of my actual app, when in reality my scope block was using a different arity and passing the web module. 🤦‍♂️
  3. I didn't even realize that the initial mix phx.new I had ran generated:
  scope "/", MyAppWeb do
    pipe_through :browser

    get "/", PageController, :index
  end

Removing that module name and fully qualifying the controllers gets rid of the dialyzer error, thank you a ton!

It's probably not necessary, but would y'all accept a minor doc change PR to clarify that users adding open-api-spex might need to double check which version of scope they are using? 😅

@Nezteb Nezteb closed this as completed Oct 4, 2022
@mbuhot
Copy link
Collaborator

mbuhot commented Oct 4, 2022

It's probably not necessary, but would y'all accept a minor doc change PR to clarify that users adding open-api-spex might need to double check which version of scope they are using? 😅

Yes please!

@mbuhot mbuhot changed the title Dialyzer error: Function PlBetsWeb.OpenApiSpex.Plug.RenderSpec.init/1 does not exist Dialyzer error: Function MyAppWeb.OpenApiSpex.Plug.RenderSpec.init/1 does not exist Oct 4, 2022
@Nezteb
Copy link
Author

Nezteb commented Oct 4, 2022

Yes please!

Done! #507

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants