-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
Description / Steps to reproduce / Feature proposal
Currently an OpenAPI response can only be set by providing the complete controller spec OR by passing it in the operation decorator. Describing a spec is very tedious and time consuming and we should provide an easier way to automagically assemble the spec.
Proposed Design
class MyController {
@response.ok('todo model instance created')
@post('/')
myMethod(): Promise<Todo> {
// implementation
}
}
A few alternatives for the decorator:
// schema in this case can be a Model / TypeScript Type.
@response(statusCode: number, description: string, responseSchema: schema)
@response.ok(description: string, responseSchema: schema) // ok in this case would translate to a 200
@response.statusCode(description: string, responseSchema: schema) // statusCode being 200, 404, etc.
@response.ok(description: string) + @response.schema(Todo) // allows arbitrary schema registration with the OpenAPI spec.
Acceptance Criteria
- Create a series of new "sugar" decorators to simplify OpenAPI response decorations for REST APIs. Proposed Decorators are as follows:
@response(200, 'description', 'application/custom-type', Customer)
@response(statusCode, Customer)
@response(statusCode, description, Customer)
@response(Customer) // Automagically generate statusCode, description (as done today), and assume json return type
// NOTE: Document that complex cases are dealt with via the operational decorators (@get, @post).
- The decorators should be "stackable", meaning the same decorator can be utilized multiple times on the same class method to specify multiple responses
class MyController {
@response(String)
@response(500, 'server error', Error)
hello() { // ... }
}
- Update CLI controller templates to use the new decorator instead
- Update example/todo, example/todo-list to use the new decorators
- Tests
- Docs
- Blog