From a2c210d6a4ae8c251a52e2c75a2a644caa435f94 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Mon, 30 Aug 2021 17:29:09 +0200 Subject: [PATCH] bump dep --- README.md | 8 ++++-- examples/dynamic-swagger.js | 53 ++++++++++++++++--------------------- package.json | 2 +- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index ac082bb8..8ae4cb2d 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ fastify.register(require('fastify-swagger'), { When this plugin is configured as `dynamic` mode, it will resolve all `$ref`s in your application's schemas. This process will create an new in-line schema that is going to reference itself. -This logic stap it is done to make sure that the generated documentation is valid, otherwise the Swagger UI will try to fetch the schemas from the server or the network and fail. +This logic step is done to make sure that the generated documentation is valid, otherwise the Swagger UI will try to fetch the schemas from the server or the network and fail. By default, this option will resolve all `$ref`s renaming them to `def-${counter}`, but your view models keep the original `$id` naming thanks to the [`title` parameter](https://swagger.io/docs/specification/2-0/basic-structure/#metadata). @@ -274,7 +274,7 @@ fastify.register(require('fastify-swagger'), { ... refResolver: { buildLocalReference (json, baseUri, fragment, i) { - return `my-fragment-${i}` + return json.$id || `my-fragment-${i}` } } } @@ -664,6 +664,10 @@ You can integration this plugin with ```fastify-helmet``` with some little work. }) ``` + +## `$id` and `$ref` usage + + ## Development In order to start development run: ``` diff --git a/examples/dynamic-swagger.js b/examples/dynamic-swagger.js index f9bc9e53..83f6682a 100644 --- a/examples/dynamic-swagger.js +++ b/examples/dynamic-swagger.js @@ -25,31 +25,37 @@ fastify.register(require('../index'), { exposeRoute: true }) +fastify.addSchema({ + $id: 'user', + type: 'object', + properties: { + id: { + type: 'string', + description: 'user id' + } + } +}) + +fastify.addSchema({ + $id: 'some', + type: 'object', + properties: { + some: { type: 'string' } + } +}) + fastify.put('/some-route/:id', { schema: { description: 'post some data', tags: ['user', 'code'], summary: 'qwerty', security: [{ apiKey: [] }], - params: { - type: 'object', - properties: { - id: { - type: 'string', - description: 'user id' - } - } - }, + params: { $ref: 'user#' }, body: { type: 'object', properties: { hello: { type: 'string' }, - obj: { - type: 'object', - properties: { - some: { type: 'string' } - } - } + obj: { $ref: 'some#' } } }, response: { @@ -69,25 +75,12 @@ fastify.post('/some-route/:id', { description: 'post some data', summary: 'qwerty', security: [{ apiKey: [] }], - params: { - type: 'object', - properties: { - id: { - type: 'string', - description: 'user id' - } - } - }, + params: { $ref: 'user#' }, body: { type: 'object', properties: { hello: { type: 'string' }, - obj: { - type: 'object', - properties: { - some: { type: 'string' } - } - } + obj: { $ref: 'some#' } } }, response: { diff --git a/package.json b/package.json index 367919aa..ac6511a1 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "fastify-plugin": "^3.0.0", "fastify-static": "^4.0.0", "js-yaml": "^4.0.0", - "json-schema-resolver": "github:Eomm/json-schema-resolver#ref-to-def", + "json-schema-resolver": "^1.3.0", "openapi-types": "^9.1.0" }, "standard": {