Closed virkt25 closed 3 years ago
I don't think there is need to introduce --json
as we already have --config
which takes a json file or stringified json.
Oh, I might've confused the flags ... but it's basically adding support for the --config
flag (I thought it was --json
) ... by skipping over the prompts for properties if supplied by a user.
Adding a use case for @virkt25 proposal. We use models that have more than 20,30 columns. We create manually our models and for this scenario we would not be using an lb4 model wizard that asks each property step by step. But we would like an option that could generate a basic repository and a model class out of this definition file automatically. That could save us a lot of time.
lb4 model --config src/models/large.definition.ts
And then it would create the src/models/large.model.ts and src/repositories/large.repository.ts automatically, that could help :-)
@marioestradarosa, It might be a stupid question... what would be the difference between large.definition.ts
that user provides and large.model.ts
that LB CLI generates?
@dhmlau 😄 forgive me, but I think I am the one who made the mistake for the .ts extension. I meant .json extension and I meant having a large table defined in json format (LB3 ), we should provide a way to migrate to LB4 with single command
lb4 model --config-json="anydirectory/large.table.json
or
lb4 model --config-json="anydirectory/large.table.json --with-repository
and it would create the LB4 artifacts in src/models
By large, I meant a table with several columns. I believe for demos is fine to have the lb4 model
to ask for properties etc., but in large applications that wouldn't work. So this feature makes sense for two scenarios:
Developers can create these json files compatible with juggler easily out of their production schema (reverse-engineer more or less)
I hope this clarifies what I meant and thank you for answering. Please let me know if my comment makes sense and is aligned with @virkt25 request.
Makes perfect sense to me @marioestradarosa. @dhmlau The json
can be considered LB3 equivalent of a ModelDefinition json file.
For --with-repository
I'll be making a new issue later today to track how we want generators to be composed because calling model, repository, controller can be a bit annoying and I see it as a separate feature than support for --config
got it. Thanks!
Looks like this is working. WIth the following model.json, I can use lb4 model --config model.config.json --yes
to create the model. But it seems like the need to have --yes
is not trivial.
{
"name": "Customer",
"base": "Entity",
"properties": {
"id": {
"type": "number",
"id": true,
"required": false
},
"name": {
"type": "string",
"length": 200,
"id": false,
"required": true
}
}
}
Hi,
I have a problem with generation model with inner attributes (property properties) for example:
{
"id": {
"type": "string",
"annotations": [
{
"destinationClass": "className",
"destinationField": "name",
"prefix": "prefix"
}
],
"required": true,
"id": true
},
"name": {
"type": "string",
"required": true
}
}
The Model look like:
{
@property({
type: 'string',
annotations: [object Object],
required: true,
id: true,
})
id: string;
@property({
type: 'string',
required: true,
})
name: string;
}
Is it possible to generate Model with correct property properties?
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.
IIUC, the problem is in the way how we are emitting property metadata fields.
@property({
// ...
annotations: [object Object],
})
In https://github.com/strongloop/loopback-next/pull/4180, we fixed the problem for model discovery. Unfortunately that fix was not generic enough to address other use cases.
I think we should improve the template to handle nested objects in all property metadata fields. You can check the model generator to see how it deals with this problem.
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.
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.
Acceptance Criteria
Add support for
--config
forlb4 model
as follows:[ ]
--config
accepts an Object with aproperties
object that describes the properties for a model[ ] This will allow us to test
property
generation logic (not the prompts) BY feeding in the properties viajson
and then checking the generated model. WRITE tests for testing the different types of properties and options available for properties to ensure we generate correct files.