Oaskit.Plugs.SpecProvider (oaskit v0.6.0)
View SourceA plug to associate an OpenAPI specification with a group of routes in a router or a controller.
It takes a :spec option with the name of a module implementing the
Oaskit behaviour.
It will generally be used from a Phoenix.Router implementation:
defmodule MyAppWeb.Router do
use Phoenix.Router
# The provider should be called in a pipeline.
pipeline :api do
plug Oaskit.Plugs.SpecProvider, spec: MyAppWeb.ApiSpec
end
scope "/api", MyAppWeb.Api do
# Then that pipeline can be used in one or
# more scopes.
pipe_through :api
# Controllers used in such scopes can now use
# the `Oaskit.Plugs.ValidateRequest` plug.
get "/hello", HelloController, :hello
end
endWhy do we need this?
Why not directly pass the spec module to Oaskit.Plugs.ValidateRequest?
Because we may want to attach a controller action and its operation ID to multiple API specifications.
For that reason, specs are attached to routes using a pipeline, and not to
controllers. This is why this plug is used in router modules, while the
Oaskit.Plugs.ValidateRequest plug will take whatever spec was given in the
conn and fetch the operation ID from there.
Summary
Functions
Callback implementation for Plug.call/2.
Returns the spec module from a conn if the conn went through this plug, raises an error otherwise.
Callback implementation for Plug.init/1.
Functions
Callback implementation for Plug.call/2.
Returns the spec module from a conn if the conn went through this plug, raises an error otherwise.
Callback implementation for Plug.init/1.