Skip to content

Commit

Permalink
Merge: pull request #58
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkingmik committed Jun 18, 2021
1 parent 43137cb commit 95371ef
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 640 deletions.
26 changes: 21 additions & 5 deletions lib/swagger-express-ts-lib/src/api-model-property.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,27 @@ export function ApiModelProperty(
args?: IApiModelPropertyArgs
): PropertyDecorator {
return (target: any, propertyKey: string | symbol) => {
const propertyType = Reflect.getMetadata(
'design:type',
target,
propertyKey
).name;
let propertyType = '';

if (typeof args.itemType !== 'undefined' && args.itemType !== null) {
propertyType = args.itemType;
} else {
try {
propertyType = Reflect.getMetadata(
'design:type',
target,
propertyKey
).name;
} catch (err) {
if (err.message === "Cannot read property 'name' of undefined") {
throw new Error(
`${err.message}. This usually occours due to a circular reference between models. A possible solution is to set the itemType argument of the @ApiModelProperty to a string that matches the class name of the field type. The field in question is named ${String(propertyKey)}.`);
} else {
throw err;
}
}
}

SwaggerService.getInstance().addApiModelProperty(
args,
target,
Expand Down
Loading

0 comments on commit 95371ef

Please sign in to comment.