open-api-spex / open_api_spex

Open API Specifications for Elixir Plug applications
Mozilla Public License 2.0
706 stars 183 forks source link

fix: Dynamically lookup schema when simply a module #631

Closed oceanlewis closed 1 month ago

oceanlewis commented 1 month ago

Changes the Cast logic to attempt to lookup the schema when given a module as a :schema.

Addresses these issues:

mbuhot commented 1 month ago

Thanks for the PR @oceanlewis. I'm closing this one since OpenAPISpex is designed to have Schema modules resolved to %References{} immediately after constructing the %OpenApi{}, as per the example in the README:

  @impl OpenApi
  def spec do
    %OpenApi{
      servers: [
        # Populate the Server info from a phoenix endpoint
        Server.from_endpoint(Endpoint)
      ],
      info: %Info{
        title: "My App",
        version: "1.0"
      },
      # Populate the paths from a phoenix router
      paths: Paths.from_router(Router)
    }
    |> OpenApiSpex.resolve_schema_modules() # Discover request/response schemas from path specs
  end