# `Oaskit.Plugs.SpecProvider`
[🔗](https://github.com/lud/oaskit/blob/v0.13.1/lib/oaskit/plugs/spec_provider.ex#L1)

A 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
    end

> ### Why do we need this? {: .info}
>
> 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.

# `call`

# `fetch_spec_module!`

Returns the spec module from a conn if the conn went through this plug, raises
an error otherwise.

# `init`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
