kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
892 stars 235 forks source link

koa-openapi: Name created routes for later use #671

Closed imnotjames closed 4 years ago

imnotjames commented 4 years ago

the koa-router is able to generate URLs from named routes

this means if we use the operationId in the koa route creation we can call router.url later with the operationId and generate the URL as expected

For example, the OpenAPI operation

/foo/{foo_id}:
  parameters
    - name: foo_id
      in: path
  get:
    operationId: bar

can be used with route.url as such:

const url = ctx.router.url('bar', { foo_id: 'hello' });
// `url` is "/foo/hello"