11import {
22 FastifyPluginAsyncJsonSchemaToTs ,
3- FastifyPluginCallbackJsonSchemaToTs ,
4- } from " ../index" ;
5- import { expectType } from " tsd" ;
6- import Fastify , { FastifyPluginAsync , FastifyPluginCallback } from " fastify" ;
3+ FastifyPluginCallbackJsonSchemaToTs
4+ } from ' ../index'
5+ import { expectType } from ' tsd'
6+ import Fastify , { FastifyPluginAsync , FastifyPluginCallback } from ' fastify'
77
8- import { Http2Server } from " http2" ;
8+ import { Http2Server } from ' http2'
99
1010// Ensure the defaults of FastifyPluginAsyncJsonSchemaToTs are the same as FastifyPluginAsync
1111export const pluginAsyncDefaults : FastifyPluginAsync = async (
@@ -14,11 +14,11 @@ export const pluginAsyncDefaults: FastifyPluginAsync = async (
1414) => {
1515 const pluginAsyncJSONSchemaToTsDefaults : FastifyPluginAsyncJsonSchemaToTs =
1616 async ( fastifyWithJSONSchemaToTs , optionsJSONSchemaToTs ) => {
17- expectType < typeof fastifyWithJSONSchemaToTs [ " server" ] > ( fastify . server ) ;
18- expectType < typeof optionsJSONSchemaToTs > ( options ) ;
19- } ;
20- fastify . register ( pluginAsyncJSONSchemaToTsDefaults ) ;
21- } ;
17+ expectType < typeof fastifyWithJSONSchemaToTs [ ' server' ] > ( fastify . server )
18+ expectType < typeof optionsJSONSchemaToTs > ( options )
19+ }
20+ fastify . register ( pluginAsyncJSONSchemaToTsDefaults )
21+ }
2222
2323// Ensure the defaults of FastifyPluginCallbackJsonSchemaToTs are the same as FastifyPluginCallback
2424export const pluginCallbackDefaults : FastifyPluginCallback = async (
@@ -32,77 +32,77 @@ export const pluginCallbackDefaults: FastifyPluginCallback = async (
3232 optionsJSONSchemaToTs ,
3333 doneJSONSchemaToTs
3434 ) => {
35- expectType < typeof fastifyWithJSONSchemaToTs [ " server" ] > ( fastify . server ) ;
36- expectType < typeof optionsJSONSchemaToTs > ( options ) ;
37- } ;
35+ expectType < typeof fastifyWithJSONSchemaToTs [ ' server' ] > ( fastify . server )
36+ expectType < typeof optionsJSONSchemaToTs > ( options )
37+ }
3838
39- fastify . register ( pluginCallbackJSONSchemaToTsDefaults ) ;
40- } ;
39+ fastify . register ( pluginCallbackJSONSchemaToTsDefaults )
40+ }
4141
4242const asyncPlugin : FastifyPluginAsyncJsonSchemaToTs <
4343 { optionA : string } ,
4444 Http2Server
4545> = async ( fastify , options ) => {
46- expectType < Http2Server > ( fastify . server ) ;
46+ expectType < Http2Server > ( fastify . server )
4747
48- expectType < string > ( options . optionA ) ;
48+ expectType < string > ( options . optionA )
4949
5050 fastify . get (
51- "/" ,
51+ '/' ,
5252 {
5353 schema : {
5454 body : {
55- type : " object" ,
55+ type : ' object' ,
5656 properties : {
57- x : { type : " string" } ,
58- y : { type : " number" } ,
59- z : { type : " boolean" } ,
57+ x : { type : ' string' } ,
58+ y : { type : ' number' } ,
59+ z : { type : ' boolean' }
6060 } ,
61- required : [ "x" , "y" , "z" ] ,
62- } as const ,
63- } ,
61+ required : [ 'x' , 'y' , 'z' ]
62+ } as const
63+ }
6464 } ,
6565 ( req ) => {
66- expectType < boolean > ( req . body . z ) ;
67- expectType < number > ( req . body . y ) ;
68- expectType < string > ( req . body . x ) ;
66+ expectType < boolean > ( req . body . z )
67+ expectType < number > ( req . body . y )
68+ expectType < string > ( req . body . x )
6969 }
70- ) ;
71- } ;
70+ )
71+ }
7272
7373const callbackPlugin : FastifyPluginCallbackJsonSchemaToTs <
7474 { optionA : string } ,
7575 Http2Server
7676> = ( fastify , options , done ) => {
77- expectType < Http2Server > ( fastify . server ) ;
77+ expectType < Http2Server > ( fastify . server )
7878
79- expectType < string > ( options . optionA ) ;
79+ expectType < string > ( options . optionA )
8080
8181 fastify . get (
82- "/" ,
82+ '/' ,
8383 {
8484 schema : {
8585 body : {
86- type : " object" ,
86+ type : ' object' ,
8787 properties : {
88- x : { type : " string" } ,
89- y : { type : " number" } ,
90- z : { type : " boolean" } ,
88+ x : { type : ' string' } ,
89+ y : { type : ' number' } ,
90+ z : { type : ' boolean' }
9191 } ,
92- required : [ "x" , "y" , "z" ] ,
93- } as const ,
94- } ,
92+ required : [ 'x' , 'y' , 'z' ]
93+ } as const
94+ }
9595 } ,
9696 ( req ) => {
97- expectType < boolean > ( req . body . z ) ;
98- expectType < number > ( req . body . y ) ;
99- expectType < string > ( req . body . x ) ;
97+ expectType < boolean > ( req . body . z )
98+ expectType < number > ( req . body . y )
99+ expectType < string > ( req . body . x )
100100 }
101- ) ;
102- done ( ) ;
103- } ;
101+ )
102+ done ( )
103+ }
104104
105- const fastify = Fastify ( ) ;
105+ const fastify = Fastify ( )
106106
107- fastify . register ( asyncPlugin ) ;
108- fastify . register ( callbackPlugin ) ;
107+ fastify . register ( asyncPlugin )
108+ fastify . register ( callbackPlugin )
0 commit comments