feathersjs-ecosystem / feathers-swagger

Add documentation to your FeatherJS services and feed them to Swagger UI.
MIT License
226 stars 63 forks source link

Bug: Can't access ID in path #246

Closed AshotN closed 1 year ago

AshotN commented 1 year ago

Describe the bug The typing for the custom method doesn't expose params which contains the id in the path.

To Reproduce

  @customMethod('GET', '/:id/download')
  async download(data: any, params: Params) {
    const id = params.params.id; // <-- TS error
  }

image

Expected behavior The typing should contain params as an exposed property, or provide another means to retrieve the ID.

System configuration

 "feathers-swagger": "^3.0.0-pre.0",
 "@feathersjs/feathers": "^5.0.0-pre.32",

Additional context data is also undefined if it matters

Mairu commented 1 year ago

The typing of feathers method params is not in the hands of the library.

You can adjust the typing of params in the declarations.ts file of your project. As example, the generator also adds the user object to the params interface.

// Add the user as an optional property to all params
declare module '@feathersjs/feathers' {
  interface Params {
    user?: UsersResult;
    params?: Record<string, string>;
  }
}

data is also undefined if it matters

data should be only defined if provided to the REST call when using a method that supports data (POST, PUT, PATCH). For a GET call it should always be undefined.

AshotN commented 1 year ago

Thanks for the help!