-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Description / Steps to reproduce / Feature proposal
From todo.controllers.ts in example-getting-started:
async createTodo(@requestBody() todo: Todo) {
// TODO(bajtos) This should be handled by the framework
// See https://github.com/strongloop/loopback-next/issues/118
if (!todo.title) {
return Promise.reject(new HttpErrors.BadRequest('title is required'));
}
return await this.todoRepo.create(todo);
}It should be noted that the spec generated by @requestBody is not correct since the argumnet that the operation takes in does not need an id property. One may think that Partial<Todo> may be the next best thing, but it's not possible at the moment to specify which properties are optional and which aren't.
We should find a way to generate the schema for a model when used as a parameter so that id property is not included in the generated schema
Proposed behavior:
@post('/')
makeStuff(@requestBody(Note) note: Partial<Note>) {}- Whenever
requestBodyis used on a model that extendsEntity, always generate (or modify) its spec without the property that's been assigned asid. - pros:
- simple ux
- cons:
- Not very flexible
requestBodybecomes very overloaded
Acceptance Criteria:
@post('/exclude')
postWithout(@requestBody(Note, {excludeProperties: ['id']}) note: Partial<Note>) {}
@post('/include')
PostWith(@requestbody(Note, {includeProperties: ['title', 'description']) note: Partial<Note>) {}-
explore more options from TypeScript (like Partial) to see if they can infer or provide us with additional data/metadata
-
allow
requestBody(or other new decorator to create the appropriate metadata) to take in the model type and schema generation options to produce a custom schema- specifying
excludePropertiesshould generate an OpenAPI Schema that lacks the given keys and their values when converting from the JSON Schema generated inrest - specifying
includePropertiesshould generate an OpenAPI Schema that contains only the given keys and their values when converted from the JSON Schema generated inrest
- specifying
-
Backwards compatibility must be preserved (
@requestBody(spec))
See Reporting Issues for more tips on writing good issues