Emit schema excluding certain model properties#3297
Conversation
94295c5 to
d8befdd
Compare
bajtos
left a comment
There was a problem hiding this comment.
Great patch! Let's improve few details please.
d8befdd to
969c5fe
Compare
b1975d2 to
0ea2feb
Compare
0ea2feb to
db19455
Compare
jannyHou
left a comment
There was a problem hiding this comment.
@nabdelgadir The fix looks reasonable in general 👍 Please note a model's id name is not always id, therefore we cannot hardcode the property name. You can get the id name by calling method like https://github.com/strongloop/loopback-next/blob/008c8b53bf00c576028b91d3a791ed2d6eafab7f/packages/repository/src/model.ts#L277
| async create( | ||
| @param.path.<%= sourceModelPrimaryKeyType %>('id') id: typeof <%= sourceModelClassName %>.prototype.<%= sourceModelPrimaryKey %>, | ||
| @requestBody() <%= targetModelRequestBody %>: <%= targetModelClassName %>, | ||
| @requestBody({ |
There was a problem hiding this comment.
The id field is not always called id, I think we need to get a model's id name in the template.
There was a problem hiding this comment.
Good point. AFAICT, lb4 model does allow users to create a primary key property with a different name than id.
Example prompts & answers to use pk instead of id:
Model Product will be created in src/models/product.model.ts
Let's add a property to Product
Enter an empty property name when done
? Enter the property name: pk
? Property type: string
? Is pk the ID property? Yes
? Is it required?: No
? Default value [leave blank for none]:
I agree with @jannyHou that we should honor custom PK name, there should be a new test to verify. If this is too much work then I can live with adding support for custom PK names in a follow-up pull request.
There was a problem hiding this comment.
If this is too much work then I can live with adding support for custom PK names in a follow-up pull request.
Yeah forgot to say, feel free to address it in another PR :)
There was a problem hiding this comment.
Will do in a separate PR 👍
| }, | ||
| }, | ||
| }) | ||
| todoList: Omit<TodoList, 'id'>, |
There was a problem hiding this comment.
Should we support include for todoList: Pick<TodoList, 'id'>?
There was a problem hiding this comment.
I'm fine to do it in a separate PR.
There was a problem hiding this comment.
I am not sure what would you use include for? A kind of a white-list? That would make sense 👍
Let's discuss include and Pick in a separate PR. I think it's best to wait until there is (user) demand for that feature.
…m schema Add a new option `exclude: []` so that `getJsonSchema` and related helpers can request a model schema that excludes specified properties
db19455 to
ffd4d40
Compare
See #2653.
excludeoption to emit model schema excluding certain model properties.POSTin example applications to excludeid.idfromPOSTrequest body.Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈