diff --git a/README.md b/README.md index ca2cf34..b33950c 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,20 @@ await fastify.register(require('@fastify/swagger-ui', { To ensure that models are correctly rendered at the bottom of the Swagger UI page, it's important to define your schemas using $refs through [fastify.addSchema](https://fastify.dev/docs/latest/Reference/Validation-and-Serialization/#adding-a-shared-schema). Directly embedding JSON schemas within the schema property of your route definitions in Fastify may lead to them not being displayed in Swagger UI. +#### validatorUrl + +[SwaggerUI](https://github.com/swagger-api/swagger-ui/) can automatically validate the given specification using an online validator. +To enable this behavior you can pass the [`validatorUrl`](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md) option +to this plugin which will be forwarded to SwaggerUI. + +```js +fastify.register('@fastify/swagger-ui', { + validatorUrl: 'https://validator.swagger.io/validator' +}) +``` + +Note that this behavior is disabled by default in `@fastify/swagger-ui`. + ## License diff --git a/examples/dynamic-openapi.js b/examples/dynamic-openapi.js index ef0c33c..614263c 100644 --- a/examples/dynamic-openapi.js +++ b/examples/dynamic-openapi.js @@ -25,7 +25,9 @@ fastify.register(require('@fastify/swagger'), { hideUntagged: true }) -fastify.register(require('../index')) +fastify.register(require('../index'), { + validatorUrl: false +}) fastify.register(async function (fastify) { fastify.put('/some-route/:id', { @@ -113,6 +115,6 @@ fastify.register(async function (fastify) { }, (req, reply) => { reply.send({ hello: `Hello ${req.body.hello}` }) }) }) -fastify.listen({ port: 3000 }, err => { +fastify.listen({ port: 3000, hostname: '0.0.0.0' }, err => { if (err) throw err }) diff --git a/lib/swagger-initializer.js b/lib/swagger-initializer.js index 0bff3b2..9f4054b 100644 --- a/lib/swagger-initializer.js +++ b/lib/swagger-initializer.js @@ -24,7 +24,8 @@ function swaggerInitializer (opts) { plugins: [ SwaggerUIBundle.plugins.DownloadUrl ], - layout: "StandaloneLayout" + layout: "StandaloneLayout", + validatorUrl: ${serialize(opts.validatorUrl)}, }, config, { url: resolveUrl('./json').replace('static/json', 'json'), oauth2RedirectUrl: resolveUrl('./oauth2-redirect.html')