Skip to content

feature request: Paths.from_route{r,s}/1 enhancements #682

@halostatue

Description

@halostatue

I'd love to see enhancements to Paths.from_routes/1 and Paths.from_router/1, preferably making them Paths.from_routes/2 and Paths.from_router/2.

What I want

  1. I would like to enable a strict mode for path derivation that fails path derivation if a duplicate operation title is found, instead of renaming it to #{title} (#{occurrence}).

    iex> Paths.from_router(MyAppWeb.Router, operation_resolver: :strict)
    **(RuntimeError)** Path "/foo" has two identical operations
    

    Obviously, if it could provide more details about where the two identical operations have been found (I suspect it can because the path item contains the router), that would be amazing, but having that fail at compile time instead of producing openapi specs that fail validation later would be good enough.

  2. I would like to provide multiple routers.

    iex> Paths.from_router([MyAppWeb.Router, MyAppWeb.AdminRouter], operation_resolver: :strict)
    # correct output if there's no operation collisions

Context

We're in the process of cleaning up our router from several years of changes across many developers and have moved admin routes to their own router (we forward / to AdminRouter at the bottom of Router) and are currently having to do Map.merge(Paths.from_router(MyApp.Router), Paths.from_router(MyApp.AdminRouter)) (we're doing this with Map.merge/3 to raise on duplicate paths between the routers, because that's explicitly illegal in our scenario, but the strict mode outlined above would be sufficient for this purpose).

I may be able to provide a pull request for these features if there is interest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions