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

router param for a part of all my routes #288

Open
GildedHonour opened this issue Aug 11, 2023 · 1 comment
Open

router param for a part of all my routes #288

GildedHonour opened this issue Aug 11, 2023 · 1 comment

Comments

@GildedHonour
Copy link

GildedHonour commented Aug 11, 2023

There's the "router" argument

 swagger_files: %{
    "priv/static/swagger.json" => [
      router: MyAppWeb.Router,     # phoenix routes will be converted to swagger paths
      endpoint: MyAppWeb.Endpoint  # (optional) endpoint config used to set host, port and https schemes.
    ]
  }

What if I needed to create Swagger docs for only a part of all the routes in my router.ex?

Or if I had multiple APIs in it? private one, public one, something else

In other words, how will phoenix_swagger know which scope it must generate API docs for? I might name my api route-scope /my_super_route rather than /api.

Or does it use priv/static/swagger.json only and doesn't care what's in router.ex?

@WillRochaThomas
Copy link

From the 'Getting Started' guide:

The outline of the swagger document should be returned from a swagger_info/0 function defined in your phoenix Router.ex module.

defmodule MyApp.Router do
  use MyApp.Web, :router

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/api", MyApp do
    pipe_through :api
    resources "/users", UserController
  end

  def swagger_info do
    %{
      info: %{
        version: "1.0",
        title: "My App"
      }
    }
  end
end

The version and title are mandatory fields. By default the version will be 0.0.1 and the title will be <enter your title> if you do not provide swagger_info/0 function.

See the Swagger Object specification for details of other information that can be included. basePath is optional but may need to be specified if your API routes do not reside at the root location /. You can also set the description of tags here, for example:

%{
  basePath: "/api",
  info: %{..},
  tags: [%{name: "Users", description: "Operations about Users"}]
}

I haven't tested this, but have you tried setting the basePath in your swagger_info function to "/my_super_route" or whatever scope you do want to generate swagger documentation for?

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