Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

feat: add tool to generate OpenAPI spec #336

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

wpf500
Copy link
Member

@wpf500 wpf500 commented Jan 12, 2024

This PR adds experimental generation of an OpenAPI spec

It uses the packages routing-controllers-openapi and class-validator-jsonchema to generate the OpenAPI spec. It needs quite a bit of nudging in the right direction with extra decorators due to limitations in TypeScript type reflection.

In particular:

  • All route handlers which return a Promise<T> (so basically all of them) have a @ResponseSchema(T) decorator
  • There is now a separate DTO for each paginated response, e.g. PaginatedDto<GetContactDto> -> GetContactListDto. This is because class-validation-schema can't process generics, so derived classes are necessary
  • DTOs that were extended from another DTO but without new properties (e.g. GetAddressDto extends from UpdateAddressDto) have been merged. This was only an attempt at consistency and class-validation-schema can't generate JSONSchema for these classes (as they aren't registered with class-validator)

This means there is quite a lot of boilerplate in controllers and on DTOs, but I think it's good enough for now and pretty cool to be able to generate some fairly useable docs so easily :).

To do

The docs 📖

image

@wpf500 wpf500 force-pushed the feat/929-api-docs branch from d29e77f to c315dd7 Compare January 12, 2024 13:00
Base automatically changed from feat/917-new-validations to feat/917-response-validation January 17, 2024 18:22
@wpf500 wpf500 force-pushed the feat/929-api-docs branch from 37dd5cd to 134cb79 Compare January 19, 2024 17:43
@wpf500 wpf500 force-pushed the feat/929-api-docs branch from 134cb79 to abf3113 Compare January 19, 2024 17:46
Base automatically changed from feat/917-response-validation to master January 24, 2024 14:20
@wpf500 wpf500 marked this pull request as ready for review January 24, 2024 14:20
@wpf500 wpf500 changed the title feat: auto-generate API docs feat: add tool to generate OpenAPI spec Jan 24, 2024
@wpf500 wpf500 marked this pull request as draft March 22, 2024 15:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants