Hi.
This is more an information than an issue.
I tried to upgrade to @nestjs/swagger@next (because of this issue : https://github.com/nestjs/swagger/issues/63) but it seems to be a refactor that breaks a lot of things.
At least, ApiModelProperty has been renamed to ApiProperty so I have this error :
.../node_modules/@nestjsx/crud/lib/crud/validation.helper.js:23
ApiModelProperty(options)(target, propertyKey);
^
TypeError: ApiModelProperty is not a function
thanks @mbaroukh
I'll update it after nestjs/swagger new version release
@zMotivat0r Could you please release an alpha version with the compatibility fix applied?
@zMotivat0r https://www.npmjs.com/package/@nestjs/swagger new version released. now is 4.0.4
Hi I'm facing the same issue with swagger 4.0.9 and crud 4.2.0.
It's still not fixed.
Stumbled on this one and I am looking forward to see this landing in user land. Any explanation, why already installing swagger/openapi module breaks things? This seems to be a bit of a riddle to me.
Regards
Here's the partial fix:
diff --git a/node_modules/@nestjsx/crud/lib/crud/swagger.helper.js b/node_modules/@nestjsx/crud/lib/crud/swagger.helper.js
index ffb38e4..fc5a054 100644
--- a/node_modules/@nestjsx/crud/lib/crud/swagger.helper.js
+++ b/node_modules/@nestjsx/crud/lib/crud/swagger.helper.js
@@ -72,85 +72,108 @@ class Swagger {
description: `<h4>Selects fields that should be returned in the reponse body.</h4><i>Syntax:</i> <strong>?${fields}=field1${coma}field2${coma}...</strong> <br/><i>Example:</i> <strong>?${fields}=email${coma}name</strong>`,
required: false,
in: 'query',
- type: 'array',
- items: {
- type: 'string',
+ schema: {
+ type: 'array',
+ items: {
+ type: 'string',
+ },
},
- collectionFormat: 'csv',
+ style: 'form',
+ explode: false,
};
const filterMeta = {
name: filter,
description: `<h4>Adds fields request condition (multiple conditions) to the request.</h4><i>Syntax:</i> <strong>?${filter}=field${d}condition${d}value</strong><br/><i>Examples:</i> <ul><li><strong>?${filter}=name${d}eq${d}batman</strong></li><li><strong>?${filter}=isVillain${d}eq${d}false&${filter}=city${d}eq${d}Arkham</strong> (multiple filters are treated as a combination of AND type of conditions)</li><li><strong>?${filter}=shots${d}in${d}12${coma}26</strong> (some conditions accept multiple values separated by commas)</li><li><strong>?${filter}=power${d}isnull</strong> (some conditions don't accept value)</li></ul><br/>Filter Conditions:<ul><li><strong><code>eq</code></strong> (<code>=</code>, equal)</li><li><strong><code>ne</code></strong> (<code>!=</code>, not equal)</li><li><strong><code>gt</code></strong> (<code>></code>, greater than)</li><li><strong><code>lt</code></strong> (<code><</code>, lower that)</li><li><strong><code>gte</code></strong> (<code>>=</code>, greater than or equal)</li><li><strong><code>lte</code></strong> (<code><=</code>, lower than or equal)</li><li><strong><code>starts</code></strong> (<code>LIKE val%</code>, starts with)</li><li><strong><code>ends</code></strong> (<code>LIKE %val</code>, ends with)</li><li><strong><code>cont</code></strong> (<code>LIKE %val%</code>, contains)</li><li><strong><code>excl</code></strong> (<code>NOT LIKE %val%</code>, not contains)</li><li><strong><code>in</code></strong> (<code>IN</code>, in range, <strong><em>accepts multiple values</em></strong>)</li><li><strong><code>notin</code></strong> (<code>NOT IN</code>, not in range, <strong><em>accepts multiple values</em></strong>)</li><li><strong><code>isnull</code></strong> (<code>IS NULL</code>, is NULL, <strong><em>doesn't accept value</em></strong>)</li><li><strong><code>notnull</code></strong> (<code>IS NOT NULL</code>, not NULL, <strong><em>doesn't accept value</em></strong>)</li><li><strong><code>between</code></strong> (<code>BETWEEN</code>, between, <strong><em>accepts two values</em></strong>)</li></ul>`,
required: false,
in: 'query',
- type: 'array',
- items: {
- type: 'string',
+ schema: {
+ type: 'array',
+ items: {
+ type: 'string',
+ }
},
- collectionFormat: 'multi',
+ style: 'form',
+ explode: true,
};
const orMeta = {
name: or,
description: `<h4>Adds <code>OR</code> conditions to the request.</h4><i>Syntax:</i> <strong>?${or}=field${d}condition${d}value</strong><br/>It uses the same conditions as the filter parameter<br/><i>Rules and <i>Examples:</i></i><ul><li>If there is only <strong>one</strong> <code>or</code> present (without <code>filter</code>) then it will be interpreted as simple filter:</li><ul><li><strong>?${or}=name${d}eq${d}batman</strong></li></ul></ul><ul><li>If there are <strong>multiple</strong> <code>or</code> present (without <code>filter</code>) then it will be interpreted as a compination of <code>OR</code> conditions, as follows:<br><code>WHERE {or} OR {or} OR ...</code></li><ul><li><strong>?${or}=name${d}eq${d}batman&${or}=name${d}eq${d}joker</strong></li></ul></ul><ul><li>If there are <strong>one</strong> <code>or</code> and <strong>one</strong> <code>filter</code> then it will be interpreted as <code>OR</code> condition, as follows:<br><code>WHERE {filter} OR {or}</code></li><ul><li><strong>?${filter}=name${d}eq${d}batman&${or}=name${d}eq${d}joker</strong></li></ul></ul><ul><li>If present <strong>both</strong> <code>or</code> and <code>filter</code> in any amount (<strong>one</strong> or <strong>miltiple</strong> each) then both interpreted as a combitation of <code>AND</code> conditions and compared with each other by <code>OR</code> condition, as follows:<br><code>WHERE ({filter} AND {filter} AND ...) OR ({or} AND {or} AND ...)</code></li><ul><li><strong>?${filter}=type${d}eq${d}hero&${filter}=status${d}eq${d}alive&${or}=type${d}eq${d}villain&${or}=status${d}eq${d}dead</strong></li></ul></ul>`,
required: false,
in: 'query',
- type: 'array',
- items: {
- type: 'string',
+ schema: {
+ type: 'array',
+ items: {
+ type: 'string',
+ }
},
- collectionFormat: 'multi',
+ style: 'form',
+ explode: true,
};
const sortMeta = {
name: sort,
description: `<h4>Adds sort by field (by multiple fields) and order to query result.</h4><i>Syntax:</i> <strong>?${sort}=field${coma}ASC|DESC</strong><br/><i>Examples:</i></i><ul><li><strong>?${sort}=name${coma}ASC</strong></li><li><strong>?${sort}=name${coma}ASC&${sort}=id${coma}DESC</strong></li></ul>`,
required: false,
in: 'query',
- type: 'array',
- items: {
- type: 'string',
+ schema: {
+ type: 'array',
+ items: {
+ type: 'string',
+ }
},
- collectionFormat: 'multi',
+ style: 'form',
+ explode: true,
};
const joinMeta = {
name: join,
description: `<h4>Receive joined relational objects in GET result (with all or selected fields).</h4><i>Syntax:</i><ul><li><strong>?${join}=relation</strong></li><li><strong>?${join}=relation${d}field1${coma}field2${coma}...</strong></li><li><strong>?${join}=relation1${d}field11${coma}field12${coma}...&${join}=relation1.nested${d}field21${coma}field22${coma}...&${join}=...</strong></li></ul><br/><i>Examples:</i></i><ul><li><strong>?${join}=profile</strong></li><li><strong>?${join}=profile${d}firstName${coma}email</strong></li><li><strong>?${join}=profile${d}firstName${coma}email&${join}=notifications${d}content&${join}=tasks</strong></li><li><strong>?${join}=relation1&${join}=relation1.nested&${join}=relation1.nested.deepnested</strong></li></ul><strong><i>Notice:</i></strong> <code>id</code> field always persists in relational objects. To use nested relations, the parent level MUST be set before the child level like example above.`,
required: false,
in: 'query',
- type: 'array',
- items: {
- type: 'string',
+ schema: {
+ type: 'array',
+ items: {
+ type: 'string',
+ }
},
- collectionFormat: 'multi',
+ style: 'form',
+ explode: true,
};
const limitMeta = {
name: limit,
description: `<h4>Receive <code>N</code> amount of entities.</h4><i>Syntax:</i> <strong>?${limit}=number</strong><br/><i>Example:</i> <strong>?${limit}=10</strong>`,
required: false,
in: 'query',
- type: 'integer',
+ schema: {
+ type: 'integer',
+ }
};
const offsetMeta = {
name: offset,
description: `<h4>Offset <code>N</code> amount of entities.</h4><i>Syntax:</i> <strong>?${offset}=number</strong><br/><i>Example:</i> <strong>?${offset}=10</strong>`,
required: false,
in: 'query',
- type: 'integer',
+ schema: {
+ type: 'integer',
+ }
};
const pageMeta = {
name: page,
description: `<h4>Receive a portion of <code>limit</code> entities (alternative to <code>offset</code>). Will be applied if <code>limit</code> is set up.</h4><i>Syntax:</i> <strong>?${page}=number</strong><br/><i>Example:</i> <strong>?${page}=2</strong>`,
required: false,
in: 'query',
- type: 'integer',
+ schema: {
+ type: 'integer',
+ }
};
const cacheMeta = {
name: cache,
description: `<h4>Reset cache (if was enabled) and receive entities from the DB.</h4><i>Usage:</i> <strong>?${cache}=0</strong>`,
required: false,
in: 'query',
- type: 'integer',
- minimum: 0,
- maximum: 1,
+ schema: {
+ type: 'integer',
+ minimum: 0,
+ maximum: 1,
+ }
};
switch (name) {
case 'getManyBase':
@@ -166,7 +189,7 @@ class Swagger {
cacheMeta,
];
case 'getOneBase':
- return [fieldsMeta, joinMeta, cacheMeta];
+ return [fieldsMeta, joinMeta, cacheMeta ];
default:
return [];
}
diff --git a/node_modules/@nestjsx/crud/lib/crud/validation.helper.js b/node_modules/@nestjsx/crud/lib/crud/validation.helper.js
index 8247568..c32ec42 100644
--- a/node_modules/@nestjsx/crud/lib/crud/validation.helper.js
+++ b/node_modules/@nestjsx/crud/lib/crud/validation.helper.js
@@ -19,8 +19,8 @@ const swagger = util_2.safeRequire('@nestjs/swagger');
function ApiModelProperty(options) {
return (target, propertyKey) => {
if (swagger) {
- const { ApiModelProperty } = swagger;
- ApiModelProperty(options)(target, propertyKey);
+ const { ApiProperty } = swagger;
+ ApiProperty(options)(target, propertyKey);
}
};
}
this issue isn't fixed
With the current versions
@nestjs/common: 6.10.10
@nestjs/core: 6.10.10
@nestjs/swagger: 4.0.9
@nestjsx/crud: 4.3.0-alpha.0
@nestjsx/crud-typeorm: 4.3.0-alpha.0
Stacktrace
TypeError: ApiModelProperty is not a function
at /home/user/project/node_modules/@nestjsx/crud/src/crud/validation.helper.ts:19:7
at DecorateProperty (/home/user/project/node_modules/reflect-metadata/Reflect.js:553:33)
at Object.decorate (/home/user/project/node_modules/reflect-metadata/Reflect.js:123:24)
at __decorate (/home/user/project/node_modules/@nestjsx/crud/lib/crud/validation.helper.js:4:92)
at Function.createBulkDto (/home/user/project/node_modules/@nestjsx/crud/src/crud/validation.helper.ts:54:9)
at CrudRoutesFactory.setRouteArgsTypes (/home/user/project/node_modules/@nestjsx/crud/src/crud/crud-routes.factory.ts:371:34)
at CrudRoutesFactory.setBaseRouteMeta (/home/user/project/node_modules/@nestjsx/crud/src/crud/crud-routes.factory.ts:338:10)
at /home/user/project/node_modules/@nestjsx/crud/src/crud/crud-routes.factory.ts:230:14
at Array.forEach (<anonymous>)
at CrudRoutesFactory.createRoutes (/home/user/project/node_modules/@nestjsx/crud/src/crud/crud-routes.factory.ts:224:18)
This issue is fixed in master and is closed since tha patch PR is merged into master
When will this fix release? @zMotivat0r
Still getting the same error
Dependencies versions:
"@nestjs/common": "^6.7.2",
"@nestjs/core": "^6.7.2",
"@nestjs/typeorm": "^6.2.0",
"@nestjsx/crud": "^4.2.0",
"@nestjsx/crud-typeorm": "^4.2.0",
"@nestjs/swagger": "^4.0.0-next.19",
"swagger-ui-express": "^4.1.2"
published 4.3.0-beta.0
@leosuncin @jakemonton
@zMotivat0r
Tested. Works now! Many thanks! 馃憤
works for me. ty ;) <3
Most helpful comment
@zMotivat0r https://www.npmjs.com/package/@nestjs/swagger new version released. now is
4.0.4