Skip to content

Proposal: automatically infer @path #201

Open
@gabro

Description

@gabro

The most common pattern we have in our wiro/tapiro based applications is:

@path("resource")
trait ResourceController[F[_], T] {
  @query
  def example(): F[Example]
}

which will produce this endpoint:

GET /resource/example

Omitting @path will instead result in

GET /ResourceController/example

which is virtually never what we want.

I propose we optimize for the most common use case by automatically inferring path from the controller name using a regex like ^(\w+)Controller$.

Under this scheme one would be able to omit path

trait ResourceController {
  @query
  def example(): F[Example]
}

and have an endpoint

GET /resource/example

Using @path is still supported if one needs a custom prefix


To summarize, the strategy to generate a the path prefix would be (in order of descending priority)

  • respect @path if provided
  • try inferring from the controller name (we could make this configurable if we have projects that use a different scheme than ^(\w+)Controller$)
  • fall-back to the controller name if everything else fails (I would log a warning in this case, since I think it will never happen on purpose)

What do you think @calippo?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions