Skip to content

Hot to remove/move general scope prefix from paths #339

Answered by mbuhot
ycherniavskyi asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @ycherniavskyi, you should be able to adjust the paths by transforming the output of Paths.from_router/1 when you build the %OpenApi{} struct.

Something like:

defmodule MyAppWeb.ApiSpec do
  alias OpenApiSpex.{Components, Info, OpenApi, Paths, Server}
  alias MyAppWeb.{Endpoint, Router}
  @behaviour OpenApi

  @impl OpenApi
  def spec do
    %OpenApi{
      servers: [
        %{Server.from_endpoint(Endpoint) | url: "/api/v1"}
      ],
      info: %Info{
        title: "My App",
        version: "1.0"
      },
      paths: Router |> Paths.from_router() |> Map.new(fn {"/api/v1/"<>path, operations} -> {path, operations} end)
    }
    |> OpenApiSpex.resolve_schema_modules() 
  end
end

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ycherniavskyi
Comment options

Answer selected by ycherniavskyi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants