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

fix: supports setting a relative path for the API definition URL #649

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fahchen
Copy link

@fahchen fahchen commented Jan 8, 2025

By setting a relative path, we can ensure that it works regardless of where the server is hosted.
For example, the server may be served from a subpath, which is unknown at compile time.

In the example from the module doc, we can set a relative path ./api/openapi for the Swagger UI,
which is equivalent to the absolute path /api/openapi when the server is hosted at the root path.
But if the server is hosted at a subpath like /myapp, which is unknown at compile time,
we can use a relative path instead.

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

scope "/" do
  pipe_through :browser

  get "/swaggerui", OpenApiSpex.Plug.SwaggerUI,
    path: "./api/openapi"
end

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

Successfully merging this pull request may close these issues.

1 participant