managua1902
Generating REST API docs by Swagger
I have REST API project for which I need to generate documentation.
I’ve looked into phoenix_swagger | Hex . However, as I’ve found out, it requires adding Elixir code right next to each API function:
swagger_path :index do
get "/api/users"
summary "List users"
description "List all users in the database"
tag "Users"
produces "application/json"
response(200, "OK", Schema.ref(:UsersResponse),
example: %{
data: [
%{
id: 1,
count: 42,
email: "some email",
name: "some name",
private: true,
profile: "some profile",
}
]
}
)
end
def index(conn, _params) do
users = Users.list_users()
render(conn, "index.json", users: users)
end
This will greatly litter the code where it’ll be unnecessary, in my opinion.
Is there other Elixir Swagger library which is up to date and usable? Or how else will I generate the REST API docs?
Most Liked
tfwright
It’s exactly what you’re asking for:
What I want is to keep the description of each REST API endpoint somewhere aside, in a separate file or files.
Last Post!
smathy
Well in rswag the API version is just one of the swagger annotations you put in your tests, it defaults to the first version (that you’ve defined in your swagger config) but when you have multiple versions then you just annotate your v1 tests to be for your v1 docs, v2 for v2, etc.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









