Skip to content

Commit 23ad7ff

Browse files
mcollinaUzlopakkibertoad
authored
Add validatorUrl option (#105)
* Add validatorUrl option Signed-off-by: Matteo Collina <[email protected]> * Set it to false by default Signed-off-by: Matteo Collina <[email protected]> * Update README.md Co-authored-by: Igor Savin <[email protected]> --------- Signed-off-by: Matteo Collina <[email protected]> Co-authored-by: Aras Abbasi <[email protected]> Co-authored-by: Igor Savin <[email protected]>
1 parent 1ab87ea commit 23ad7ff

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,20 @@ await fastify.register(require('@fastify/swagger-ui', {
305305
306306
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.
307307
308+
#### validatorUrl
309+
310+
[SwaggerUI](https://github.com/swagger-api/swagger-ui/) can automatically validate the given specification using an online validator.
311+
To enable this behavior you can pass the [`validatorUrl`](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md) option
312+
to this plugin which will be forwarded to SwaggerUI.
313+
314+
```js
315+
fastify.register('@fastify/swagger-ui', {
316+
validatorUrl: 'https://validator.swagger.io/validator'
317+
})
318+
```
319+
320+
Note that this behavior is disabled by default in `@fastify/swagger-ui`.
321+
308322
<a name="license"></a>
309323
## License
310324

examples/dynamic-openapi.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ fastify.register(require('@fastify/swagger'), {
2525
hideUntagged: true
2626
})
2727

28-
fastify.register(require('../index'))
28+
fastify.register(require('../index'), {
29+
validatorUrl: false
30+
})
2931

3032
fastify.register(async function (fastify) {
3133
fastify.put('/some-route/:id', {
@@ -113,6 +115,6 @@ fastify.register(async function (fastify) {
113115
}, (req, reply) => { reply.send({ hello: `Hello ${req.body.hello}` }) })
114116
})
115117

116-
fastify.listen({ port: 3000 }, err => {
118+
fastify.listen({ port: 3000, hostname: '0.0.0.0' }, err => {
117119
if (err) throw err
118120
})

lib/swagger-initializer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ function swaggerInitializer (opts) {
2424
plugins: [
2525
SwaggerUIBundle.plugins.DownloadUrl
2626
],
27-
layout: "StandaloneLayout"
27+
layout: "StandaloneLayout",
28+
validatorUrl: ${serialize(opts.validatorUrl)},
2829
}, config, {
2930
url: resolveUrl('./json').replace('static/json', 'json'),
3031
oauth2RedirectUrl: resolveUrl('./oauth2-redirect.html')

0 commit comments

Comments
 (0)