Skip to content

Commit

Permalink
feat: use descriptive title to describe schema of POST (create) reque…
Browse files Browse the repository at this point in the history
…st bodies

Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Sep 16, 2019
1 parent 7664b3e commit 8f49a45
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/site/Controller-generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class TodoController {
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {exclude: ['id']}),
schema: getModelSchemaRef(Todo, {title: 'NewTodo', exclude: ['id']}),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class TodoListTodoController {
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {exclude: ['id']}),
schema: getModelSchemaRef(Todo, {title: 'NewTodo', exclude: ['id']}),
},
},
})
Expand Down Expand Up @@ -237,7 +237,7 @@ export class TodoListTodoController {
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {exclude: ['id']}),
schema: getModelSchemaRef(Todo, {title: 'NewTodo', exclude: ['id']}),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class NoteController {
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Note, {exclude: ['id']}),
schema: getModelSchemaRef(Note, {title: 'NewNote', exclude: ['id']}),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class TodoListTodoController {
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {
title: 'NewTodoInTodoList',
exclude: ['id'],
optional: ['todoListId'],
}),
Expand Down
5 changes: 4 additions & 1 deletion examples/todo-list/src/controllers/todo-list.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export class TodoListController {
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(TodoList, {exclude: ['id']}),
schema: getModelSchemaRef(TodoList, {
title: 'NewTodoList',
exclude: ['id'],
}),
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion examples/todo-list/src/controllers/todo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class TodoController {
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {exclude: ['id']}),
schema: getModelSchemaRef(Todo, {title: 'NewTodo', exclude: ['id']}),
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion examples/todo/src/controllers/todo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class TodoController {
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(Todo, {exclude: ['id']}),
schema: getModelSchemaRef(Todo, {title: 'NewTodo', exclude: ['id']}),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export class <%= className %>Controller {
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(<%= modelName %>, {exclude: ['<%= id %>']}),
schema: getModelSchemaRef(<%= modelName %>, {
title: 'New<%= modelName %>',
exclude: ['<%= id %>'],
}),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class <%= controllerClassName %> {
content: {
'application/json': {
schema: getModelSchemaRef(<%= targetModelClassName %>, {
title: 'New <%= targetModelClassName %>In<%= sourceModelClassName %>',
exclude: ['<%= targetModelPrimaryKey %>'],
optional: ['<%= foreignKeyName %>']
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function checkRestCrudContents() {
/'200': {/,
/description: 'ProductReview model instance'/,
/content: {'application\/json': {schema: getModelSchemaRef\(ProductReview\)}},\s{1,}},\s{1,}},\s{1,}}\)/,
/async create\(\s+\@requestBody\({\s+content: {\s+'application\/json': {\s+schema: getModelSchemaRef\(ProductReview, {exclude: \['productId'\]}\),\s+},\s+},\s+}\)\s+productReview: Omit<ProductReview, 'productId'>,\s+\)/,
/async create\(\s+\@requestBody\({\s+content: {\s+'application\/json': {\s+schema: getModelSchemaRef\(ProductReview, {\s+title: 'NewProductReview',\s+exclude: \['productId'\],\s+}\),\s+},\s+},\s+}\)\s+productReview: Omit<ProductReview, 'productId'>,\s+\)/,
];
postCreateRegEx.forEach(regex => {
assert.fileContent(expectedFile, regex);
Expand Down
5 changes: 4 additions & 1 deletion packages/rest-crud/src/crud-rest.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ export function defineCrudRestController<
...response.model(200, `${modelName} instance created`, modelCtor),
})
async create(
@body(modelCtor, {exclude: modelCtor.getIdProperties() as (keyof T)[]})
@body(modelCtor, {
title: `New${modelName}`,
exclude: modelCtor.getIdProperties() as (keyof T)[],
})
data: Omit<T, IdName>,
): Promise<T> {
return this.repository.create(
Expand Down

0 comments on commit 8f49a45

Please sign in to comment.