Usage
Just add docsService.registerDocs
in your code. For example
Here we just added /account/sign-up
path to open api specification. Later on we will learn how to customise it.
To look at result you can launch application and make call to api endpoint with /docs/json
path. E.g. http://localhost:3002/docs/json
if you’re using local server.
It will return you json specification in Open API standard.
You can use tools like Swagger Editor to see it in pretty editor.
In order to add body, params or query, you can add zod schema inside request
property.
E.g. for body it will look like that:
Here we also added details inside responses
property to let api user know what we might expect from there. For that we have used docsService.registerSchema
function. For more details you can look at this documentation
For query, it will look like that:
Also, there is an option to make the endpoint secure. Just set the private
property to true
, and it will add JWT authorization to this endpoint.
If your auth method is not JWT, then there is built-in cookie-auth
strategy. To update set it, you can set authType
in config.
If you need other strategies, please look at docs.service.ts
file. There will be option to extend methods like that: