zimicjs / zimic

TypeScript-first HTTP request mocking
https://npmjs.com/package/zimic
MIT License
9 stars 2 forks source link

Path aliases #252

Open diego-aquino opened 3 months ago

diego-aquino commented 3 months ago

It is possible for paths to be long and contain many path params. This makes referencing the full paths in interceptors verbose.

interceptor
  .get('/repos/:owner/:repo/branches/:branch/protection/required_status_checks/contexts')
  .respond({ status: 200 })

A possible enhancement is to support path aliases, such as the one showed bellow.

interceptor.get
  .requiredStatusCheckBranchContexts(owner, repo, branch)
  .respond({ status: 200 })

Path aliases would be declared at the interceptor level and would be a function receiving any types or number of arguments and returning a string: the path aliased to.

const interceptor = httpInterceptor.create<....>({
  ...,
  pathAliases: {
    GET: {
      requiredStatusCheckBranchContexts(owner: string, repo: string, branch: string) {
        return `/repos/${owner}/${repo}/branches/${branch}/protection/required_status_checks/contexts` as const
      }
    }
  }
})

However, I am not sure if adding a new API is worth the benefits.