Skip to content

feat(openapi-v3): responses decorator#1655

Merged
virkt25 merged 5 commits intomasterfrom
openapi-responses
Sep 13, 2018
Merged

feat(openapi-v3): responses decorator#1655
virkt25 merged 5 commits intomasterfrom
openapi-responses

Conversation

@virkt25
Copy link
Copy Markdown
Contributor

@virkt25 virkt25 commented Aug 29, 2018

connected to #1531


This PR:

  • Ensures we set a default responses property on a Controller methods OpenAPI Spec if one isn't given
  • Extends the OpenAPI spec by introducing a x-ts-type property that can be used to specify the schema of a response object. Can also be used to specify the type of array items.
content: {'x-ts-type': Todo} => content: {schema: {$ref: '#components/schemas/Todo'}}
content: {schema: {type: 'array', items: {x-ts-type: Todo}}} => content: {schema: {type: 'array', items: {$ref: '#components/schemas/Todo'}}}
  • Refactors generate-schema to have a single function to resolve schema from a Function.
  • Updates CLI Controller template to set a responses object based on the Model
  • Updates example-todo / example-todo-list to set responses object

This PR introduces:
- a new @responses decorator that can be used to decorate a Controller method with the appropriate OpenAPI responses object.
- for controller's not decorated with this property, or via the @operation and family (get, post, etc.) of decorators, we generate a default responses object to be OpenAPI 3.0 compliant
- controller-spec generator can set Model as $ref for {schema: Model} or {schema: {type: 'array', items: Model}}}in the responses object.~ ~- Decorateexample-todowith@Responses()` decorator as an example. Once this PR is agreed upon, a follow up PR/commit will add decoration to CLI template + remaining examples + docs

Checklist

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants