fastify-swagger
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -31,2 +31,3 @@ 'use strict' | ||
const externalDocs = opts.swagger.externalDocs || null | ||
const transform = opts.transform || null | ||
@@ -96,3 +97,5 @@ if (opts.exposeRoute === true) { | ||
const schema = route.schema | ||
const schema = transform | ||
? transform(route.schema) | ||
: route.schema | ||
const url = formatParamUrl(route.url) | ||
@@ -99,0 +102,0 @@ |
@@ -23,2 +23,6 @@ import * as http from 'http'; | ||
swagger?: Partial<SwaggerSchema.Spec>; | ||
/** | ||
* Overwrite the route schema | ||
*/ | ||
transform?: Function; | ||
} | ||
@@ -25,0 +29,0 @@ |
{ | ||
"name": "fastify-swagger", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Generate Swagger files automatically for Fastify.", | ||
@@ -33,14 +33,17 @@ "main": "index.js", | ||
"devDependencies": { | ||
"fastify": "next", | ||
"fs-extra": "^7.0.0", | ||
"@types/node": "^10.12.18", | ||
"fastify": "2.0.0-rc.4", | ||
"fs-extra": "^7.0.1", | ||
"joi": "^14.3.1", | ||
"joi-to-json-schema": "^3.5.0", | ||
"pre-commit": "^1.2.2", | ||
"standard": "^12.0.1", | ||
"swagger-parser": "^6.0.0", | ||
"typescript": "^3.1.6", | ||
"swagger-parser": "^6.0.3", | ||
"swagger-ui-dist": "3.20.4", | ||
"tap": "^12.0.0" | ||
"tap": "^12.1.2", | ||
"typescript": "^3.2.4" | ||
}, | ||
"dependencies": { | ||
"@types/swagger-schema-official": "^2.0.13", | ||
"fastify-plugin": "^1.2.0", | ||
"fastify-plugin": "^1.4.0", | ||
"fastify-static": "^2.1.0", | ||
@@ -47,0 +50,0 @@ "js-yaml": "^3.12.1" |
@@ -186,2 +186,28 @@ # fastify-swagger | ||
##### Convert routes schema | ||
If you would like to use different schemas like, let's say [Joi](https://github.com/hapijs/joi), you can pass a synchronous `transform` method in the options to convert them back to standard JSON schemas expected by this plugin to generate the documentation (`dynamic` mode only). | ||
```js | ||
const convert = require('joi-to-json-schema') | ||
fastify.register(require('fastify-swagger'), { | ||
swagger: { ... }, | ||
... | ||
transform: schema => { | ||
const { | ||
params = undefined, | ||
body = undefined, | ||
querystring = undefined, | ||
response = undefined, | ||
...others | ||
} = schema | ||
const transformed = { ...others } | ||
if (params) transformed.params = convert(params) | ||
if (body) transformed.body = convert(body) | ||
if (querystring) transformed.querystring = convert(querystring) | ||
if (response) transformed.response = convert(response) | ||
return transformed | ||
} | ||
} | ||
``` | ||
<a name="swagger.options"></a> | ||
@@ -188,0 +214,0 @@ ### swagger options |
@@ -8,2 +8,3 @@ import fastify = require('fastify'); | ||
app.register(fastifySwagger, {}); | ||
app.register(fastifySwagger, { transform: (schema : any) => schema }); | ||
app.register(fastifySwagger, { | ||
@@ -10,0 +11,0 @@ mode: 'static', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9218753
35
10567
250
11
Updatedfastify-plugin@^1.4.0