ID field with generated = true, forceId = true appears in Swagger example
Reopening as #3447 was closed and this is regularly causing our users confusion.
Description/Steps to reproduce
I am using the following LoopBack model definition:
{
"name": "SetupDemo",
"description": "A transaction named SetupDemo",
"plural": "SetupDemo",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true,
"composer": {
"type": "transaction",
"namespace": "org.acme.biznet",
"name": "SetupDemo",
"fqn": "org.acme.biznet.SetupDemo"
}
},
"properties": {
"$class": {
"type": "string",
"default": "org.acme.biznet.SetupDemo",
"required": false,
"description": "The class identifier for this type"
},
"id": {
"type": "string",
"id": true,
"description": "The instance identifier for this type",
"required": false,
"generated": true
},
"timestamp": {
"type": "date",
"required": false
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": [],
"forceId": true
}
Each instance of this type has those three properties ($class, id, timestamp). The ID needs to be generated on the server side when creating new instances of this type. The ID must not be supplied by the client.
Expected result
The ID cannot be supplied by the client as I would expect:
The 'SetupDemo' instance is not valid. Details: 'id' can't be set (value: \"string\").
However the id property still appears in the generated Swagger example for the POST method:
Since the id property cannot be supplied in the POST method, it should not appear in the generated Swagger example.
Additional information
It would be cool if we could have more control over swagger generated model and decide what properties should appear in the input model and output model.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.
please provide a solution for this, the problem still persists. even after writing "transactionId" : false,
this is the error
{
"error": {
"statusCode": 400,
"name": "SyntaxError",
"message": "Unexpected token t in JSON at position 110",
"body": "{\n "$class": "test.AccountTransfer",\n "from": "HimaniAccount",\n "to": "AstatineAccount",\n "amount": 20,\n transactionId: false,\n "timestamp": "2018-06-01T04:33:39.539Z"\n}",
"status": 400,
"stack": "SyntaxError: Unexpected token t in JSON at position 110\n at JSON.parse (
please provide a solution for this, the problem still persists. even after writing "transactionId" : false,
this is the error
{ "error": { "statusCode": 400, "name": "SyntaxError", "message": "Unexpected token t in JSON at position 110", "body": "{\n "$class": "test.AccountTransfer",\n "from": "HimaniAccount",\n "to": "AstatineAccount",\n "amount": 20,\n transactionId: false,\n "timestamp": "2018-06-01T04:33:39.539Z"\n}", "status": 400, "stack": "SyntaxError: Unexpected token t in JSON at position 110\n at JSON.parse ()\n at parse (/home/himani/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/body-parser/lib/types/json.js:88:17)\n at /home/himani/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/body-parser/lib/read.js:116:18\n at invokeCallback (/home/himani/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/raw-body/index.js:262:16)\n at done (/home/himani/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/raw-body/index.js:251:7)\n at IncomingMessage.onEnd (/home/himani/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/raw-body/index.js:307:7)\n at emitNone (events.js:106:13)\n at IncomingMessage.emit (events.js:208:7)\n at endReadableNT (_stream_readable.js:1064:12)\n at _combinedTickCallback (internal/process/next_tick.js:138:11)\n at process._tickCallback (internal/process/next_tick.js:180:9)" } }
i am getting same error as u get above can you help me how to solve that error