Skip to content

Commit

Permalink
fix(crud): take into account Swagger meta defined on overridden methods
Browse files Browse the repository at this point in the history
For example, allow specifying Swagger metadata this way:

```typescript
export class SomeController {
  @OverRide()
  @ApiOperation({
    title: 'Get list of something',
    operationId: 'getSomething',
  }),
  @ApiOkResponse({ type: Something })
  public getMany() {}
}
```
  • Loading branch information
roland-chernov committed Oct 4, 2019
1 parent e4e6339 commit feb01a6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/crud/src/crud/crud-routes.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,24 @@ export class CrudRoutesFactory {
const interceptors = R.getInterceptors(this.targetProto[name]);
const baseInterceptors = R.getInterceptors(this.targetProto[override]);
const baseAction = R.getAction(this.targetProto[override]);
const operation = Swagger.getOperation(this.targetProto[name]);
const baseOperation = Swagger.getOperation(this.targetProto[override]);
const swaggerParams = Swagger.getParams(this.targetProto[name]);
const baseSwaggerParams = Swagger.getParams(this.targetProto[override]);
const responseOk = Swagger.getResponseOk(this.targetProto[name]);
const baseResponseOk = Swagger.getResponseOk(this.targetProto[override]);
// set metadata
R.setInterceptors([...baseInterceptors, ...interceptors], this.targetProto[name]);
R.setAction(baseAction, this.targetProto[name]);
Swagger.setOperation(baseOperation, this.targetProto[name]);
Swagger.setParams(baseSwaggerParams, this.targetProto[name]);
Swagger.setResponseOk(baseResponseOk, this.targetProto[name]);
Swagger.setOperation({ ...baseOperation, ...operation }, this.targetProto[name]);
Swagger.setParams(
[...baseSwaggerParams, ...swaggerParams],
this.targetProto[name],
);
Swagger.setResponseOk(
{ ...baseResponseOk, ...responseOk },
this.targetProto[name],
);
this.overrideParsedBodyDecorator(override, name);
// enable route
R.setRoute(route, this.targetProto[name]);
Expand Down

0 comments on commit feb01a6

Please sign in to comment.