New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a transform method for schema #144
Add a transform method for schema #144
Conversation
Add transform options in opts to be able to convert schema properties if required
Update documentation for transform option
This version will be able to generate documentation if fastify-swagger merge the PR fastify/fastify-swagger#144 for the new transform option
As a side note, I had the same errors locally as in travis-ci when running TypeScript |
Add mention about the mode and fix notes
I’m not sure why, but can you add that as a devDependency? We’ll need CI to pass to land this. |
Can you add a unit test? Also, can you update the typings? |
Done @mcollina, waiting for CI |
Ah, forgot the typings sorry... |
/** | ||
* Overwrite the route schema | ||
* @default false | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think the default is false. Typings also have tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm gonna fix it and currently looking at for the unit-tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you usually test dynamic mode ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being so long about the unit-tests, I'm not familiar with tap
.
Also I don't know to which extend you need to test the property.
Ok it should be good by now :) |
As a side note I noticed that it doesn't play well with |
Anyway my guess is that the user who implements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This seems a pretty innocent feature to have. I don't really understand your points, would you mind opening an issue or a follow up PR? |
@mcollina Actually after testing and looking at documentation, to make the story short that's OK 😃 In details, my test was something like : const params = ...
const body = ...
const querystring = ...
const response = {
200: Joi.object().keys({ message: Joi.string().required() }).required()
} Looking at fastify documentation I understand why adding a joi object for not ok Converting circular structure to JSON
found:
name: TypeError
stack: |-
TypeError: Converting circular structure to JSON
at stringify (/Users/romain/Development/sandbox/fastify-swagger/node_modules/fast-json-stable-stringify/index.js:42:19)
at stringify (/Users/romain/Development/sandbox/fastify-swagger/node_modules/fast-json-stable-stringify/index.js:50:25)
at stringify (/Users/romain/Development/sandbox/fastify-swagger/node_modules/fast-json-stable-stringify/index.js:50:25)
at module.exports (/Users/romain/Development/sandbox/fastify-swagger/node_modules/fast-json-stable-stringify/index.js:58:7)
at Ajv._addSchema (/Users/romain/Development/sandbox/fastify-swagger/node_modules/ajv/lib/ajv.js:293:30)
at Ajv.compile (/Users/romain/Development/sandbox/fastify-swagger/node_modules/ajv/lib/ajv.js:111:24)
at isValidSchema (/Users/romain/Development/sandbox/fastify-swagger/node_modules/fast-json-stringify/index.js:917:7)
at build (/Users/romain/Development/sandbox/fastify-swagger/node_modules/fast-json-stringify/index.js:39:3)
at getValidatorForStatusCodeSchema (/Users/romain/Development/sandbox/fastify-swagger/node_modules/fastify/lib/validation.js:13:10)
at /Users/romain/Development/sandbox/fastify-swagger/node_modules/fastify/lib/validation.js:19:21
at Array.reduce (<anonymous>)
at getResponseSchema (/Users/romain/Development/sandbox/fastify-swagger/node_modules/fastify/lib/validation.js:18:22)
at build (/Users/romain/Development/sandbox/fastify-swagger/node_modules/fastify/lib/validation.js:53:31)
at afterRouteAdded (/Users/romain/Development/sandbox/fastify-swagger/node_modules/fastify/fastify.js:636:9)
at /Users/romain/Development/sandbox/fastify-swagger/node_modules/fastify/fastify.js:596:7
at Object._encapsulateThreeParam (/Users/romain/Development/sandbox/fastify-swagger/node_modules/avvio/boot.js:389:7)
message: Converting circular structure to JSON
at:
line: 62
column: 7
file: test/transform.js
function: fastify.ready.err
stack: |
fastify.ready.err (test/transform.js:62:7)
Object._encapsulateThreeParam (node_modules/avvio/boot.js:380:13)
Boot.callWithCbOrNextTick (node_modules/avvio/boot.js:311:5)
release (node_modules/fastq/queue.js:127:16)
Object.resume (node_modules/fastq/queue.js:61:7)
Boot.Plugin.loadPlugin.call (node_modules/avvio/boot.js:146:20)
toLoad.finish (node_modules/avvio/plugin.js:169:7)
done (node_modules/avvio/plugin.js:127:5)
check (node_modules/avvio/plugin.js:138:7)
source: |
t.error(err) Last but not least it's actually mentioned here that :
And there's no mention of validating |
* Add transform in opts Add transform options in opts to be able to convert schema properties if required * Update documentation Update documentation for transform option * Lint code * Update documentation Add mention about the mode and fix notes * Add @types/node as a dev dependency * Update typings * Remove wrong default * Add basic unit-test * Fix unit-tests
This version will be able to generate documentation if fastify-swagger merge the PR fastify/fastify-swagger#144 for the new transform option
Add a transform option to convert
route.schema
on documentation generation indynamic
mode.