Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit schema with all model properties optional #2652

Closed
5 tasks done
bajtos opened this issue Mar 28, 2019 · 1 comment
Closed
5 tasks done

Emit schema with all model properties optional #2652

bajtos opened this issue Mar 28, 2019 · 1 comment

Comments

@bajtos
Copy link
Member

bajtos commented Mar 28, 2019

Allow Controller methods implementing PATCH operation to describe their input data as "a model with all properties optional". This story requires #2629 and #2631 to be implemented first.

To emit schema with optional model properties, we should add a new schema-generation option called partial.

export interface JsonSchemaOptions {
  /// Make all properties optional
  partial?: boolean;
}

An example showing a controller method accepting a partial model instance:

class TodoListController {
  // ...

  @patch('/todo-lists/{id}', {
    responses: {
      // left out for brevity
    },
  })
  async updateById(
    @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> {
    await this.todoListRepository.updateById(id, obj);
  }
}

See 887ae84 for a spike showing proposed implementation details.

Acceptance criteria

@bajtos
Copy link
Member Author

bajtos commented Jun 27, 2019

Done 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants