You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a follow-up for the discussion started in #2082, #2152 and the related issues.
In #2631, we are introducing a new function getModelSchemaRef that can be used to obtain OpenAPI schema for a model in a configurable way. Example use:
classTodoListController{// ...
@patch('/todo-lists/{id}',{responses: {// left out for brevity},})asyncupdateById(
@param.path.number('id')id: number,
@requestBody({content: {'application/json': {schema: getModelSchemaRef(TodoList,{partial: true}),/***** ^^^ THIS IS IMPORTANT - OPENAPI SCHEMA ^^^ ****/},},})obj: Partial<TodoList>,/***** ^^^ THIS IS IMPORTANT - TYPESCRIPT TYPE ^^^ ****/): Promise<void>{awaitthis.todoListRepository.updateById(id,obj);}}
Eventually, we plan to implement the following schema generator options:
The current approach is very verbose. Compare the example above with a controller method that uses default options:
classTodoController{// ...
@put('/todos/{id}',{responses: {// left out for brevity},})asyncreplaceTodo(
@param.path.number('id')id: number,
@requestBody()todo: Todo,): Promise<void>{awaitthis.todoRepo.replaceById(id,todo);}}
In this spike, we should research different options for simplifying request-body definitions requiring custom schema options.
This addresses only how to provide schema options when using x-ts-type extension. It does not address the problem of too complex spec required by @requestBody decorator.
classTodoController{// ...// `id` property is not allowed for `create`:
@post('/')createTodo(@requestBody(Todo,{exclude: ['id']})todo: ExcludeKeys<Todo,'id'>){}// all properties are allowed, all are optional
@patch('/')updateTodo(@requestBody(Todo,{partial: true})todo: Partial<Todo>){}}
Research different options for improving the current situation
Open a spike pull request showing a PoC of the proposed implementation
In the PR, include a /_SPIKE_.md document explaining what options you considered, what were pros and cons, how and why did you pick the winner. Include a list of follow-up stories needed to implement the proposed solution.
Discuss the propsal with the team and get their approval
Create follow-up stories.
The text was updated successfully, but these errors were encountered:
bajtos
changed the title
Spike: simplify requestBody annotation with JsonSchemaOptions
Spike: simplify requestBody annotation with schema options
Mar 28, 2019
looks more declarative than calling getModelSchemaRef(TodoList, {partial: true}), directly, but
It does not address the problem of too complex spec required by @requestbody decorator.
is still valid.
So I am proposing create some sugar apis like @requestBody().addContent('media-content-type-name', ModelCtor, options) to simplify the UX. And will try implement it in code.
This is a follow-up for the discussion started in #2082, #2152 and the related issues.
In #2631, we are introducing a new function
getModelSchemaRef
that can be used to obtain OpenAPI schema for a model in a configurable way. Example use:Eventually, we plan to implement the following schema generator options:
includeRelations
in Allow controllers to provide definitions of models referenced in operation spec #2629partial
in Emit schema with all model properties optional #2652exclude
in Emit schema excluding certain model properties #2653The current approach is very verbose. Compare the example above with a controller method that uses default options:
In this spike, we should research different options for simplifying request-body definitions requiring custom schema options.
Few examples to get started:
In Partial update (PATCH) over REST #1722 (comment), @raymondfeng proposed:
This addresses only how to provide schema options when using
x-ts-type
extension. It does not address the problem of too complex spec required by@requestBody
decorator.In Partial update (PATCH) over REST #1722 (comment), @bajtos proposed a different solution:
Acceptance criteria
Partial
#1179, fix: change service generator's ds to uppercase #2125, etc./_SPIKE_.md
document explaining what options you considered, what were pros and cons, how and why did you pick the winner. Include a list of follow-up stories needed to implement the proposed solution.The text was updated successfully, but these errors were encountered: