Skip to content

Commit

Permalink
bump dep
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm committed Aug 30, 2021
1 parent 21bbc19 commit a2c210d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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}`
}
}
}
Expand Down Expand Up @@ -664,6 +664,10 @@ You can integration this plugin with ```fastify-helmet``` with some little work.
})
```
<a name="usage"></a>
## `$id` and `$ref` usage
## Development
In order to start development run:
```
Expand Down
53 changes: 23 additions & 30 deletions examples/dynamic-swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit a2c210d

Please sign in to comment.