Prompt issue by creating model with specified config
Steps to reproduce
I specified a config to create model not to prompt me the question but It still prompts me to create a property.
My config.json
{
"name": "Customer",
"base": "Entity",
"properties": {
"id": {
"type": "number",
"id": true,
"required": false
},
"name": {
"type": "string",
"length": 200,
"id": false,
"required": true
}
}
}
My controller creation CLI command:
lb4 model --config config.json --yes
Note: If I don't use --yes arg, the config doesn't work.
Current Behavior
The customer.model.ts file is created but the specified properties are not created, and the terminal prompts me this:
Model Customer will be created in src/models/customer.model.ts
Let's add a property to Customer
Enter an empty property name when done
? Enter the property name:
Still prompts me a property name to create a property for this model but I don't want another property. I specify all my properties in the config. However, It throws an error when I just enter it or passing a property name:
(node:74396) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Environment'
| property '_rootGenerator' -> object with constructor 'ModelGenerator'
| property 'options' -> object with constructor 'Object'
--- property 'env' closes the circle
at JSON.stringify (<anonymous>)
at ModelGenerator.promptPropertyName (/usr/local/lib/node_modules/@loopback/cli/generators/model/index.js:375:31)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:74396) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:74396) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Expected Behavior
Generating model without prompting anything.
@canmustu, I've created this PR https://github.com/strongloop/loopback-next/pull/7406 which would fix the issue. Will need to add tests.
@dhmlau, I've used that changed codes. I specified all properties by the config but it still prompts me for properties. Expected behaviour is that not prompt me any property, just generates the model by specified config.
The behaviour:
Model Customer will be created in src/models/customer.model.ts
Let's add a property to Customer
Enter an empty property name when done
? Enter the property name: test
Default value [leave blank for none]: [ <pressed enter> ]
And then, I get the error again,
(node:74396) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Environment'
| property '_rootGenerator' -> object with constructor 'ModelGenerator'
| property 'options' -> object with constructor 'Object'
--- property 'env' closes the circle
at JSON.stringify (<anonymous>)
at ModelGenerator.promptPropertyName (/usr/local/lib/node_modules/@loopback/cli/generators/model/index.js:375:31)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:74396) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:74396) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@dhmlau, Hi, is there any update about this issue?
@canmustu, sorry about the delay. I was a bit stuck on getting my tests to pass.
This issue has been marked stale because it has not seen activity within six months. 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. This issue will be closed within 30 days of being stale.