Skip to content

feat: swagger & swagger-ui #12

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

feat: swagger & swagger-ui #12

wants to merge 11 commits into from

Conversation

enricoprazeres
Copy link

@enricoprazeres enricoprazeres commented Jul 7, 2025

Closes #4

  • Kept the test_controller so the reviewer can test it and visualize something on the swagger.
  • To add a new controller to Swagger, you need to define Swagger documentation using the swagger_path macro inside the controller module just like that:
  use PhoenixSwagger

  swagger_path :index do
    get("/api/test")
    summary("Health check")
    description("Returns a simple OK message.")
    produces("application/json")
    response(200, "Success", Schema.ref(:HealthResponse))
  end

  • And run mix phx.swagger.generate.
  • As long as it's reviewed, I can remove the test_controller.

@deployum
Copy link

deployum bot commented Jul 7, 2025

The preview deployment failed. 🔴

Open Build Logs

Last updated at: 2025-07-15 20:27:44 CET

@enricoprazeres enricoprazeres self-assigned this Jul 8, 2025
Copy link
Member

@MarioRodrigues10 MarioRodrigues10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also change in endpoint.ex the following lines

  plug Plug.Static,
    at: "/",
    from: :atlas,
    gzip: false,
    only: AtlasWeb.static_paths()

to

  plug Plug.Static,
    at: "/",
    from: :atlas,
    gzip: false,
    only: ~w(css fonts images js favicon.ico robots.txt swagger.json)

produces("application/json")
tag("Authentication")
operation_id("sessions")
response(200, "Sessions succesfully returned")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use schemas to specify exactly the format of the content that gets returned. Maybe also add an example?

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.

feat: add Swagger/OpenAPI Spec for easy API documentation
3 participants