@@ -19,7 +19,7 @@ test('support $ref schema', async (t) => {
1919
2020 await fastify . register ( fastifySwagger , openapiOption )
2121 fastify . register ( async ( instance ) => {
22- instance . addSchema ( { $id : 'Order' , type : 'object' , properties : { id : { type : 'integer' } } } )
22+ instance . addSchema ( { $id : 'Order' , type : 'object' , properties : { id : { type : 'integer' , examples : [ 25 ] } } } )
2323 instance . post ( '/' , { schema : { body : { $ref : 'Order#' } , response : { 200 : { $ref : 'Order#' } } } } , ( ) => { } )
2424 } )
2525
@@ -28,6 +28,7 @@ test('support $ref schema', async (t) => {
2828 const openapiObject = fastify . swagger ( )
2929 t . equal ( typeof openapiObject , 'object' )
3030 t . match ( Object . keys ( openapiObject . components . schemas ) , [ 'Order' ] )
31+ t . equal ( openapiObject . components . schemas . Order . properties . id . example , 25 )
3132
3233 await Swagger . validate ( openapiObject )
3334} )
@@ -67,7 +68,7 @@ test('support nested $ref schema : simple test', async (t) => {
6768 const fastify = Fastify ( )
6869 await fastify . register ( fastifySwagger , openapiOption )
6970 fastify . register ( async ( instance ) => {
70- instance . addSchema ( { $id : 'OrderItem' , type : 'object' , properties : { id : { type : 'integer' } } } )
71+ instance . addSchema ( { $id : 'OrderItem' , type : 'object' , properties : { id : { type : 'integer' } } , examples : [ { id : 1 } ] } )
7172 instance . addSchema ( { $id : 'ProductItem' , type : 'object' , properties : { id : { type : 'integer' } } } )
7273 instance . addSchema ( { $id : 'Order' , type : 'object' , properties : { products : { type : 'array' , items : { $ref : 'OrderItem' } } } } )
7374 instance . post ( '/' , { schema : { body : { $ref : 'Order' } , response : { 200 : { $ref : 'Order' } } } } , ( ) => { } )
@@ -84,6 +85,7 @@ test('support nested $ref schema : simple test', async (t) => {
8485
8586 // ref must be prefixed by '#/components/schemas/'
8687 t . equal ( schemas . Order . properties . products . items . $ref , '#/components/schemas/OrderItem' )
88+ t . match ( schemas . OrderItem . example , { id : 1 } )
8789
8890 await Swagger . validate ( openapiObject )
8991} )
@@ -93,7 +95,7 @@ test('support nested $ref schema : complex case', async (t) => {
9395 await fastify . register ( fastifySwagger , openapiOption )
9496 fastify . register ( async ( instance ) => {
9597 instance . addSchema ( { $id : 'schemaA' , type : 'object' , properties : { id : { type : 'integer' } } } )
96- instance . addSchema ( { $id : 'schemaB' , type : 'object' , properties : { id : { type : 'string' } } } )
98+ instance . addSchema ( { $id : 'schemaB' , type : 'object' , properties : { id : { type : 'string' , examples : [ 'ABC' ] } } } )
9799 instance . addSchema ( { $id : 'schemaC' , type : 'object' , properties : { a : { type : 'array' , items : { $ref : 'schemaA' } } } } )
98100 instance . addSchema ( { $id : 'schemaD' , type : 'object' , properties : { b : { $ref : 'schemaB' } , c : { $ref : 'schemaC' } } } )
99101 instance . post ( '/url1' , { schema : { body : { $ref : 'schemaD' } , response : { 200 : { $ref : 'schemaB' } } } } , ( ) => { } )
@@ -112,6 +114,7 @@ test('support nested $ref schema : complex case', async (t) => {
112114 t . equal ( schemas . schemaC . properties . a . items . $ref , '#/components/schemas/schemaA' )
113115 t . equal ( schemas . schemaD . properties . b . $ref , '#/components/schemas/schemaB' )
114116 t . equal ( schemas . schemaD . properties . c . $ref , '#/components/schemas/schemaC' )
117+ t . equal ( schemas . schemaB . properties . id . example , 'ABC' )
115118
116119 await Swagger . validate ( openapiObject )
117120} )
0 commit comments